AnsweredAssumed Answered

Alfresco Open CMIS Class Cast Exception

Question asked by rutaveejshah on Aug 5, 2013
Latest reply on Aug 7, 2013 by rutaveejshah
Hello!.
I am creating a new folder using Open CMIS. But i got error like class Cast Exception.
Below is my code.

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.alfresco.cmis.client.AlfrescoFolder;
import org.apache.chemistry.opencmis.client.api.Folder;
import org.apache.chemistry.opencmis.client.api.Repository;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
private Session getSession(String serverUrl, String username, String password)
      {
      SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
      Map<String, String> params = new HashMap<String, String>();
      params.put(SessionParameter.USER, username);
      params.put(SessionParameter.PASSWORD, password);
      params.put(SessionParameter.ATOMPUB_URL, serverUrl);
      params.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
      List<Repository> repos = sessionFactory.getRepositories(params);
      if (repos.isEmpty()) {
      throw new RuntimeException("Server has no repositories!");
      }
      return repos.get(0).createSession();
      }
public void createFolder()
      {
         String servalUrl="http://localhost:8080/alfresco/service/cmis";
         String userName="admin";
         String password="admin";
      
         Map<String, Object> properties = new HashMap<String, Object>();
         properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder,P:cm:titled");
         properties.put(PropertyIds.NAME, "TestFolder3");
         properties.put(PropertyIds.CREATED_BY, "admin");
         properties.put("cm:title", "Title");
         properties.put("cm:description", "Desc");
         
         AlfrescoFolder alfFolder=(AlfrescoFolder)getSession(servalUrl, userName,password).getObjectByPath("/");
         AlfrescoFolder newFolder=(AlfrescoFolder) alfFolder.createFolder(properties);
         System.out.println(newFolder.getName());

      }



When i run this code i got the below error.
Exception in thread "main" java.lang.ClassCastException: org.apache.chemistry.opencmis.client.runtime.FolderImpl cannot be cast to org.alfresco.cmis.client.AlfrescoFolder
   at com.tcs.alfresco.sample.Test.createFolder(Test.java:59)
   at com.tcs.alfresco.sample.SampleTest.main(SampleTest.java:8)

Please if any body have any idea please reply.
Thanks in advance.

Outcomes