Helma Logo
main list history
previous version  overview  next version

Version 1 by tobi on 20. October 2008, 15:28

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|http://urlrewritefilter.googlecode.com* 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.

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

=== Prerequisites

* *Helma patched and configured|http://dev.helma.org/wiki/Setting+Up+A+Web+Application+With+Jetty+And+Helma+1.x/* to run web applications
* *UrlRewriteFilter 3.1.0|http://urlrewritefilter.googlecode.com/files/urlrewritefilter-3.1.0-src.zip* source
* *Patch|http://code.google.com/p/urlrewritefilter/source/diff?spec=svn166&r=166&format=side&path=/trunk/src/java/org/tuckey/web/filters/urlrewrite/RuleBase.java&old_path=/trunk/src/java/org/tuckey/web/filters/urlrewrite/RuleBase.java&old=146* fixing functions in Url Rewrite Filter

Apply the patch to the Java source of UrlRewriteFilter and compile by invoking <code>ant dist-jar</code>. The resulting JAR file is located in the <code>./dist/urlrewrite-3.1.0/webapp/WEB-INF/lib/</code> directory.

(Alternatively to the 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 <code>lib/ext</code> directory.)

=== 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.

Furthermore, it defines the URL path <code>/rewrite-status</code> 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|http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/3.1/index.html#configuration*.

Here's the basic setup 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>

=== Defining Rewrite Rules <code>mod_rewrite</code> Style

Although it says in the manual that UrlRewriteFilter rules can be defined with the *syntax used by Apache and the <code>mod_rewrite</code> module|http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/3.1/index.html#mod_rewrite_conf* 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|http://groups.google.com/group/urlrewrite/browse_thread/thread/49d7da989c6fbc80/b78aaae8c8d23411?hl=en&lnk=gst&q=mod_rewrite#b78aaae8c8d23411* to the UrlRewriteFilter discussion group.

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

     removed
     added