OpenCMIS Provider Layer
The OpenCMIS provider layer hides the CMIS AtomPub and Web Services bindings and provides an interface that is very similar to the CMIS domain model. The services, operations, parameters, and structures are named after the CMIS domain model and behave as described in the CMIS specification.
The primary objective of the provider layer is to be complete, covering all CMIS operations and extension points. The result is a somewhat clunky interface. The OpenCMIS Client API sits on top of the provider layer and exposes a nicer and simpler to use interface. It is the better choice for most applications.
A connection to a CMIS repository is represented by a CmisProvider
object. Such an object can be created by the CmisProviderFactory
. The factory provides two main methods, one for each binding, that require binding specific connection information. The created CmisProvider
object exposes a binding agnostic interface.
CmisProvider
is the entry point to the CMIS services and a few utility operations. It contains a transparent cache for repository infos and type definitions. The object is serializable, although dehydrating can be expensive. CmisProvider
is thread-safe.
The get*Service()
methods provide access to the CMIS services. Some service operations take provider layer specific objects. These objects should be created with the ProviderObjectFactory
. This factory can be obtained through the getObjectFactory()
method of the CmisProvider
object.
Please refer to the OpenCMIS Commons JavaDoc and OpenCMIS Provider JavaDoc for more details on the interfaces.
Sample Code
Creating an AtomPub Provider
The AtomPub provider requires the URL of the CMIS service document. HTTP basic authentication is enabled by default and a username and a password have to be provided.
Map<String, String> parameters = new HashMap<String, String>(); parameters.put(SessionParameter.USER, user); parameters.put(SessionParameter.PASSWORD, password); parameters.put(SessionParameter.ATOMPUB_URL, url); // service document URL CmisProviderFactory factory = CmisProviderFactory.newInstance(); CmisProvider provider = factory.createCmisAtomPubProvider(parameters);
Creating a Web Services Provider
The Web Services provider requires a WSDL URL for each CMIS service. This might the same the URL for all services. WS-Security (UsernameToken) is enabled by default and a username and a password have to be provided.
Map<String, String> parameters = new HashMap<String, String>(); parameters.put(SessionParameter.USER, username); parameters.put(SessionParameter.PASSWORD, password); parameters.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, repositoryServiceWsdlUrl); parameters.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, navigationServiceWsdlUrl); parameters.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, objectServiceWsdlUrl); parameters.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, versioningServiceWsdlUrl); parameters.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, discoveryServiceWsdlUrl); parameters.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, relationshipServiceWsdlUrl); parameters.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, multiFilingServiceWsdlUrl); parameters.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, policyServiceWsdlUrl); parameters.put(SessionParameter.WEBSERVICES_ACL_SERVICE, aclServiceWsdlUrl); CmisProviderFactory factory = CmisProviderFactory.newInstance(); CmisProvider provider = factory.createCmisWebServicesProvider(parameters);
Getting an Object
The following snippet gets the name of the object "myObject" in repository "myRepository". The parameters of getObject() can be found in the CMIS specification.
CmisProvider provider = ... ObjectData myObject = provider.getObjectService().getObject("myRepository", "myObject", "*", true, IncludeRelationships.BOTH, "cmis:none", true, true, null); PropertiesData properties = myObject.getProperties(); PropertyData<String> nameProperty = properties.getProperties().get(PropertyIds.CMIS_NAME); String name = nameProperty.getFirstValue();
Custom Authentication Provider
OpenCMIS supports HTTP basic authentication for the AtomPub binding and WS-Security (UsernameToken) for the Web Services binding out of the box. Other authentication methods can be added by implementing a custom authentication provider.
Such a provider must extend org.apache.opencmis.client.provider.spi.AbstractAuthenticationProvider
and overwrite the methods getHTTPHeaders
and getSOAPHeaders
. See JavaDoc for details.
The session parameter SessionParameter.AUTHENTICATION_PROVIDER_CLASS
must be set to the fully qualified class name in order to active the authentication provider before the session is created.
For example:
Map<String, String> parameters = new HashMap<String, String>(); parameters.put(SessionParameter.AUTHENTICATION_PROVIDER_CLASS, "org.example.opencmis.MyAuthenticationProvider"); parameters.put("org.example.opencmis.user", "cmisuser"); // MyAuthenticationProvider can get and evaluate this parameters.put("org.example.opencmis.secret", "b3BlbmNtaXMgdXNlcg=="); parameters.put(SessionParameter.ATOMPUB_URL, url); // service document URL CmisProviderFactory factory = CmisProviderFactory.newInstance(); CmisProvider provider = factory.createCmisAtomPubProvider(parameters);