javawebparts.filter
Class URLRedirectFilter

java.lang.Object
  |
  +--javawebparts.filter.URLRedirectFilter
All Implemented Interfaces:
javax.servlet.Filter

public class URLRedirectFilter
extends java.lang.Object
implements javax.servlet.Filter

This filter allows you to redirect incoming requests to another URL based on requested URL. For instance, you can redirect http://www.me.com/search to http://www.google.com. You can in fact redirect or forward, and all of this is driven by XML config file.

Init parameters are:


Example configuration in web.xml:

<filter>
  <filter-name>URLRedirectFilter</filter-name>
  <filter-class>javawebparts.filter.URLRedirectFilter</ filter-class>
  <init-param>
    <param-name>configFile</param-name>
    <param-value>/WEB-INF/redirect_config.xml </param-value>
</filter>

<filter-mapping>
  <filter-name>URLRedirectFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

Author:
Frank W. Zammetti.

Field Summary
private  java.util.ArrayList entries
          This is the collection of configured items read from the config file.
private static org.apache.commons.logging.Log log
          Log instance.
 
Constructor Summary
URLRedirectFilter()
           
 
Method Summary
private  void addEntry(java.lang.String type, java.lang.String from, java.lang.String to)
          Add an entry to the entries collection.
 void addForward(java.lang.String from, java.lang.String to)
          Add a forward item from the config file.
 void addRedirect(java.lang.String from, java.lang.String to)
          Add a redirect item from the config file.
 void destroy()
          Destroy.
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain filterChain)
          Do filter's work.
 void init(javax.servlet.FilterConfig filterConfig)
          Initialize this filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Log instance.


entries

private java.util.ArrayList entries
This is the collection of configured items read from the config file.

Constructor Detail

URLRedirectFilter

public URLRedirectFilter()
Method Detail

addEntry

private void addEntry(java.lang.String type,
                      java.lang.String from,
                      java.lang.String to)
Add an entry to the entries collection.

Parameters:
type - This is the type of the entry, either "redirect" or "forward".
from - The URL we want to redirect from.
to - The URL we want to redirect to.

addRedirect

public void addRedirect(java.lang.String from,
                        java.lang.String to)
Add a redirect item from the config file.

Parameters:
from - The URL we want to redirect from.
to - The URL we want to redirect to.

addForward

public void addForward(java.lang.String from,
                       java.lang.String to)
Add a forward item from the config file.

Parameters:
from - The URL we want to redirect from.
to - The URL we want to redirect to.

init

public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
Initialize this filter.

Specified by:
init in interface javax.servlet.Filter
Parameters:
filterConfig - The configuration information for this filter.
Throws:
javax.servlet.ServletException - ServletException.

destroy

public void destroy()
Destroy.

Specified by:
destroy in interface javax.servlet.Filter

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain filterChain)
              throws javax.servlet.ServletException,
                     java.io.IOException
Do filter's work.

Specified by:
doFilter in interface javax.servlet.Filter
Parameters:
request - The current request object.
response - The current response object.
filterChain - The current filter chain.
Throws:
javax.servlet.ServletException - ServletException.
java.io.IOException - IOException.


Copyright 2005 Frank W. Zammetti