Url Rewrite Filter 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.

Annotations

@HttpUrl

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


    @HttpUrl("^/do-something/([0-9]+)$")
    public void doSomething(Long id)
    

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

@HttpParam

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"/>
   </javac>
   <!-- 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" />
</target>

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"
        "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd"
[
    <!ENTITY included SYSTEM "urlrewrite-generated.xml">
]>
<urlrewrite>

    <!--
        other rules...
    -->

    &included;


</urlrewrite>

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