June 17, 2019

Alfresco, check CMIS Session using Spring Interceptor

Apache Chemistry OpenCMIS provides open source implementations of the CMIS standard i.e. the abstraction layer for controlling different document management systems and ECM repositories using web protocols. OpenCMIS hides the binding details and provides APIs on different abstraction levels. Using the OpenCMIS client APIs, for example, you can develop high customizable front-end web applications that interact with the Alfresco Content Repository in a decoupled manner.

In a previous article I showed a simple example about the creation of a CMIS session using the OpenCMIS client APIs. Now, I want to move on to a much more advanced topic. In this post I show how to open and check a CMIS Session in a Spring MVC web application. The back-end ECM Content Repository will be Alfresco. To check a valid CMIS Session I use Spring HandlerInterceptor, the base object of the interceptor mechanism in the Spring MVC chain-execution (you can see more details in this article). Here is an high level representation of the client-server architecture.


In the above image the user makes access to the sampleace front-end webapp. If credentials are successfully passed, then a valid CMIS Session is created. The sampleaci is plugged-into a content repository to handle all content services using the CMIS specification and the user can interact with the Alfresco Content Repository through the sampleaci webapp.

IMPORTANT NOTICE about the openCMIS Session

“In order to be effective, this Session object has to be reused as much as possible! Don’t throw it away. Keep it and reuse it! OpenCMIS is thread-safe. The Session object can and should be reused across thread boundaries.”

Offcial wiki says OpenCMIS is thread-safe, it means the Session should be reused as much as possible. To do this I will use ThreadLocal object. Below you can see the application stack and the roadmap I used in this post.

SOURCE CODE (/giuseu/alfresco)

git clone https://gitlab.com/giuseppeurso-eu/alfresco


– SO CentOS 6.5 x86_64
– Alfresco Community 4.2.f
– JDK 1.7.0_07
– Apache Maven 3.0.4
– Eclipse Helios


STEP 1. Web project from-scratch using Maven
STEP 2. Spring MVC Dispatcher
STEP 3. Session CMIS and ThreadLocal
STEP 4. Session CMIS Interceptor
STEP 5. Spring Controller
STEP 6. Logging and test

STEP 1.  Web project from-scratch using Maven

Create a web project skeleton using Maven and import the project in Eclipse.


STEP 2. Spring MVC Dispatcher

Spring MVC dependencies in pom.xml and Spring DispatcherServlet definition in web.xml file.



STEP 3. Session CMIS e ThreadLocal

OpenCMIS dependencies in pom.xml file.

Create a class for the CMIS Session management. To create a CMIS Session against Alfresco, the createSession method makes use of the ATOMPUB service url. To reuse a valid CMIS Session, the currentSession saves  the created session in a local thread.


Here is a configuration file used by a ResouceBundle to externalize the Alfresco CMIS service url. Pay attention to the two different urls for Alfresco vers 4.0 and vers 4.2 (uncommented).


STEP 4. Session CMIS Interceptor

The Spring HandlerInterceptor takes care of intercepting all the requests on the webapp. This HandlerInterceptor‘s implementation, always checks a valid CMIS Session in the preHandle method (more info in this article).

The Interceptor definition in the spring-dispatcher.xml file.


STEP 5. Spring Controller

Here is a resume of the mapping requests for the Controller of the login and welcome pages (source code here).

The LoginController implements the method to process the login credentials submitted by the user.


STEP 6. Logging and test

Some logging definition in the log4j.xml file. Note the package eu.giuseppeurso.sampleaci.cmis is setted to debug.

Start a instance of Alfresco, deploy the sampleaci webapp in the Eclipse Tomcat and run some tests of access. Here is some results.





Related posts

Leave a Reply

Your email address will not be published.