org.tuckey.web.filters.urlrewrite
Class UrlRewriteFilter

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

public 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.

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_MOD_REWRITE_STYLE_CONF_PATH
           
static java.lang.String DEFAULT_WEB_CONF_PATH
           
static java.lang.String VERSION
           
 
Constructor Summary
UrlRewriteFilter()
           
 
Method Summary
protected  void checkConf(Conf conf)
          Separate from checkConfLocal so that it can be overidden.
 void destroy()
          Destroy is called by the application server when it unloads this filter.
 void destroyActual()
           
protected  void destroyUrlRewriter()
           
 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()
           
static java.lang.String getFullVersionString()
           
 java.lang.String getStatusPath()
           
protected  UrlRewriter getUrlRewriter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          Called for every request.
 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()
           
 boolean isTimeToReloadConf()
          Is it time to reload the configuration now.
protected  void loadUrlRewriter(javax.servlet.FilterConfig filterConfig)
          Separate from init so that it can be overidden.
 void reloadConf()
          Forcibly reload the configuration now.
 
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

DEFAULT_MOD_REWRITE_STYLE_CONF_PATH

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

UrlRewriteFilter

public UrlRewriteFilter()
Method Detail

init

public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
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
Throws:
javax.servlet.ServletException

loadUrlRewriter

protected void loadUrlRewriter(javax.servlet.FilterConfig filterConfig)
                        throws javax.servlet.ServletException
Separate from init so that it can be overidden.

Throws:
javax.servlet.ServletException

checkConf

protected void checkConf(Conf conf)
Separate from checkConfLocal so that it can be overidden.


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()

destroyUrlRewriter

protected void destroyUrlRewriter()

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

getUrlRewriter

protected UrlRewriter getUrlRewriter(javax.servlet.ServletRequest request,
                                     javax.servlet.ServletResponse response,
                                     javax.servlet.FilterChain chain)
Called for every request.

Split from doFilter so that it can be overriden.


isTimeToReloadConf

public boolean isTimeToReloadConf()
Is it time to reload the configuration now. Depends on is conf reloading is enabled.


reloadConf

public void reloadConf()
Forcibly reload the configuration now.


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()

getFullVersionString

public static java.lang.String getFullVersionString()