Alfresco and Tapestry on the Same Tomcat Installation

cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco and Tapestry on the Same Tomcat Installation

resplin
Intermediate
0 0 1,149

Obsolete Pages{{Obsolete}}

The official documentation is at: http://docs.alfresco.com



Installation


Introduction


This page describes how to configure a Tomcat installation to run Alfresco's Web Client as one Tomcat webapp and, in parallel, a second Tomcat webapp that uses Tapestry 4.1.x and accesses the Alfresco repository.

This wiki page was not created by Alfresco engineers but contributed by community members; it is therefore neither official nor does it come with any kind of guarantee as far as accuracy and compatibility is concerned.

Requirements:


  • Alfresco 2.1
  • Tapestry 4.1.3
  • Tomcat 5.5.x

Configuration steps


Basic installation


  1. Install Tomcat & Alfresco, and Tapestry.
    Notice that the directory tomcat/shared/lib is empty and tomcat/shared/classes contains a folder hierarchy with one file (wcm-bootstrap-context.xml).
  2. Create your Tapestry webapp. I created mine using Eclipse's Web Tools Platform but you can also create it manually. Start with a very simple Tapestry webapp that – for the time being – is independent of Alfresco. (Even though the goal is to be able to query/modify the Alfresco repository from the Tapestry webapp.)
  3. Make sure both Alfresco's Web Client and your (very basic) Tapestry webapp work.

Sharing Alfresco's code base for use in other webapps (in our case, for the Tapestry webapp)


In order for the Tapestry webapp to be able to access the repository, it needs to have access to Alfresco's code base and (at runtime) to the Spring beans representing the Alfresco services (the bean serviceRegistry). For this, I followed this advice, which means:


  1. Stop Tomcat if it is running.
  2. Deploy tomcat/webapps/alfresco.war. You can do this by starting up Alfresco and shutting down again.
  3. Copy the contents of the directory tomcat/webapps/alfresco/WEB-INF/classes/ to tomcat/shared/classes/. Then remove all contents of the former directory. (We copy & delete instead of just moving in order to make sure that we do not delete the previous content in tomcat/shared/classes, which in my case – as noted above – is the single file wcm-bootstrap-context.xml.)
  4. Copty the contents of the directory tomcat/webapps/alfresco/WEB-INF/lib/ to tomcat/shared/lib/. Then remove all contents of the former directory. (Again, copy & delete instead of move in order to keep possibly existing content…)

Restart Tomcat and make sure both webapps, Alfresco's Web Client and your Tapestry webapp, continue to work.


Share Alfresco's application context with your Tapestry webapp


We need to make Alfresco's application context available to your Tapestry webapp in order to access the bean serviceRegistry from Tapestry. You can accomplish this as follows:


  • In your Tapestry webapp's WEB-INF/ directory add a file called hivemodule.xml with this content:
<module id='org.mycompany.tapestry.alfresco.AlfrescoApplicationInitializer' version='1.0.0'>

<service-point id='AlfrescoApplicationInitializer' interface='org.apache.tapestry.services.ApplicationInitializer' visibility='private'>
<invoke-factory>
  <construct class='org.mycompany.tapestry.alfresco.AlfrescoApplicationInitializer'>
  </construct>
</invoke-factory>
</service-point>

<contribution configuration-id='tapestry.init.ApplicationInitializers'>
<command after='*' id='alfresco-context' object='service:AlfrescoApplicationInitializer' />
</contribution>

</module>

  • In your Tapestry webapp's Java source code directory, add a file org/mycompany/tapestry/alfersco/AlfrescoApplicationInitializer.java with this content:
package org.mycompany.tapestry.alfresco;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;

import org.apache.tapestry.services.ApplicationInitializer;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.transaction.TransactionService;

public final class AlfrescoApplicationInitializer implements ApplicationInitializer {
private static ServletContext servletContext;
private static ServiceRegistry serviceRegistry = null;
private static TransactionService transactionService;

public void initialize(HttpServlet servlet)
{
   servletContext = servlet.getServletContext();
}

public static ServiceRegistry getServiceRegistry()
{
   if (serviceRegistry == null) {
     ServletContext alfrescoWebContext = servletContext.getContext('/alfresco');
     WebApplicationContext alfrescoSpringContext = WebApplicationContextUtils.getRequiredWebApplicationContext(alfrescoWebContext);
     serviceRegistry = (ServiceRegistry) alfrescoSpringContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
   }
   return serviceRegistry;
}
}

  • Lastly, make sure the context-entry in your Tomcat's server.xml file for your tapestry webapp has the crossContext attribute set. In my case, the entry looks as follows (yours may be different – remember that I am using Eclipse's Web Tools Platform):
<Context docBase='Foo' path='/Foo' reloadable='true' crossContext='true' source='org.eclipse.jst.j2ee.server:Foo'/>

After this steps, you should be able to start Tomcat and run both your webapps again. Also, you can now, in any Tapestry BasePage subclass run the code

   serviceRegistry = AlfrescoApplicationInitializer.getServiceRegistry();
   transactionService = serviceRegistry.getTransactionService();
   authenticationService = serviceRegistry.getAuthenticationService();
   nodeService = serviceRegistry.getNodeService();

in order to get hold of Alfresco's services. (In order to actually perform queries or edits, you have to set up a translation, see for example FirstFoundationClient.java in the Alfresco SDK.)


Open issues


  • It is not clear to me whether moving Alfresco's code and configuration files to tomcat/shared is fully supported by Alfresco.