cmisopencmisdotcmis

Unable to create folder in repositry through CMIS


I am new to this and trying to create folder in repositry, but it is showing some exception.Help me out wtih this thanks in advance.

Here Is my code

SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
    Map<String, String> parameter = new HashMap<String, String>();

    // ECM user credentials
    parameter.put(SessionParameter.USER, "User");
    parameter.put(SessionParameter.PASSWORD, "password");

            parameter.put(SessionParameter.ATOMPUB_URL, "URL");
    parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

    // Get a list of repositories retrieved by the atompub CMIS endpoint (for Alfresco there is only one element)
    List<Repository> repositories = sessionFactory.getRepositories(parameter);

    // Create CMIS session to the repository
    Session session = repositories.get(0).createSession();
    System.out.println("Root Folder Name: "+session.getRepositoryInfo().getRootFolderId());
    Folder subFolder = null;

    Folder parentFolder = session.getRootFolder();
    try {
      subFolder = (Folder) session.getObjectByPath(parentFolder.getPath() + "/" + "folderName");
      System.out.println("Folder already existed!");
    } catch (CmisObjectNotFoundException onfe) {
      Map props = new HashMap();
      props.put("cmis:objectTypeId",  "cmis:folder");
      props.put("cmis:name", "folderName");
      subFolder = parentFolder.createFolder(props);
      String subFolderId = subFolder.getId();
      System.out.println("Created new folder: " + subFolderId);
    }

Getting This error----- Exception in thread "main" org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException: Conflict at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:482) at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.post(AbstractAtomPubService.java:629) at org.apache.chemistry.opencmis.client.bindings.spi.atompub.ObjectServiceImpl.createFolder(ObjectServiceImpl.java:158) at org.apache.chemistry.opencmis.client.runtime.SessionImpl.createFolder(SessionImpl.java:814) at org.apache.chemistry.opencmis.client.runtime.FolderImpl.createFolder(FolderImpl.java:136) at org.apache.chemistry.opencmis.client.runtime.FolderImpl.createFolder(FolderImpl.java:479) at com.reva.test.main(test.java:55)


Solution

  • The path of the root folder is / and you are adding /folderName to it. So, the final path you are sending to the server is //folderName and that's an invalid path.

    Use the method getObjectByPath(String parentPath, String name) for save path concatenation.