org.tuckey.web.filters.urlrewrite
Class UrlRewriteFilter

java.lang.Object
  extended by org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
All Implemented Interfaces:
javax.servlet.Filter

public final class UrlRewriteFilter
extends java.lang.Object
implements javax.servlet.Filter

Based on the popular and very useful mod_rewrite for apache, UrlRewriteFilter is a Java Web Filter for any J2EE compliant web application server (such as Resin or Tomcat), which allows you to rewrite URLs before they get to your code. It is a very powerful tool just like Apache's mod_rewrite.

The main things it is used for are:

UrlRewriteFilter uses an xml file, called urlrewrite.xml (lives in the WEB-INF directory), for configuration. Most parameters can be Perl5 style Regular Expressions or Wildcards (i.e. *). This makes it very powerful indeed.

Special thanks to all those who gave patches/feedback especially Vineet Kumar.

Thanks also to Ralf S. Engelschall (www.engelschall.com) the inventor of mod_rewrite.

todo: ability to have no from, just conditions matches

todo: user in role throw 403 if no match?

todo: ability to set default-to-type on level of conf file for conf files full of redirects

todo: ability to test new conf without having to reload, via status page

todo: allow condition matching on get-param or post-param as well as just parameter

todo: store list of robots and hide jsessionid when a robot also have condition

todo: allow mounting of packages from /xxxyyy/aaa.gif to org.tuckey.xxx.static."aaa.gif" http://wiki.opensymphony.com/pages/viewpage.action?pageId=4476

todo: will conflict with run in a rule init?

todo: handle exceptions, condition exception regex match name

todo: instanceof in urlrewrite filter conditions

todo: consider using http://dtddoc.sourceforge.net/documentation.html

todo: random condition type 2. A randomized condition, i.e. a condition which is true with a certain probability. 3. A round robin condition, i.e. a condition which is true every n-th time.

todo: backrefs in sets

todo: no error is trapped correctly and conf.isOk still return true???

todo: better debugging of server name matcher

todo: debugging tool especially googlebot client debugger, possibly googlebot tag

todo: ability to set request parameters

todo: ability to specify a $1 as $encode($1) (or something like that)

todo: pull out exception condition type?

todo: struts will call context.getNamedDispatcher() to similar

todo: grouping of rule for default settings

todo: capture original (pre match) url into request attr so that people can use it

todo: to UrlRewrite is there a way to compare ALL parameters with a pattern? As far as i understand the manual i allways have to provide a name when using type="parameter" in a condition. todo: javaFreak 12/13/06 In Apache: RewriteEngine on RewriteMap upper2lower int:tolower RewriteRule ^/(.*)$ /${upper2lower:$1} todo: Rostislav Hristov

Version:
$Revision: 51 $ $Date: 2006-12-08 11:37:07 +1300 (Fri, 08 Dec 2006) $
Author:
Paul Tuckey

Field Summary
static java.lang.String DEFAULT_WEB_CONF_PATH
           
static java.lang.String VERSION
           
 
Constructor Summary
UrlRewriteFilter()
           
 
Method Summary
 void destroy()
          Destroy is called by the application server when it unloads this filter.
 void destroyActual()
           
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          The main method called for each request that this filter is mapped for.
 int getConfReloadCheckInterval()
          The amount of seconds between reload checks.
 java.util.Date getConfReloadLastCheck()
           
 java.lang.String getStatusPath()
           
 void init(javax.servlet.FilterConfig filterConfig)
          Init is called automatically by the application server when it creates this filter.
 boolean isConfReloadCheckEnabled()
           
 boolean isLoaded()
           
 boolean isStatusEnabled()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
See Also:
Constant Field Values

DEFAULT_WEB_CONF_PATH

public static final java.lang.String DEFAULT_WEB_CONF_PATH
See Also:
Constant Field Values
Constructor Detail

UrlRewriteFilter

public UrlRewriteFilter()
Method Detail

init

public void init(javax.servlet.FilterConfig filterConfig)
Init is called automatically by the application server when it creates this filter.

Specified by:
init in interface javax.servlet.Filter
Parameters:
filterConfig - The config of the filter

destroy

public void destroy()
Destroy is called by the application server when it unloads this filter.

Specified by:
destroy in interface javax.servlet.Filter

destroyActual

public void destroyActual()

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws java.io.IOException,
                     javax.servlet.ServletException
The main method called for each request that this filter is mapped for.

Specified by:
doFilter in interface javax.servlet.Filter
Parameters:
request - the request to filter
response - the response to filter
chain - the chain for the filtering
Throws:
java.io.IOException
javax.servlet.ServletException

isConfReloadCheckEnabled

public boolean isConfReloadCheckEnabled()

getConfReloadCheckInterval

public int getConfReloadCheckInterval()
The amount of seconds between reload checks.

Returns:
int number of millis

getConfReloadLastCheck

public java.util.Date getConfReloadLastCheck()

isStatusEnabled

public boolean isStatusEnabled()

getStatusPath

public java.lang.String getStatusPath()

isLoaded

public boolean isLoaded()