URL Matching Annotations
Support for annotations has been added as part of version 3 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]+)$")
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
Add a post-compile step to your ant build script (requires ant 1.7+). note, the annotation jar is included in the src version of UrlRewriteFilter.
<target name="compile-urlrewrite-conf">
<path id="annotation-classpath">
<fileset file="lib/urlrewrite-annotation-3.1.0.jar"/>
<fileset file="lib/servlet-api.jar"/>
</path>
<mkdir dir="build/WEB-INF/"/>
<apt compile="false" factory="org.tuckey.web.filters.urlrewrite.annotation.HttpUrlAPTFactory"
srcdir="src/annotation/test/" classpathref="annotation-classpath">
<option name="saveRulesTo" value="build/WEB-INF/urlrewrite-generated.xml"/>
</apt>
</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://tuckey.org/res/dtds/urlrewrite3.0.dtd"
[
<!ENTITY included SYSTEM "urlrewrite-generated.xml">
]>
<urlrewrite>
<!--
other rules...
-->
&included;
</urlrewrite>
Check your /rewrite-status for errors if things start going strange.