Create a session
There are three ways to connect to CMIS repository:
Binding Type | Description |
---|---|
Browser |
The fastest and the recommended for CMIS 1.1 repositories |
Atom |
Recommended for CMIS 1.0 repositories |
Web services |
The slowest one and not recommended. |
Browser binding
Sample to create a connection to the CMIS reposiroty 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.
Use Web services is not recommend due slowest connection response.
// 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.