Obsolete Pages{{Obsolete}}
The official documentation is at: http://docs.alfresco.com
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:
tomcat/shared/lib
is empty and tomcat/shared/classes
contains a folder hierarchy with one file (wcm-bootstrap-context.xml
).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:
tomcat/webapps/alfresco.war
. You can do this by starting up Alfresco and shutting down again.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
.)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.
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:
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>
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;
}
}
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.)
tomcat/shared
is fully supported by Alfresco.