May 22, 2017

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, the context is more complex. In this post I show an example of 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 the Spring HandlerInterceptor object, the base 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.

giuseppe-urso-alfresco-cmis-interceptor-00

In the above image the user makes directly access to the sampleace front-end. When the credentials are correctly submitted, 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.

A important note about the openCMIS Session object. In the official wiki you can read this:

“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.”

OpenCMIS is thread-safe, the Session should be reused as much as possible. I will try to do this using the ThreadLocal object. Below you can see the application stack and the roadmap I used in this post.

CHECK OUT THE SOURCE CODE

APPLICATION STACK

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

ROADMAP

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.

giuseppe-urso-alfresco-cmis-interceptor-01

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.

giuseppe-urso-alfresco-cmis-interceptor-02

giuseppe-urso-alfresco-cmis-interceptor-03

giuseppe-urso-alfresco-cmis-interceptor-04

giuseppe-urso-alfresco-cmis-interceptor-05

Related posts

Leave a Reply

Your email address will not be published.