cancel
Showing results for 
Search instead for 
Did you mean: 

Cant establish session with browser binding

longinus
Champ in-the-making
Champ in-the-making

Hello,

I am trying to establish a session using cmis 1.1 browser binding. My service url is :

<server:port>/<context_path>/api/-default-/cmis/versions/1.1/browser

 and setting following session parameters:

SessionParameter.BROWSER_URL, browserUrl SessionParameter.BINDING_TYPE, BindingType.BROWSER.value() ...

but getting the repository not found exception: Repository Id is not set! java.lang.IllegalStateException: Repository Id is not set! While debugging noticed that getRepositoryInfos() call overwrites the repository_id with null.

Can you advise how the session should be established, please? Do i need to enable cmis 1.1 or browser binding on the Alfresco Content Repository? Set some properties?

Kind Regards

Krzysztof

1 ACCEPTED ANSWER

jpotts
World-Class Innovator
World-Class Innovator

Check your service URL and make sure it is correct.

Also, there is no reason to specify a repository ID. Alfresco only has one repository. So you can just ask CMIS for the list of repositories and then use the first one in the list.

If you must specify a repository ID for some reason, the repository ID on most modern versions of Alfresco is "-default-".

Here is a sample class:

public class CMISExampleBase extends ExampleBase {
    private String serviceUrl = "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser";
    private Session session = null;

    public static void main(String[] args) throws Exception {
        CMISExampleBase ex = new CMISExampleBase();
        ex.setUser(args[0]);
        ex.setPassword(args[1]);
        ex.getProductInfo();
    }
   
    public void getProductInfo() {
        System.out.println(getSession().getRepositoryInfo().getProductName());
        System.out.println(getSession().getRepositoryInfo().getProductVersion());
        System.out.println(getSession().getRepositoryInfo().getId());
    }
   
    public Session getSession() {

        if (session == null) {
            // default factory implementation
            SessionFactory factory = SessionFactoryImpl.newInstance();
            Map<String, String> parameter = new HashMap<String, String>();
    
            // user credentials
            parameter.put(SessionParameter.USER, getUser());
            parameter.put(SessionParameter.PASSWORD, getPassword());
    
            // connection settings
            parameter.put(SessionParameter.BROWSER_URL, getServiceUrl());
            parameter.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());
              
            List<Repository> repositories = factory.getRepositories(parameter);
    
            this.session = repositories.get(0).createSession();
        }
        return this.session;
    }

    public String getServiceUrl() {
        return serviceUrl;
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This is a modification of the CMISExampleBase class from the CMIS examples in the Alfresco Developer Series content tutorial.

Notice on line 35 where the session that gets created just uses the first repository in the list rather than specifying a repository ID.

When you run it, it returns:

Alfresco Community
5.2.0 (r135134-b14)
-default-

So you can see that the repository ID is "-default-".

View answer in original post

3 REPLIES 3

jpotts
World-Class Innovator
World-Class Innovator

Check your service URL and make sure it is correct.

Also, there is no reason to specify a repository ID. Alfresco only has one repository. So you can just ask CMIS for the list of repositories and then use the first one in the list.

If you must specify a repository ID for some reason, the repository ID on most modern versions of Alfresco is "-default-".

Here is a sample class:

public class CMISExampleBase extends ExampleBase {
    private String serviceUrl = "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser";
    private Session session = null;

    public static void main(String[] args) throws Exception {
        CMISExampleBase ex = new CMISExampleBase();
        ex.setUser(args[0]);
        ex.setPassword(args[1]);
        ex.getProductInfo();
    }
   
    public void getProductInfo() {
        System.out.println(getSession().getRepositoryInfo().getProductName());
        System.out.println(getSession().getRepositoryInfo().getProductVersion());
        System.out.println(getSession().getRepositoryInfo().getId());
    }
   
    public Session getSession() {

        if (session == null) {
            // default factory implementation
            SessionFactory factory = SessionFactoryImpl.newInstance();
            Map<String, String> parameter = new HashMap<String, String>();
    
            // user credentials
            parameter.put(SessionParameter.USER, getUser());
            parameter.put(SessionParameter.PASSWORD, getPassword());
    
            // connection settings
            parameter.put(SessionParameter.BROWSER_URL, getServiceUrl());
            parameter.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());
              
            List<Repository> repositories = factory.getRepositories(parameter);
    
            this.session = repositories.get(0).createSession();
        }
        return this.session;
    }

    public String getServiceUrl() {
        return serviceUrl;
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This is a modification of the CMISExampleBase class from the CMIS examples in the Alfresco Developer Series content tutorial.

Notice on line 35 where the session that gets created just uses the first repository in the list rather than specifying a repository ID.

When you run it, it returns:

Alfresco Community
5.2.0 (r135134-b14)
-default-

So you can see that the repository ID is "-default-".

longinus
Champ in-the-making
Champ in-the-making

The only difference between your code and my code was OBJECT_FACTORY_CLASS property set to org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl which was causing an issue. i also had to upgrade chemistry-opencmis-client library to 0.11.0 from 0.6.0 and now the session seems to get established. Only the secondary types "custom:" are not recognized, so not sure if they need another version upgrade.

jpotts
World-Class Innovator
World-Class Innovator

Right, if you are using CMIS 1.1 you do not use the CMIS extension/Alfresco Object Factory. There is no reason to do so because the point of that library was to add support for aspects, and aspects are supported in CMIS 1.1 natively with secondary object types.

Tip: You can always check $ALFRESCO_HOME/tomcat/webapps/alfresco/WEB-INF/lib for the Chemistry JARs if you want to match the version that Alfresco ships with.

The reason your "custom:*" types are not being recognized is because you have not deployed those content models (we discussed this on the Apache Chemistry list). Look at the content types tutorial to understand how that works.

Tip: You can always use the Apache Chemistry CMIS Workbench to browse the types and secondary types that the repository knows about. If you don't see your type or secondary type listed, you won't be able to create or query that type.