Tuckey Logo Url Rewrite Filter 3.0.4

URL Matching Annotations

EXPIREMENTAL support for annotations has been added as part of 3.0 development. You must be using JDK 1.5 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]+)$")
        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

Add a post-compile step to your build script.


        <target name="compile-urlrewrite-conf">
            <path id="annotation-classpath">
                <path refid="compile.classpath"/>
                <path refid="compiled.classpath"/>
                <fileset file="${jdk.home}/lib/tools.jar"/>
            </path>
            <fileset id="sources" dir="." includes="src/**/actions/**/*.java"/>
            <pathconvert pathsep=" " property="sourcefiles" refid="sources"/>
            <!-- helpful for debugging classpath issues
                <property name="prop-annotation-classpath" refid="annotation-classpath"/>
                <echo>
                CLASSPATH ${prop-annotation-classpath}
                SOURCES: ${sourcefiles}
                </echo> -->
            <exec executable="apt">
                <arg value="-classpath"/>
                <arg pathref="annotation-classpath"/>
                <arg value="-nocompile"/>
                <arg value="-factory"/>
                <arg value="org.tuckey.web.filters.urlrewrite.annotation.HttpUrlAPTFactory"/>
                <arg value="-AsaveRulesTo=build/web/WEB-INF/urlrewrite-generated.xml"/>
                <arg line="${sourcefiles}"/>
            </exec>
        </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 3.0//EN"
        "http://www.tuckey.org/res/dtds/urlrewrite3.0.dtd"
[
    <!ENTITY included SYSTEM "urlrewrite-generated.xml">
]>
<!--

    Configuration file for UrlRewriteFilter
    http://www.tuckey.org/urlrewrite/

-->
<urlrewrite>

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

    &included;


</urlrewrite>

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