Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

OpenCMIS

...

Client Bindings

The OpenCMIS provider client bindings 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 client bindings 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 CmisBinding object. Such an object can be created by the CmisProviderFactory CmisBindingFactory. The factory provides two main methods, one for each binding, that require binding specific connection information. The created CmisProvider CmisBinding object exposes a binding agnostic interface.

CmisProvider CmisBinding 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 CmisBinding 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 BindingsObjectFactory. This factory can be obtained through the getObjectFactory() method of the CmisProvider CmisBinding object.

Please refer to the OpenCMIS Commons JavaDoc and OpenCMIS Provider Client Binding JavaDoc for more details on the interfaces.

Sample Code

Creating an AtomPub

...

binding instance

The AtomPub provider binding 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.

Code Block
java
java
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

CmisProviderFactoryCmisBindingFactory factory = CmisProviderFactoryCmisBindingFactory.newInstance();
CmisProviderCmisBinding providerbinding = factory.createCmisAtomPubProvidercreateCmisAtomPubBinding(parameters);

Creating a Web Services

...

binding instance

The Web Services provider binding 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.

Code Block
java
java
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);

CmisBindingFactory factory = CmisBindingFactory.newInstance();

CmisProviderFactoryCmisBinding binding = factory.createCmisWebServicesBinding(parameters);

Creating a Local binding instance

The Local binding connects to an OpenCMIS server in the same JVM. The server factory class name has to be supplied.

Code Block
java
java

Map<String, String> parameters = new HashMap<String, String>();

parameters.put(SessionParameter.USER, user);
parameters.put(SessionParameter.PASSWORD, password);

parameters.put(SessionParameter.LOCAL_FACTORY, factoryClassName);

CmisBindingFactory factory = CmisProviderFactoryCmisBindingFactory.newInstance();
CmisProviderCmisBinding providerbinding = factory.createCmisWebServicesProvidercreateCmisLocalBinding(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.

Code Block
java
java
CmisProviderCmisBinding providerbinding = ...

ObjectData myObject = providerbinding.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.chemistry.opencmis.client.provider.spi.AbstractAuthenticationProvider and overwrite the methods getHTTPHeaders and getSOAPHeaders. See JavaDoc for details.

...

Code Block
java
java
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

CmisProviderFactoryCmisBindingFactory factory = CmisProviderFactoryCmisBindingFactory.newInstance();
CmisProviderCmisBinding provider = factory.createCmisAtomPubProvidercreateCmisAtomPubBinding(parameters);