Create a session

There are three ways to connect to a CMIS repository:

Binding TypeDescription
Browser

The fastest and recommended binding for CMIS 1.1 repositories

Atom

Recommended for CMIS 1.0 repositories

Web services

The slowest one; it is not recommended.

Browser binding

Sample to create a connection to the CMIS repository using Browser binding:

// default factory implementation
SessionFactory factory = SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String, String>();

// user credentials
parameters.put(SessionParameter.USER, "okmAdmin");
parameters.put(SessionParameter.PASSWORD, "admin");

// connection settings
parameters.put(SessionParameter.BROWSER_URL, "http://localhost:8080/openkm/cmis/browser");
parameters.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());		

// create session
List<Repository> list= factory.getRepositories(parameters);

// List every repository found
for (Repository repository: list) {
    System.out.println("New repository found: " + repository.getId());
    System.out.println("Capabilities: ");
    System.out.println(repository.getCapabilities());	
    // Create session
    Session session = repository.createSession();			
}		

 The session object created will be used in the following sections to operate with the repository.

Atom binding

Sample to create a connection to the CMIS repository using Atom binding:

// default factory implementation
SessionFactory factory = SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String, String>();

// user credentials
parameters.put(SessionParameter.USER, "okmAdmin");
parameters.put(SessionParameter.PASSWORD, "admin");

// connection settings
parameters.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/openkm/cmis/atom");
parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());		

// create session
List<Repository> list= factory.getRepositories(parameters);

// List every repository found
for (Repository repository: list) {
    System.out.println("New repository found: " + repository.getId());
    System.out.println("Capabilities: ");
    System.out.println(repository.getCapabilities());	
    // Create session
    Session session = repository.createSession();			
}			

 The session object created will be used in the following sections to operate with the repository. 

Web services

With this code, a user can connect to the repository using web services.

Using Web services is not recommended due to slow connection response times.

// default factory implementation
SessionFactory factory = SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String, String>();

// user credentials
parameters.put(SessionParameter.USER, "okmAdmin");
parameters.put(SessionParameter.PASSWORD, "admin");

// connection settings
parameters.put(SessionParameter.BINDING_TYPE, BindingType.WEBSERVICES.value());		
parameters.put(SessionParameter.WEBSERVICES_ACL_SERVICE, "http://localhost:8080/openkm/services/cmis/ACLService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, "http://localhost:8080/openkm/services/cmis/DiscoveryService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, "http://localhost:8080/openkm/services/cmis/MultiFilingService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, "http://localhost:8080/openkm/services/cmis/NavigationService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, "http://localhost:8080/openkm/services/cmis/ObjectService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, "http://localhost:8080/openkm/services/cmis/PolicyService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, "http://localhost:8080/openkm/services/cmis/RelationshipService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, "http://localhost:8080/openkm/services/cmis/RepositoryService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, "http://localhost:8080/openkm/services/cmis/VersioningService?wsdl");

// create session
List<Repository> list= factory.getRepositories(parameters);

// List every repository found
for (Repository repository: list) {
    System.out.println("New repository found: " + repository.getId());
    System.out.println("Capabilities: ");
    System.out.println(repository.getCapabilities());	
    // Create session
    Session session = repository.createSession();			
}

 The session object created will be used in the following sections to operate with the repository.