cancel
Showing results for 
Search instead for 
Did you mean: 

Error while finding folder in repository

knkpchari
Champ in-the-making
Champ in-the-making
Hi All,

When i am trying to find the folder details in repository using below code i am getting error which is a number changing every time. How to solve can any one help me in this.

public String DISCOVERY_SERVICE_WSDL_LOCATION = "/alfresco/cmisws/DiscoveryService?wsdl";
public final static QName DISCOVERY_SERVICE_NAME = new QName("http://docs.oasis-open.org/ns/cmis/ws/200908/", "DiscoveryService");

query.setStatement("select * from cmis:folder where cmis:name LIKE '"+reg_id+"'");
QueryResponse queryresponse=null;
try{
    queryresponse = disvcoveryServicePort.query(query);
}catch(CmisException ex){
    System.out.println("The value of exception ::::::::::::"+ex.getMessage());
    ex.printStackTrace();
}

I am using Alfresco4.0. The above code is working fine in alfresco3.4.

Regards,
Naveen
10 REPLIES 10

kaynezhang
World-Class Innovator
World-Class Innovator
It is not recommended to call disvcoveryServicePort directly ,you can use opencmis api instead.

knkpchari
Champ in-the-making
Champ in-the-making
hi,
Thanks for you reply. Can you please suggest some material on this as in am not getting equivakent for navigation service.

Regards,
Naveen

kaynezhang
World-Class Innovator
World-Class Innovator
For query,you can use apache chemistry opencmis client and execute cmis query like following,

String url= "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom"; //for 1.1
//String url= "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.0/atom"; //for 1.0
      SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
      Map<String, String> params = new HashMap<String, String>();
      params.put(SessionParameter.USER, "admin");
      params.put(SessionParameter.PASSWORD, "admin");
      params.put(SessionParameter.ATOMPUB_URL, url);
      params.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
      params.put(SessionParameter.OBJECT_FACTORY_CLASS,
            "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
      List<Repository> repos = sessionFactory.getRepositories(params);
      if (repos.isEmpty()) {
         throw new RuntimeException("Server has no repositories!");
      }

      Session session = repos.get(0).createSession();
      ItemIterable<QueryResult> qrs = session.query("select * from cmis:folder where cmis:name LIKE '"+reg_id+"'", false);
      for(QueryResult q : qrs) {

      }

For navigation,you can use getObject()/getObjectByPath() method of Session class and combine getDescendants/getChildren method of Folder class
or You just get navigation service from binding and use it directly,like following:
 
session.getBinding().getNavigationService()

knkpchari
Champ in-the-making
Champ in-the-making
Thanks kaynezhang your reply really support me. I had followed the url for cmis
https://github.com/jpotts/alfresco-developer-series/blob/master/content/content-tutorial-cmis/src/ma...

downloaded cmis from :
http://chemistry.apache.org/java/download.html

Where as in my alfresco i am getting error for
Cannot access WSDL: http://localhost:9080/chemistry/browser/RepositoryService

can you  please sugget what might be the problem or how to publish this now.

Regards,
Naveen

knkpchari
Champ in-the-making
Champ in-the-making
Hi,
After changing the url for webservice i am getting error as below:

Changed url : parameter.put(SessionParameter.WEBSERVICES_ACL_SERVICE, serviceUrl + "/ACLService?wsdl");

Error is occurred when i am calling
session = factory.createSession(parameter);
<blockcode>19:17:55,617 ERROR [STDERR] Caused by: java.lang.ClassCastException: $Proxy456 cannot be cast to com.sun.xml.ws.developer.WSBindingProvider

19:17:55,620 ERROR [STDERR]    at org.apache.chemistry.opencmis.client.bindings.spi.webservices.SunRIPortProvider.createPortObject(SunRIPortProvider.java:85)

19:17:55,622 ERROR [STDERR]    … 77 more</blockcode>

kaynezhang
World-Class Innovator
World-Class Innovator
What bindding are you using? you are using browser binding? why do you provide a url like
http://localhost:9080/chemistry/browser/RepositoryService

Please paste your code here.

knkpchari
Champ in-the-making
Champ in-the-making
I am using webservice binding

SessionFactory factory = SessionFactoryImpl.newInstance();
        Map<String, String> parameter = new HashMap<String, String>();
        serviceUrl=alfrescoURL+"/alfresco/cmis";
        // user credentials
        parameter.put(SessionParameter.USER, cmsUser);
        parameter.put(SessionParameter.PASSWORD, cmsPassword);

       
        parameter.put(SessionParameter.BINDING_TYPE, BindingType.WEBSERVICES.value());
        parameter.put(SessionParameter.WEBSERVICES_ACL_SERVICE, serviceUrl + "/ACLService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, serviceUrl + "/DiscoveryService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, serviceUrl + "/MultiFilingService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, serviceUrl + "/NavigationService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, serviceUrl + "/ObjectService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, serviceUrl + "/PolicyService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, serviceUrl + "/RelationshipService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, serviceUrl + "/RepositoryService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, serviceUrl + "/VersioningService?wsdl");
        parameter.put(SessionParameter.REPOSITORY_ID, repositoryId);
       
        session = factory.createSession(parameter);


i am getting the error as shown above…kindly let me know how to get session object.

Regards,
Naveen

kaynezhang
World-Class Innovator
World-Class Innovator
Following is sample code ,please write it like this

   public static String webservicesUrl="http://localhost:8080/alfresco/cmisws/";
   public static String username="admin";
   public static String password="admin";
   public static Session getSession()

   {

      SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
      Map<String, String> parameter = new HashMap<String, String>();
      parameter.put(SessionParameter.USER, username);
      parameter.put(SessionParameter.PASSWORD, password);
        final String BINDING_TYPE = BindingType.WEBSERVICES.value();
        parameter.put(SessionParameter.BINDING_TYPE, BINDING_TYPE);
        parameter.put(SessionParameter.WEBSERVICES_ACL_SERVICE, webservicesUrl + "/ACLService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, webservicesUrl + "/DiscoveryService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, webservicesUrl + "/MultiFilingService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, webservicesUrl + "/NavigationService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, webservicesUrl + "/ObjectService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, webservicesUrl + "/PolicyService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, webservicesUrl + "/RelationshipService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, webservicesUrl + "/RepositoryService?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, webservicesUrl + "/VersioningService?wsdl");

       
        parameter.put(SessionParameter.OBJECT_FACTORY_CLASS,
            "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
      List<Repository> repos = sessionFactory.getRepositories(parameter);
      if (repos.isEmpty()) {
         throw new RuntimeException("Server has no repositories!");
      }

      return repos.get(0).createSession();
   }

knkpchari
Champ in-the-making
Champ in-the-making
Hi kaynezhang,

After changing url for webservice to
http://localhost:8080/alfresco/cmisws/NavigationService?wsdl
Stil i am getting error at
List<Repository> repos = factory.getRepositories(parameter);
Is there any problem with alfresco 4.0 with cmis.

Please suggest what should i do for getting session so that i can create a folder.
My initial code is in alfresco3.4d with direct web services which is working fine, same code is not working for me on alfresco4.0 so i changed to cmis.
Error:
<block>Caused by: java.lang.ClassCastException: $Proxy456 cannot be cast to com.sun.xml.ws.developer.WSBindingProvider
08:42:03,293 ERROR [STDERR]    at org.apache.chemistry.opencmis.client.bindings.spi.webservices.SunRIPortProvider.createPortObject(SunRIPortProvider.java:85)</block>

Regards,
Naveen