Tengo una función que se encarga de dar de alta el documento de la siguiente manera:
public boolean guardarDocumentoGestorDocumental(byte[] contenido) throws Exception {
      
      String spaceRaizPruebas = "Pruebas";
      boolean result=true;
      
      System.out.println("Inicio guardarDocumentoGD");
      
      // asignamos un nombre al documento
      /*int cont = Contador.getContador();
      String nameFile = String.valueOf(cont);
      String nombreFicheroCompleto = nameFile+"."+extension;*/
      String nombreFicheroCompleto = nombreArchivo+"."+extension;
      
      // creamos carpetas separados con el mismo nombre de documento
      
      int contador = Contador.getContador();
      String nameCarpeta = String.valueOf(contador);
      String carpetaPrueba = carpeta+nameCarpeta;
      try {
         WebServiceFactory.setEndpointAddress(urlGestor);
         WebServiceFactory.setTimeoutMilliseconds(TIMEOUT);
         // Start the session
         AuthenticationUtils.startSession(userGestor, passwordGestor);
         
         // Create a reference to the parent where we want to create content
         Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
         System.out.println("Obtengo la raiz del repositorio.");
         
         ParentReference companyHomeParent = new ParentReference(storeRef,null, "/app:company_home", Constants.ASSOC_CONTAINS,"sample_folder");
         // Create a reference to the parent where we want to create content
         ParentReference Nodo = new ParentReference();
         // creamos la raiz Pruebas dentro de company_home
         Nodo = this.getPadre(storeRef, "/app:company_home/*[@cm:name=\""+ spaceRaizPruebas + "\"]", spaceRaizPruebas,companyHomeParent);
         
         // se obtiene la referencia ala carpeta Pruebas –> PruebasRaiz
         ParentReference Nodo2 = this.getPadre(storeRef,"/app:company_home/*[@cm:name=\"" + spaceRaizPruebas+ "\"]/*[@cm:name=\"" + carpetaRaiz + "\"]",carpetaRaiz, Nodo);
         
         // Create a reference to the parent where we want to create content
         //ParentReference Origen = this.getPadre(storeRef,"/app:company_home/*[@cm:name=\"" + spaceRaizPruebas+ "\"]/*[@cm:name=\"" + carpetaPrueba + "\"]",carpetaPrueba, Nodo);
         ParentReference Origen = this.getPadre(storeRef,"/app:company_home/*[@cm:name=\"" + spaceRaizPruebas + "\"]/*[@cm:name=\"" + carpetaRaiz + "\"]/*[@cm:name=\"" + carpetaPrueba + "\"]",carpetaPrueba, Nodo2);
         System.out.println("Ruta Fichero a buscar:");
         System.out.println(Origen);
         
         // Assign name
         String name = nombreFicheroCompleto;
         Origen.setChildName("cm:" + name);
         // Construct CML statement to create content node
         // Note: Assign "1" as a local id, so we can refer to it in
         // subsequent
         // CML statements within the same CML block
         NamedValue[] contentProps = new NamedValue[1];
         contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, name);
         CMLCreate create1 = new CMLCreate("1", Origen, null, null, null,
               Constants.TYPE_CONTENT, contentProps);
         // Construct CML statement to add titled aspect
         NamedValue[] titledProps = new NamedValue[2];
         titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE, name);
         titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION,
               name);
         CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED,titledProps, null, "1");
         // Construct CML Block
         CML cml1 = new CML();
         cml1.setCreate(new CMLCreate[] { create1 });
         cml1.setAddAspect(new CMLAddAspect[] { addAspect });
         // Issue CML statement via Repository Web Service and retrieve
         // result
         // Note: Batching of multiple statements into a single web call
         UpdateResult[] updateResult = WebServiceFactory.getRepositoryService().update(cml1);
         Reference content = updateResult[0].getDestination();
         //
         // Write some content
         //   
         ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
         ContentFormat contentFormat = new ContentFormat("application/octet-stream", "UTF-8");
         Content contentRef = contentService.write(content,Constants.PROP_CONTENT, contenido,contentFormat);
         if (contentRef==null){
            result=false;
            logger.error("NO SE HA PODIDO GUARDAR EL DOCUMENTO "+carpetaPrueba+"/"+nombreFicheroCompleto);
            throw new Exception("No se ha podido guardar el documento");
         }
         result=true;
         logger.info("SE HA GUARDADO EL DOCUMENTO "+nombreFicheroCompleto);
      } catch (Exception e) {
         result=false;
         e.printStackTrace();
         logger.error("NO SE HA PODIDO GUARDAR EL DOCUMENTO "+carpetaPrueba+"/"+nombreFicheroCompleto);
         throw new Exception("No se ha podido guardar el documento. "+e.getMessage());
         
      } catch (Throwable ee){
         ee.printStackTrace();
         logger.error("NO SE HA PODIDO GUARDAR EL DOCUMENTO "+carpetaPrueba+"/"+nombreFicheroCompleto);
         throw new Exception("No se ha podido guardar el documento. "+ee.getMessage());
      }
      finally {
         System.out.println("Fin guardarDocumentoGD");
         AuthenticationUtils.endSession();
         
      }
      
      return result;
   }
La función getPadre obtiene la referencia padre de un nodo. Y si no existe, la crea:
private ParentReference getPadre(Store storeRef, String path, String espacio, ParentReference abuelo) throws RepositoryFault, RemoteException {
      ParentReference parent = null;
      try {
         System.out.println("Entramos a getPadre");
         System.out.println("Comprobamos que la referencia ya exista.");
         
         WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[] { new Reference(storeRef,null, path) }, storeRef, null));
         
         System.out.println("El nodo " + espacio + " ya existe.");
         parent = new ParentReference(storeRef, null, path,Constants.ASSOC_CONTAINS, Constants.createQNameString(
                     Constants.NAMESPACE_CONTENT_MODEL, espacio));
         return parent;
      } catch (Exception e) {
         System.out.println("El nodo " + espacio + " no existe. Vamos a crearlo.");
         NamedValue[] properties = new NamedValue[] { Utils.createNamedValue(Constants.PROP_NAME, espacio) };
         CMLCreate create = new CMLCreate("1", abuelo, null, null, null,   Constants.TYPE_FOLDER, properties);
         CML cml = new CML();
         cml.setCreate(new CMLCreate[] { create });
         UpdateResult[] results = WebServiceFactory.getRepositoryService().update(cml);
         // Create parent reference to sample folder
         Reference sampleFolder = results[0].getDestination();
         parent = new ParentReference(storeRef, sampleFolder.getUuid(),path, Constants.ASSOC_CONTAINS, Constants.createQNameString(
                           Constants.NAMESPACE_CONTENT_MODEL, espacio));
         System.out.println("El nodo " + espacio + " ya ha sido creado.");
         return parent;
      }
   }