You want to compress CocoonServlet output from Tomcat (Standalone) ?

First you need to have a Servlet-2.3 Servlet Engine (for example Tomcat 4.x)

Then you need to do just two things:

  1. Get CompressionFilter from Tomcat-Examples and put into your Cocoon-App

  2. Modify the WebApp Deployment Descriptor (WEB-INF/web.xml) of your Cocoon-App

  3. Change Document Type to

<!DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd">

  <filter>
    <filter-name>Compression Filter</filter-name>
    <filter-class>compressionFilters.CompressionFilter</filter-class>
    <init-param>
      <param-name>compressionThreshold</param-name>
      <param-value>10</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>0</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>Compression Filter</filter-name>
    <servlet-name>Cocoon2</servlet-name>
  </filter-mapping>


Note that this will have a performance impact on your server, so test first. This probably works best with a reverse proxy in front for high traffic sites. Do also check if your reverse proxy does not support compression already. But then it might save you bandwidth and make the site virtually faster for the users as long as you have enough computing power for the compression.


TODO: Maybe Tomcat connected to Apache httpd via AJP13 and mod_gzip is a better solution, but haven't this tested though.

CocoonServletCompressionFilterSnippet (last edited 2009-09-20 23:40:41 by localhost)