UrlRewriteFilter 4.0.3

URL Matching Annotations

Support for annotations has been added as part of version 3 development. You must be using JDK 1.6 for this to work.

The intention of annotations in UrlRewriteFilter is purely for conf file generation. The is NO runtime dependency on the annotations.



Set the method up to be used when the url is Matched, matched groups are assigned to method paramters (if any).

    public void doSomething(Long id)

When a request for /do-something/1234, doSomething is called with id set to 1234.


Sets the parameter from request.getParameter (handles type conversion as necessary)

    void doSomething(@HttpParam String name, @HttpParam long id, @HttpParam("uid") Long userId)

The above example will:
name = request.getParameter("name");
id = convertTolongDefault0(request.getParameter("id"));
userId = convertToLongDefaultNull(request.getParameter("uid"));
An exception will never be thown during type conversion

Conf Generation

With Java 1.6 the javac tool handles annotation processing. So this means all you need to do is have a "urlrewriteDest" option specified and have urlrewritefilter annotations jar in your classpath. Example of compilerarg elements that would be used with javac ant task:

<compilerarg line="-AurlrewriteDest=build/WEB-INF/urlrewrite-generated.xml"/>
<!-- optional arguments
<compilerarg value="-AurlrewriteShowPositions=true"/>
<compilerarg value="-AurlrewriteDebug=true"/>

An example compile ant task with urlrewrite option might look like:

<target name="compile-urlrewrite-conf">
   <javac srcdir="src/" destdir="build/WEB-INF/classes">
        <classpath refid="compile.classpath"/>
        <classpath path="lib/urlrewritefilter-annotation-4.0.3.jar"/>
        <compilerarg line="-AurlrewriteDest=build/WEB-INF/urlrewrite-generated.xml"/>
   <!-- check file generated ok (if not you may be using the wrong jdk version)-->
   <available property="urlrewrite.generated" file="build/WEB-INF/urlrewrite-generated.xml"/>
   <fail unless="urlrewrite.generated" />

This will generate to the file specified. Any errors will be output to stdout using the standard APT method. Read the generated conf file and check it for errors.

Include the compiled conf file in your normal conf.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
    <!ENTITY included SYSTEM "urlrewrite-generated.xml">

        other rules...



Check your /rewrite-status for errors if things start going strange.