Setting Up Cocoon 2.2 as a Tomcat Servlet

Contributor(s): Than Grove

To transform XML content into web pages, THL uses Apache Cocoon as a servlet within Tomcat. Initially, we used Cocoon 2.1.11 built into a servlet by members of the UVa library staff. In April of 2012, it was decided we should begin the migration to Cocoon 2.2, which represents a major shift in architecture and deployment. Cocoon 2.2 is fully modular, its functionality having been segregated into blocks. Furthermore, the Apache Maven program is used, instead of Ant, to build a project from Cocoon. Once the Cocoon WAR file has been built, it is easy to install but the building of the .war file is more complicated issue. To document this process, the steps taken to create the cocoon22.war file presently installed on THL's Development are detailed below.

change the line "<Cocoon-Block-Name>${pom.artifactId}</Cocoon-Block-Name>" to "<Cocoon-Block-Name>${project.artifactId}</Cocoon-Block-Name>"

Save with :x

Within the block code navigate to and edit the sitemap.xmp in vi: {block folder}/src/main/resources/COB-INF/sitemap.xmap

Remove demo pipeline code at top of the Pipelines element.

Under the Pipelines element at the top add the Pipeline code to read and use sub-directory sitemaps from the pipeline section below.

Save file with :x

Navigate back to home folder /usr/local/projects/thlib-cocoon/cocoon22 and run the command again: "mvn archetype:generate -DarchetypeCatalog=http://cocoon.apache.org" but pick option 3 and enter the following params entered upon request:

Group ID: org.thlib

Artifact ID: cocoonWebapp

Version: 1.0.0

Package: org.thlib.cocoonWebapp

Edit the file cocoonWebapp/pom.xml with vi and make the following changes:

Comment out the Jetty <plugin> definition

Add the plugin definition for either Tomcat 6 or 7, depending on which you are using. See below in Code Snippets > Plugin Definitions.

Change the line for <servlet:context …> to "<servlet:context mount-path="" context-path="file:///usr/local/projects/thlib-texts/current/cocoon/"/>"

This means that the path to invoke cocoon (mount-path) would be whatever is declared in Context Path when deployed in Context (in this case /cocoon or the full url of http://dev.thlib.org:8080/cocoon) and the root for the application (context-path) is the location of the THL XML Texts SVN repository on Dev1.

Change folder to /thlib-cocoon/cocoon22/cocoonCore/

Run "mvn install"

Change back to /thlib-cocoon/cocoon22/cocoonWebapp/

Run "mvn package"

cp cocoonWebapp-1.0.0.war to /thlib-cocoon/cocoon22/shared/

Adding Tomcat Manager To Tomcat6 Install

On Dev1 thlib.org, Tomcat manager was not installed. So, I installed that by:

Logging onto Dev1 with secureCRT

sudo su root (my password)

cd /usr/share/tomcat (though not necessary I think)

Run "sudo yum install tomcat6-admin-webapps"

cd /etc/tomcat6 and vi tomcat-users.xml, added manager-gui role and "deployer" user with the same password as on previous dev.

Restarted tomcat by doing "systemctl stop tomcat6.service" and "systemctl start tomcat6.service" as I wasn't sure if "systemctl restart tomcat6.service" was working right.

Then I could logon to manager.

Test Of Cocoon Webapp

Tried installing webapp using the manager to see if demo would work before configuring for THL:

Placed war from cocoon22/cocoonWebapp/target in /usr/local/projects/thlib-cocoon/current and created the Tomcal web app context file at /usr/local/projects/thlib-cocoon/shared/thlib-cocoon.xml

Increasing Memory for Tomcat

Turns out the memory setting for Tomcat was not boosted like it is on old Dev, Staging and Production. So edited the /etc/tomcat6/tomcat6.conf file with vi and added CATALINA_OPTS variable in the following context:

Change the line for <servlet:context …> to "<servlet:context mount-path="" context-path="file:///usr/local/projects/thlib-texts/current/cocoon/"/>"

This means that the path to invoke cocoon (mount-path) would be whatever is declared in Context Path when deployed in Context (in this case /cocoon or the full url of http://dev.thlib.org:8080/cocoon) and the root for the application (context-path) is the location of the THL XML Texts SVN repository on Dev1.

cd /usr/local/projects/thlib-cocoon/cocoon22/cocoonCore/

Run "mvn install"

cd /usr/local/projects/thlib-cocoon/cocoon22/cocoonWebapp/

Run "mvn package"

Install as above.

Potential Need for Redirect

When this was done for the new production (sdsv11), the URL used to access a cocoon site was ../cocoon/texts but the subfolders (jiats, essays, catalogs, etc.) were all in /usr/local/projects/thlib-texts/current/cocoon/. I thus needed to create a symlink *within* the cocoon folder that was called "texts" but pointed to the cocoon folder so that the url /usr/local/projects/thlib-texts/current/cocoon/texts/ would point to the cocoon folder. Thus within the cocoon folder when you "ls" it, you have the following entry: