cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with Repository connection using Apache Chemistry APIs

mandarj
Champ in-the-making
Champ in-the-making
Hi,

I am trying use Apache Chemistry client APIs (0.3.0 also tried 0.7.0) to connect to repository through CMIS. I tried with below code but I am not able to establish a connection to repository. I am not sure why its not creating a session. Can somebody help me in this?

The Repository I'm trying to connect is: Alfresco 3.4.1 enterprise

   try {
      log.debug("Step-1");
      SessionFactory factory = SessionFactoryImpl.newInstance();
      log.debug("Step-2");
      Map<String, String> parameter = new HashMap<String, String>();
      log.debug("Step-3");
      parameter.put(SessionParameter.USER, "{username}");
      log.debug("Step-4");
      parameter.put(SessionParameter.PASSWORD, "{password}");
      log.debug("Step-5");
      parameter.put(SessionParameter.ATOMPUB_URL, "http://hostname:8080/alfresco/cmisatom");
      log.debug("Step-6");
      parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
      log.debug("Step-7");
      parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
      log.debug("Step-8");
      List<Repository> repositories = factory.getRepositories(parameter);
      log.debug("Step-9");
      Session session = repositories.get(0).createSession();
      log.debug("Step-10");
      log.debug("Connected to repository:" + repositories.get(0).getId());
      Folder root = session.getRootFolder();
      log.debug("Step-11");
   }
   catch(CmisBaseException Excep) {
      log.debug("Error: " + Excep.getErrorContent());
   }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

It doesn't throw any exception. So, I added a logging steps as above and it looks like it gets stuck at
List<Repository> repositories = factory.getRepositories(parameter);‍


The logger says:

   Log:
   Step-1
   Step-2
   Step-3
   Step-4
   Step-5
   Step-6
   Step-7
   Step-8
   Error: null‍‍‍‍‍‍‍‍‍‍

Can you help me to solve this issue?

Thanks,
Mandar
8 REPLIES 8

jpotts
World-Class Innovator
World-Class Innovator
What version of Alfresco are you running? If you are running Alfresco 4 you are using the correct ATOMPUB_URL. If you are running Alfresco 3.x you need to use this for your URL:
http://hostname:8080/alfresco/s/api/cmis

Jeff

mandarj
Champ in-the-making
Champ in-the-making
Tried with this URL but still not working. It is stuck at same point:
 List<Repository> repositories = factory.getRepositories(parameter);‍

I am trying to connect to 3.4.1 Enterprise version.

Any idea why it is not working?

Thanks,
Mandar

mrogers
Star Contributor
Star Contributor
Is your hostname really "hostname" ?   http://hostname:8080/alfresco/cmisatom

Using a web browser can you log into http://hostname:8080/alfresco or http://hostname:8080/share

mandarj
Champ in-the-making
Champ in-the-making
No, its not exact "hostname", but I am trying with correct hostname.

I tried both:

http://<host>:<port>/alfresco/s/api/cmis
http://<host>:<port>/alfresco/cmisatom‍‍

I can access "http://<host>:<port>/alfresco" through browser. I can also connect to cmis through browser using "http://<host>:<port>/alfresco/s/api/cmis"
but not able to connect through Java code as mentioned above.

Thanks,
Mandar

jpotts
World-Class Innovator
World-Class Innovator
Please provide the full source code to your class, including import statements.

Jeff

mandarj
Champ in-the-making
Champ in-the-making
Hi Jeff,

Here is the source. (host+port name replaced by <host>:<port>)

import java.io.*;
import java.net.*;
import java.util.*;

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.client.api.*;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
import org.apache.chemistry.opencmis.commons.*;

public class CMISTest {

   public static void main(String[] args) {
         System.out.println("Repository Connection in progress.");
         try {
            System.out.println("Step-1");
            SessionFactory factory = SessionFactoryImpl.newInstance();
            System.out.println("Step-2");
            Map<String, String> parameter = new HashMap<String, String>();
            System.out.println("Step-3");
            parameter.put(SessionParameter.USER, "username");
            System.out.println("Step-4");
            parameter.put(SessionParameter.PASSWORD, "password");
            System.out.println("Step-5");
            parameter.put(SessionParameter.ATOMPUB_URL, "http://<host>:<port>/alfresco/s/api/cmis");
            System.out.println("Step-6");
            parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
            System.out.println("Step-7");
            parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
            System.out.println("Step-8");
            List<Repository> repositories = factory.getRepositories(parameter);
            System.out.println("Step-9");
            Session session = repositories.get(0).createSession();
            System.out.println("Step-10");
            System.out.println("Connected to repository:" + repositories.get(0).getId());
            Folder root = session.getRootFolder();
            System.out.println("Step-11");
            for (Tree<FileableCmisObject> item : root.getDescendants(1)) {
                  System.out.println("Itemname=" + item.getItem().getName());
                  System.out.println("Itemtype=" + item.getItem().getType().getDisplayName());
            }
            System.out.println("Reached End");
         }
         catch(CmisBaseException Excep) {
            System.out.println("Error: " + Excep.getErrorContent());
         }
   }   
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks,
Mandar

jpotts
World-Class Innovator
World-Class Innovator
Your code runs fine on my machine when running 3.4.d on localhost and OpenCMIS 0.7.0 with the OpenCMIS extension 0.2:
Repository Connection in progress.
Step-1
Step-2
Step-3
Step-4
Step-5
Step-6
Step-7
Step-8
Step-9
Step-10
Connected to repository:e7dc358f-b8c3-4473-964d-99e57d8c055f
Step-11
Itemname=Sites
Itemtype=Sites
Itemname=Data Dictionary
Itemtype=Folder
Itemname=Guest Home
Itemtype=Folder
Itemname=User Homes
Itemtype=Folder
Itemname=test
Itemtype=Folder
Itemname=Foundation API sample (1337349850801)
Itemtype=Document
Reached End‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
If you can use a web browser to log in to Alfresco on the same host and using the same username and password you are using to run your code, maybe there is some sort of network problem between your machine and your Alfresco server that is preventing Java from making a successful call.

If you have curl installed on your machine, try this:
curl -v -uadmin:admin http://localhost:8080/alfresco/s/api/cmis‍
Change admin:admin to be the same username and password you are using to test your code and change localhost and the port number to match as well. When you run it you should get atom pub back. If you do, then I'm stumped as to why your Java app won't work. If you don't get atom pub back, see if you can determine what the problem is from the error messages that do come back.

Jeff

mandarj
Champ in-the-making
Champ in-the-making
It works now!! Actually, it was an issue with version of commons-httpclient-3.1.jar that I was using. It doesn't work when I use 3.1 version of httpclient. But when I upgrade it to 4.x (httpclient-4.2.1.jar), it works.

Thanks for looking into it.

Mandar