org.tuckey.web.filters.urlrewrite
Class UrlRewriter

java.lang.Object
  extended by org.tuckey.web.filters.urlrewrite.UrlRewriter

public class UrlRewriter
extends java.lang.Object

The main rewriter.

Version:
$Revision: 52 $ $Date: 2007-02-26 07:00:28 +1300 (Mon, 26 Feb 2007) $
Author:
Paul Tuckey

Constructor Summary
UrlRewriter(Conf conf)
           
 
Method Summary
 java.lang.String decodeRequestString(javax.servlet.http.HttpServletRequest request, java.lang.String source)
          Decode the string with a URLDecoder.
 void destroy()
          Destory the rewriter gracefully.
 Conf getConf()
           
 java.lang.String getContextPath(javax.servlet.http.HttpServletRequest request)
          Return the context path for the given request, detecting an include request URL if called within a RequestDispatcher include.
 java.lang.String getPathWithinApplication(javax.servlet.http.HttpServletRequest request)
          Return the path within the web application for the given request.
 RewrittenUrl handleInvocationTargetException(javax.servlet.http.HttpServletRequest hsRequest, javax.servlet.http.HttpServletResponse hsResponse, java.lang.reflect.InvocationTargetException e)
          Handle an exception thrown by a Run element.
protected  RewrittenOutboundUrl processEncodeURL(javax.servlet.http.HttpServletResponse hsResponse, javax.servlet.http.HttpServletRequest hsRequest, boolean encodeUrlHasBeenRun, java.lang.String outboundUrl)
          Handles rewriting urls in jsp's etc, i.e.
 RewrittenUrl processRequest(javax.servlet.http.HttpServletRequest hsRequest, javax.servlet.http.HttpServletResponse hsResponse)
          Helpful for testing but otherwise, don't use.
 boolean processRequest(javax.servlet.http.HttpServletRequest hsRequest, javax.servlet.http.HttpServletResponse hsResponse, javax.servlet.FilterChain parentChain)
          The main method called for each request that this filter is mapped for.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UrlRewriter

public UrlRewriter(Conf conf)
Method Detail

processRequest

public RewrittenUrl processRequest(javax.servlet.http.HttpServletRequest hsRequest,
                                   javax.servlet.http.HttpServletResponse hsResponse)
                            throws java.io.IOException,
                                   javax.servlet.ServletException,
                                   java.lang.reflect.InvocationTargetException
Helpful for testing but otherwise, don't use.

Throws:
java.io.IOException
javax.servlet.ServletException
java.lang.reflect.InvocationTargetException

processRequest

public boolean processRequest(javax.servlet.http.HttpServletRequest hsRequest,
                              javax.servlet.http.HttpServletResponse hsResponse,
                              javax.servlet.FilterChain parentChain)
                       throws java.io.IOException,
                              javax.servlet.ServletException
The main method called for each request that this filter is mapped for.

Parameters:
hsRequest - The request to process.
Returns:
returns true when response has been handled by url rewriter false when it hasn't.
Throws:
java.io.IOException
javax.servlet.ServletException

getPathWithinApplication

public java.lang.String getPathWithinApplication(javax.servlet.http.HttpServletRequest request)
Return the path within the web application for the given request.

Detects include request URL if called within a RequestDispatcher include.


getContextPath

public java.lang.String getContextPath(javax.servlet.http.HttpServletRequest request)
Return the context path for the given request, detecting an include request URL if called within a RequestDispatcher include.

As the value returned by request.getContextPath() is not decoded by the servlet container, this method will decode it.


decodeRequestString

public java.lang.String decodeRequestString(javax.servlet.http.HttpServletRequest request,
                                            java.lang.String source)
Decode the string with a URLDecoder. The encoding will be taken from the request, falling back to the default for your platform ("ISO-8859-1" on windows).


handleInvocationTargetException

public RewrittenUrl handleInvocationTargetException(javax.servlet.http.HttpServletRequest hsRequest,
                                                    javax.servlet.http.HttpServletResponse hsResponse,
                                                    java.lang.reflect.InvocationTargetException e)
                                             throws javax.servlet.ServletException,
                                                    java.io.IOException
Handle an exception thrown by a Run element.

Throws:
javax.servlet.ServletException
java.io.IOException

getConf

public Conf getConf()

processEncodeURL

protected RewrittenOutboundUrl processEncodeURL(javax.servlet.http.HttpServletResponse hsResponse,
                                                javax.servlet.http.HttpServletRequest hsRequest,
                                                boolean encodeUrlHasBeenRun,
                                                java.lang.String outboundUrl)
Handles rewriting urls in jsp's etc, i.e. response.encodeURL() is overriden in the response wrapper.

Parameters:
hsResponse - response
hsRequest - request
encodeUrlHasBeenRun - if encodeUrl has already been run on the originalOutboundUrl speficy this to be true
outboundUrl - url
Returns:
RewrittenOutboundUrl
See Also:
UrlRewriteWrappedResponse

destroy

public void destroy()
Destory the rewriter gracefully.