cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting Alfresco with JAVA

fabernate
Champ in-the-making
Champ in-the-making
Hello

this line below is just what I do to connect Alfresco that I have just installed:

public static void main(String argv[]){
   
      SessionFactory factory = SessionFactoryImpl.newInstance();
      Map<String, String> parameter = new HashMap<String, String>();

      // user credentials
      parameter.put(SessionParameter.USER, "Admin");
      parameter.put(SessionParameter.PASSWORD, "Adminq1w2");

      // connection settings
      parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/cmisatom");
      parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
      parameter.put(SessionParameter.REPOSITORY_ID, "myRepository");

      // create session
      Session session = factory.createSession(parameter);
   }

just for testing….

but I get the following exception:

Exception in thread "main" org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException: Not Found
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:432)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.read(AbstractAtomPubService.java:554)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.getRepositoriesInternal(AbstractAtomPubService.java:718)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.RepositoryServiceImpl.getRepositoryInfo(RepositoryServiceImpl.java:63)
   at org.apache.chemistry.opencmis.client.bindings.impl.RepositoryServiceImpl.getRepositoryInfo(RepositoryServiceImpl.java:69)
   at org.apache.chemistry.opencmis.client.runtime.SessionImpl.connect(SessionImpl.java:676)
   at org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl.createSession(SessionFactoryImpl.java:90)
   at org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl.createSession(SessionFactoryImpl.java:64)
   at simonet.alfresco.main.Main.test2(Main.java:34)
   at simonet.alfresco.main.Main.main(Main.java:17)

YET I tried to connect to ALfresco via HTTP at the same url I pass as parameter (see above) and I get the windows Admin Passowrd and then
an xml file. So I supposed that Alfresco is running well….

more, I don't know if the parameter Repository is correct.
During the set up I didn't set any repository name, just password not even the login name
I SUPPOSE is "Admin", but never set

Thank you in advance

Regards
Fabio
5 REPLIES 5

jonash
Champ in-the-making
Champ in-the-making
Hi,

You need a valid REPOSITORY_ID parameter to connect. You could look this up for your server and pass it using the parameters hash map or just query for the list of available repositories and connect to the first (and only) one. I recommend the second option.

To do this remove the following line where the repository id is set:


parameter.put(SessionParameter.REPOSITORY_ID, "myRepository");

and replace


Session session = factory.createSession(parameter);

by


List<Repository> repositories = factory.getRepositories(parameter);
Session session = repositories.get(0).createSession();

This way you don't have to provide the repository id. OpenCMIS will fetch all available repository ids and connect to the first one. Since an Alfresco repository only has one repository id this is likely the behavior you want.

jpotts
World-Class Innovator
World-Class Innovator
I agree about grabbing the first repository in the list and creating a session from that.

But I also notice that you are using this as your service URL:
http://localhost:8080/cmisatom

When it should most likely be this:
http://localhost:8080/alfresco/cmisatom

Unless you are redirecting or have installed alfresco into your Tomcat root context or something.

Jeff

fabernate
Champ in-the-making
Champ in-the-making
Unfortunately,
because other technical problems, I am not going on with Alfresco and I was to reply
that eventually not even the second way was good throwing the exceptions anyway.

As soon as I can I will test the Jeff's

fabernate
Champ in-the-making
Champ in-the-making
That's all right Jeff, thank you!

got confused.

Regards

ivanek
Champ in-the-making
Champ in-the-making
I know the subject is more than 2 years old, but I still want to thank you Jeff, you are a lifesaver Smiley Happy