cancel
Showing results for 
Search instead for 
Did you mean: 

Repository connection using Apache Chemistry APIs

zepolar
Champ in-the-making
Champ in-the-making
Hi everybody!!!

I have a problem. I am trying to connect Alfresco v3.2 with Apache Chemistry 0.10.

I am using the following code that found in another forum.


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://localhost/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");


When I run the project in the console of netbeans show the follow:


session cmis
Step-1
Step-2
Step-3
Step-4
Step-5
Step-6
Step-7
Step-8
Step-9
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.745 sec <<< FAILURE!
testSessionCMIS(ec.com.linbrox.alfresco.AlfrescoUtilsV3Test)  Time elapsed: 1.684 sec  <<< ERROR!
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
   at java.util.ArrayList.rangeCheck(ArrayList.java:635)
   at java.util.ArrayList.get(ArrayList.java:411)


I don't know to do.
2 REPLIES 2

kaynezhang
World-Class Innovator
World-Class Innovator
It seems there is nothing wrong with your code,Maybe it is a bug of your alfresco version,you can try a higher version.
And you'd better  use url http://localhost/alfresco/cmisatom instead of http://localhost/alfresco/s/api/cmis.Since 3.x(I can't remember the exact version number) url http://localhost/alfresco/s/api/cmis is deprecated.

zepolar
Champ in-the-making
Champ in-the-making
Thanks kaynezhang for your answer. I installed the Alfresco 3.4 and the code works very good. I will think, the problem is Alfresco 3.2.