This is the first of two blogs where I demonstrate how to use the openCMIS library from a JAVA client to connect to a CMIS enabled SharePoint site through the REST Atom service of SharePoint. The “lessons learned” and tips I include come from examining MSDN and CMIS documentation, “how to” results from google searches, debugging, and the time honored “trial and error” development methodology!
Accessing SharePoint Site from JAVA Application
The following provides instructions and examples for connecting to and manipulating objects in a CMIS enabled SharePoint 2010 site from a JAVA Application using the Apache Chemistry OpenCMIS[2] API.
SharePoint 2010 Configuration
The OpenCMIS API uses the REST AtomPub services provided by a CMIS enabled SharePoint site. So the first step is to ensure the SharePoint site of interest is CMIS enabled. MSDN provides guidance for enabling CMIS in a SharePoint site[3] which I also cover in a previous blog “SharePoint 2010 – Implementing CMIS.”
Two other things are needed to connect to the SharePoint site: Authorization Credentials and the GUID of the SharePoint library of interest. CMIS Repositories are mapped to SharePoint Lists and Libraries. Unfortunately a session is based on a particular repository, so you cannot operate in two separate lists or libraries in the same session.
You need to be aware of two additional configurations in the SharePoint 2010 site: User Authorization and Versioning.
Authorization in IIS for the web site needs to match that set for the site in the Central Administration application.
Versioning is set in the SharePoint library settings. Whatever version setting is made must be mirrored in the REST method when adding a new document to the site.
Connecting to SharePoint CMIS Provider
The following is an example of connecting to a SharePoint CMIS Repository and establishing a session with that repository.
| import org.apache.chemistry.opencmis.client.api.Repository; importorg.apache.chemistry.opencmis.client.api.Session; import org.apache.chemistry.opencmis.client.api.SessionFactory; import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl; import org.apache.chemistry.opencmis.commons.SessionParameter; import org.apache.chemistry.opencmis.commons.enums.BindingType; import java.util.HashMap; import java.util.Map;public class CMISConnect { public void fillParams() {//define some values for the connection string String rest_base = “http://armwssp:2333/_vti_bin/cmis/rest”; String repository_id =”E8AE6B3A-BAC2-4B4C-B889-BAE76A8142E6″; String atompub_url = rest_base + “/” + repository_id + “?getRepositoryInfo”; String username =”username”; String password = “userpassword”; //put everything into a HashMap |
Key things to note:
1) The ATOMPUB_URL session parameter is exactly that prescribed in the MSDN library referenced on the first page.
2) You establish a session on a Repository.
3) Though you can really only see one repository at a time in SharePoint, you have to use the “getRepositories” method and the first item in the list to instantiate the Repository object.
Retrieving SharePoint Library Properties and Capabilities
Now that you have a session you can look at some of the Repository (SharePoint library) properties and capabilities.
| RepositoryInfo info = session.getRepositoryInfo(); String myInfo = “CMIS version: ” + info.getCmisVersionSupported()+ ”\n Repository ID: ” + info.getId() + ”\n Repository Name: ” + info.getName() + ”\n Product Name: ” + info.getProductName(); RepositoryCapabilities rc = soleRepository.getCapabilities(); String capabilities = twolines + “SUPPORTED CAPABILITIES:” + newline + tab + “isAllVersionsSearchableSupported: ” + rc.isAllVersionsSearchableSupported() + newline + tab + “isGetDescendantsSupported: ” + rc.isGetDescendantsSupported()+ newline + tab + “isGetFolderTreeSupported: ” + rc.isGetFolderTreeSupported()+ newline + tab + “isMultifilingSupported: ” + rc.isMultifilingSupported()+ newline + tab + “isPwcSearchableSupported: ” + rc.isPwcSearchableSupported()+ newline + tab + “isPwcUpdatableSupported: ” + rc.isPwcUpdatableSupported()+ newline + tab + “isUnfilingSupported: ” + rc.isUnfilingSupported()+ newline + tab + “isVersionSpecificFilingSupported: ” + rc.isVersionSpecificFilingSupported()+ newline + tab + “CapabilityContentStreamUpdates: ” + rc.getContentStreamUpdatesCapability() + newline + tab + “getChangesCapability: ” + rc.getChangesCapability() + newline + tab + “getRenditionsCapability: ” + rc.getRenditionsCapability() + newline + tab + “CapabilityQuery: ” + rc.getQueryCapability() + newline + tab + “CapabilityJoin: ” + rc.getJoinCapability() + newline + tab + “CapabilityAcl: ” + rc.getAclCapability(); |
Results:
| CMIS version: 1.0Repository ID: e8ae6b3a-bac2-4b4c-b889-bae76a8142e6 Repository Name: Shared Documents Product Name: Office SharePoint Server SUPPORTED CAPABILITIES: isAllVersionsSearchableSupported: false isGetDescendantsSupported: false isGetFolderTreeSupported: true isMultifilingSupported: false isPwcSearchableSupported: true isPwcUpdatableSupported: true isUnfilingSupported: false isVersionSpecificFilingSupported: false CapabilityContentStreamUpdates: ANYTIME getChangesCapability: OBJECTIDSONLY getRenditionsCapability: NONE CapabilityQuery: BOTHESEPARATE CapabilityJoin: NONE CapabilityAcl: MANAGE |
Things to note:
1) Getting a RepositoryInfo object was not necessary – the same methods are available to the Repository object.
2) “twolines”, “newline”, and “tab” are public string variables I created for formatting purposes.
3) The “getCapabilities” method of the respository sets the RespositoryCapabilities object, but that object is not iterable, so you have to retrieve the capabilities you are interested in individually.
I hope that I have shown how you can use the Chemistry openCMIS library to connect to a CMIS enabled SharePoint 2010 site through the REST Atom Service and look at some of the SharePoint site’s capabilities.
In my next blog I will show how you how to use the openCMIS library and REST Atom Service to:
1) Access and Create Folders; 2) Iterate over SharePoint folders; and 3) Add documents to a SharePoint folder.

Subscribe via RSS