« Torna a Configuring

Alfresco integration

Introduction #

With Alfresco 3.0, deploying Alfresco in its entirety as a portlet into Liferay is highly discouraged and will likely not work. Depending on your content management needs it's possible the built-in portlets such as the Document Library may suit your needs. However, if you do need to use Alfresco, there are different approaches you can take. Some of them are explored below.

Using the Web Script Container #

Alfresco has de-coupled the Web Script Container from the core Alfresco application such that it can be deployed independently as a portlet into Liferay or other portals.

As of Alfresco Enterprise 3.2r, Web Script-based portlets have SSO support and can be deployed rather easily.

Read this tutorial to learn more about this new Alfresco portlet development option.

Alfresco Web script Portlet rivet#

AWPr (Alfresco Web Script Portlet rivet) is a JSR-286 portlet that can be used to expose remote Alfresco Web scripts, including those that need user authentication. With the help of a custom Alfresco authentication component that we wrote, the portlet can carry the user credentials from the portal to Alfresco, authenticate the user in Alfresco and retrieve a ticket that can be used during all subsequent interactions between the end-user, the portlet and ultimately the Alfresco Web script itself.

This portlet alleviates the need for having to deploy all of Alfresco inside the portal as is the case when using Alfresco's OOTB (out-of-the-box) Web script portlet. http://forge.rivetlogic.com/Forge/Rivets/Alfresco-Web-script-Portlet

Using the CMIS Proposed Standard #

Recently, Alfresco, IBM, Microsoft, Documentum and others announced the submission of a new content management standard proposal called "CMIS" or "Content Management Interoperability Service". Alfresco has released an initial implementation of this proposed standard which includes support for REST-like RPC and SOAP-based web services. This provides the Liferay community with a cross-platform mechanism of integrating not just with Alfresco, but with any other content management system that supports the specification.

The Apache Adbdera library may be used to parse the ATOM-formated CMIS responses but here's a sample of a portlet that uses a basic XML parser to do the same:

package training;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletSecurityException;
import javax.portlet.PortletSession;
import javax.portlet.PortletURL;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class AlfrescoTrainingPortlet extends GenericPortlet {

	@Override
	protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
		response.setContentType("text/html");
		
		HttpClient client = new HttpClient();
		client.getParams().setAuthenticationPreemptive(true);
		Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin");
		client.getState().setCredentials(AuthScope.ANY, defaultcreds);
		String url;
		
		String objectIdParam = (String) request.getPortletSession().getAttribute("objectId", PortletSession.PORTLET_SCOPE);
		if (objectIdParam == null) {
			url = "http://localhost:8080/alfresco/s/api/path/workspace/SpacesStore/Company%20Home/children";
		} else {
			url = "http://localhost:8080/alfresco/s/api/node/workspace/SpacesStore/" + objectIdParam + "/children";
		}
		
		GetMethod method = new GetMethod(url);
		client.executeMethod(method);
		
		PortletURL actionURL = response.createActionURL();
		
		PrintWriter writer = response.getWriter();
		try {
			Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(method.getResponseBodyAsStream());
			NodeList list = dom.getElementsByTagName("cmis:propertyId");
			int len = list.getLength();
			
			for (int i = 0; i < len; i++) {
				Element element = (Element) list.item(i);
				String propertyName = element.getAttribute("cmis:name");
				String objectId = null;
				if (propertyName.equals("ObjectId")) {
					objectId = element.getElementsByTagName("cmis:value").item(0).getTextContent();
					objectId = objectId.replaceAll("workspace://SpacesStore/", "");
					writer.println("<p>" + objectId);
				}
				if (objectId == null) {
					continue;
				}
				NodeList stringList = ((Element) element.getParentNode()).getElementsByTagName("cmis:propertyString");
				int stringSize = stringList.getLength();
				for (int j = 0; j < stringSize; j++) {
					Element strElem = ((Element) stringList.item(j));
					String strName = strElem.getAttribute("cmis:name");
					if (strName.equals("Name")) {
						actionURL.setParameter("objectId", objectId);
						writer.println("<a href='" + actionURL.toString() + "'>" + strElem.getTextContent() + "</a>");
						break;
					}
				}
			}
		} catch (Exception exc) {
			exc.printStackTrace();
		}
		
		//response.getWriter().println(method.getResponseBodyAsString());
	}

	@Override
	public void processAction(ActionRequest request, ActionResponse response)
			throws PortletException, PortletSecurityException, IOException {
		String objectId = request.getParameter("objectId");
		if (objectId != null) {
			request.getPortletSession().setAttribute("objectId", objectId, PortletSession.PORTLET_SCOPE);
		}
	}
}//

Other REST APIs #

In addition to the proposed CMIS standard, Alfresco has exposed a myriad of REST-like APIs for services such as workflow, tagging, thumbnailing, user management and more. These services are documented in the Alfresco 3.0 REST API wiki page.

RAAr (Remote Alfresco API rivet) #

Another recently available option is presented by Rivet Logic's Remote Alfresco API rivet (also referred to as RAAr). This API is a Java API that uses REST calls to communicate with a remote Alfresco repository. The advantage of this approach is that it provides all the pros of the web services approach and does not carry the burden of the SOAP stack thus making it an attractive option for Java portlet developers.

RAAr is open source and is currently maintained by Rivet Logic Corporation. It provides most (if not all) of the Alfresco Foundation Service methods. It can be used to do anything that the Alfresco web client can do.

More information about RAAr can be found at this url: http://wiki.rivetlogic.com/display/RAAr

An example demo web client written by Rivet Logic that makes use of RAAr can be found at this location: http://scar.rivetlogic.com

Using your own API #

Some users (like Ruben Gonzalo Garcia) have succesfully written their own API for communicating Liferay with Alfresco.

This method consists on creating an API which communicates with Alfresco, this API is independent from Liferay, you can use it in a portlet, a servlet or a normal java application and this API allows you to search, delete, send documents...etc to Alfreso through Web Services. You can find all the libraries you need for communicating with Alfresco here: http://sourceforge.net/project/showfiles.php?group_id=143373&package_id=178146&release_id=524563

For example, you can search in a space (filtering by one property) and you obtain a list with all the documents found. Then, in your Liferay Portlet you can work with that list as you prefer.

The main advantage is that allows you to have Liferay and Alfresco in different machines, which is very positive, as they are heavy applications. The main disadvantage is that Web Services is quite slow.

Some examples can be found at the following link: http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/sdk/samples/WebServiceSamples/source/org/alfresco/sample/webservice/

Some references from Alfresco can be found here: http://wiki.alfresco.com/wiki/Alfresco_Content_Management_Web_Services

Pagine dei bambini

0 Allegati
108667 Visualizzazioni
Media (0 Voti)
La media del punteggio è 0.0 stelle su 5.
Commenti
Commenti Autore Data
Hi, Could you explain in more detail why... Javier Arnáiz 15 gennaio 2009 8.25
Hi Javier, It IS possible to integrate... Jonas Yuan 27 gennaio 2009 8.20
There is also a FlexSpaces for Alfresco Liferay... Steve Reiner 13 novembre 2009 12.19

Hi,
Could you explain in more detail why Alfresco 3.0 can't be integrated as a portlet in Liferay? Is not it possible to resolve in a later version?

Thank you very much for the article.
Inviato il 15/01/09 8.25.
Hi Javier,

It IS possible to integrate Alfresco 3.0 as a portlet in Liferay, using above options: REST Web Scripts, CMIS, even Alfresco web client. Here are integration examples: (both REST and WEB Client): http://liferay.cignex.com.
Inviato il 27/01/09 8.20 in risposta a Javier Arnáiz.
There is also a FlexSpaces for Alfresco Liferay Portlet
http://www.liferay.com/web/guest/downloads/community_plugins/-/software_c­atalog/products/3879045
Inviato il 13/11/09 12.19.