Creating a Session
A session is the entry point to the content repository. Creating a session is the first thing an application has to do to interact with the repository.
A few details such as the URL of the repository endpoint, the user name and the user’s credentials are necessary to establish a session. Beyond that more details might be required, depending on the repository and the environment. Those details are controlled by session parameters.
A complete list of all session parameters for OpenCMIS can be found in the JavaDoc. For PortCMIS, please refer to the help file that is contained in the binary packages.
Session objects can be expensive to create and should be kept as long as possible. Most OpenCMIS and PortCMIS objects, including session objects, are thread safe. They can and should be reused across threads to reduce the number of calls to the repository.
A session object manages a set of caches that keeps object metadata (properties values, Allowable Actions, ACL, etc.), paths information, and type metadata in memory. There is no content cache.
There is no fixed lifetime of a session object. It can be used for a long time. Only if the repository requires cookies that expire it may have to be recreated from time to time. There is no need to close a session or clean its caches if you don’t need it anymore. Just let the GC deal with it.
Which binding should I use?
The Browser Binding is the fastest binding and is recommended for CMIS 1.1 repositories.
Choose the AtomPub Binding for CMIS 1.0 repositories.
The Web Services Binding is the last resort and should be avoided. It is the slowest binding and is the most complex to set up.
AtomPub Binding
CMIS 1.0 CMIS 1.1
OpenCMIS (Java)
// default factory implementation
SessionFactory factory = SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String, String>();
// user credentials
parameters.put(SessionParameter.USER, "Otto");
parameters.put(SessionParameter.PASSWORD, "****");
// connection settings
parameters.put(SessionParameter.ATOMPUB_URL, "http://<host>:<port>/cmis/atom");
parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
parameters.put(SessionParameter.REPOSITORY_ID, "myRepository");
// create session
Session session = factory.createSession(parameters);
PortCMIS (C#)
// default factory implementation
SessionFactory factory = SessionFactory.NewInstance();
Dictionary<string, string> parameters = new Dictionary<string, string>();
// user credentials
parameters[SessionParameter.User] = "Otto";
parameters[SessionParameter.Password] = "****";
// connection settings
parameters[SessionParameter.AtomPubUrl] = "http://<host>:<port>/cmis/atom";
parameters[SessionParameter.BindingType] = BindingType.AtomPub;
parameters[SessionParameter.RepositoryId] = "myRepository";
// create session
ISession session = factory.CreateSession(parameters);
Browser Binding
CMIS 1.1
OpenCMIS (Java)
// default factory implementation
SessionFactory factory = SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String, String>();
// user credentials
parameters.put(SessionParameter.USER, "Otto");
parameters.put(SessionParameter.PASSWORD, "****");
// connection settings
parameters.put(SessionParameter.BROWSER_URL, "http://<host>:<port>/cmis/browser");
parameters.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());
parameters.put(SessionParameter.REPOSITORY_ID, "myRepository");
// create session
Session session = factory.createSession(parameters);
PortCMIS (C#)
// default factory implementation
SessionFactory factory = SessionFactory.NewInstance();
Dictionary<string, string> parameters = new Dictionary<string, string>();
// user credentials
parameters[SessionParameter.User] = "Otto";
parameters[SessionParameter.Password] = "****";
// connection settings
parameters[SessionParameter.BrowserUrl] = "http://<host>:<port>/cmis/browser";
parameters[SessionParameter.BindingType] = BindingType.Browser;
parameters[SessionParameter.RepositoryId] = "myRepository";
// create session
ISession session = factory.CreateSession(parameters);
Web Services Binding
CMIS 1.0 CMIS 1.1
PortCMIS does not support the Web Service binding.
OpenCMIS (Java)
// default factory implementation
SessionFactory factory = SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String, String>();
// user credentials
parameters.put(SessionParameter.USER, "Otto");
parameters.put(SessionParameter.PASSWORD, "****");
// connection settings
parameters.put(SessionParameter.BINDING_TYPE, BindingType.WEBSERVICES.value());
parameters.put(SessionParameter.WEBSERVICES_ACL_SERVICE, "http://<host>:<port>/cmis/services/ACLService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, "http://<host>:<port>/cmis/services/DiscoveryService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, "http://<host>:<port>/cmis/services/MultiFilingService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, "http://<host>:<port>/cmis/services/NavigationService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, "http://<host>:<port>/cmis/services/ObjectService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, "http://<host>:<port>/cmis/services/PolicyService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, "http://<host>:<port>/cmis/services/RelationshipService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, "http://<host>:<port>/cmis/services/RepositoryService?wsdl");
parameters.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, "http://<host>:<port>/cmis/services/VersioningService?wsdl");
parameters.put(SessionParameter.REPOSITORY_ID, "myRepository");
// create session
Session session = factory.createSession(parameters);
Local Binding
CMIS 1.0 CMIS 1.1
The local binding is specific to OpenCMIS. It lets an OpenCMIS client connect to an OpenCMIS server in the same JVM. There is no PortCMIS equivalent.
OpenCMIS (Java)
// default factory implementation
SessionFactory factory = SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String, String>();
// user credentials
parameters.put(SessionParameter.USER, "Otto");
parameters.put(SessionParameter.PASSWORD, "****");
// connection settings
parameters.put(SessionParameter.BINDING_TYPE, BindingType.LOCAL.value());
parameters.put(SessionParameter.LOCAL_FACTORY, "my.local.factory");
parameters.put(SessionParameter.REPOSITORY_ID, "myRepository");
// create session
Session session = factory.createSession(parameters);
Connecting to the First Repository
Some CMIS endpoints only provide one repository. In this case it is not necessary to provide its repository ID. The following code snippet gets the list of all available repositories and connects to the first one.
OpenCMIS (Java)
SessionFactory factory = SessionFactoryImpl.newInstance();
List<Repository> repositories = factory.getRepositories(parameters);
Session session = repositories.get(0).createSession();
PortCMIS (C#)
SessionFactory factory = SessionFactory.NewInstance();
ISession session = factory.GetRepositories(parameters)[0].CreateSession();