Helma Logo
main list history

URL Rewriting With Jetty And Helma 1.x

Due to the recent update to Jetty 6.1 in Helma the options described in this document only apply to Helma versions <=1.6.3.

The only reason why I make such a fuss about how to configure web applications with Jetty and Helma is the option of using servlet filters in web applications.

Especially the UrlRewriteFilter drew my attention because rewriting URLs is currently the only missing feature imagining Antville.org running without the great Apache webserver and with Jetty only...*

Anyway, here's outlined how I made Jetty do the same what Apache 2.0 currently does at Antville.org.

* Why I would imagine such a thing, you ask? I guess it's partly performance tweaking, partly pure curiosity.

Prerequisites

Apply the patch to the Java source of UrlRewriteFilter and compile by invoking ant dist-jar. The resulting JAR file is located in the ./dist/urlrewrite-3.1.0/webapp/WEB-INF/lib/ directory and needs to be moved to Helma's lib/ext directory.

(Alternatively to the linked patch above you also can use the one provided in the attachments or simply copy the attached urlrewrite-3.1.0.jar file in Helma's lib/ext directory.)

nametypesize
UrlRewriteFilter-fixFunctions.patchundefined bytes
urlrewrite-3.1.0.jarundefined bytes
url-rewrite-for-web.xmlundefined bytes

Enabling UrlRewriteFilter

Add the contents of the attached file url-rewrite-for-web.xml to the desired web application configuration file web.xml (in some WEB-INF directory).

The configuration prompts the web application to reload a file called rewrite.xml (also located in the WEB-INF directory) every 60 seconds. This file contains the rewrite rules (see below).

Furthermore, it defines the URL path /rewrite-status dumping the current status of the UrlRewriteFilter for debugging.

Defining Rewrite Rules

The syntax for the rewrite rules of UrlRewriteFilter are very well documented in the corresponding manual.

Here's the basic content of the rewrite.xml file I started with for emulating the current Apache rewrite rules at Antville.org:

   <?xml version="1.0" encoding="utf-8"?>
   <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN"
    "http://tuckey.org/res/dtds/urlrewrite2.6.dtd">
   <urlrewrite>
      <rule>
         <from>
            ^/helma/static/antville(.*)$
         </from>
         <to>
            /helma/static/antville$1
         </to>
      </rule>
      <rule>
         <condition type="server-name">
            ^(?:www\.)?antville\.org$
         </condition>
         <from>
            ^/(.*)$
         </from>
         <to>
            /helma/antville/$1
         </to>
      </rule>
      <rule>
         <condition type="server-name">
            ^[^.]+\.antville\.org$
         </condition>
         <from>
            ^/(.*)$
         </from>
         <to>
            /helma/antville/${replace:%{server-name}:.antville.org:}/$1
         </to>
      </rule>
   </urlrewrite>

Its main purpose is to rewrite any Antville.org URL by appending the server part (ie. the foo in foo.antville.org) after the basic path /helma/antville/, and thus, enabling host-based weblogs.

Defining Rewrite Rules mod_rewrite Style

Although it says in the manual that UrlRewriteFilter rules can be defined with the syntax used by Apache and the mod_rewrite module I did not manage to get the filter working like this.

Instead, I always get the same output of rewrite-status as described in this posting to the UrlRewriteFilter discussion group.

If someone else is more successful here please let me know. (However, I guess it's a bug in UrlRewriteFilter we will have to wait for being fixed.)