org.archive.wayback.util.webapp
Class RequestMapper

java.lang.Object
  extended by org.archive.wayback.util.webapp.RequestMapper

public class RequestMapper
extends Object

This class maintains a mapping of RequestHandlers and ShutDownListeners, to allow (somewhat) efficient mapping and delegation of incoming requests to the appropriate RequestHandler. This class uses PortMapper to delegate some of the responsibility of mapping requests received on a particular port, and also allows configuration of a global PRE RequestHandler, which gets first dibs on EVERY incoming request, as well as a global POST RequestHandler, which may attempt to handle any incoming request not handled by the normal RequestHandler mapping.

Author:
brad

Field Summary
static String GLOBAL_POST_REQUEST_HANDLER
          Bean name used to register the special global POST RequestHandler.
static String GLOBAL_PRE_REQUEST_HANDLER
          Bean name used to register the special global PRE RequestHandler.
 
Constructor Summary
RequestMapper(Collection<RequestHandler> requestHandlers, javax.servlet.ServletContext servletContext)
          Construct a RequestMapper, for the given RequestHandler objects, on the specified ServletContext.
 
Method Summary
 void addGlobalPostRequestHandler(RequestHandler requestHandler)
          Configure the specified RequestHandler to handle ALL incoming requests after all other normal mapping has been attempted
 void addGlobalPreRequestHandler(RequestHandler requestHandler)
          Configure the specified RequestHandler to handle ALL incoming requests before any other normal mapping.
 void addRequestHandler(int port, String host, String path, RequestHandler requestHandler)
          Register the RequestHandler to accept requests on the given port, for the specified host and path.
 void addShutdownListener(ShutdownListener shutdownListener)
          Request the shutdownListener object to be notified of ServletContext shutdown.
static String getRequestContextPath(javax.servlet.http.HttpServletRequest request)
           
static String getRequestContextPathQuery(javax.servlet.http.HttpServletRequest request)
           
static String getRequestPathPrefix(javax.servlet.http.HttpServletRequest request)
          Extract the request path prefix, as computed at RequestHandler mapping, from the HttpServletRequest object.
 boolean handleRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Map the incoming request to the appropriate RequestHandler, including the PRE and POST RequestHandlers, if configured.
 RequestHandlerContext mapRequest(javax.servlet.http.HttpServletRequest request)
           
 void shutdown()
          notify all registered ShutdownListener objects that the ServletContext is being destroyed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GLOBAL_PRE_REQUEST_HANDLER

public static final String GLOBAL_PRE_REQUEST_HANDLER
Bean name used to register the special global PRE RequestHandler.

See Also:
Constant Field Values

GLOBAL_POST_REQUEST_HANDLER

public static final String GLOBAL_POST_REQUEST_HANDLER
Bean name used to register the special global POST RequestHandler.

See Also:
Constant Field Values
Constructor Detail

RequestMapper

public RequestMapper(Collection<RequestHandler> requestHandlers,
                     javax.servlet.ServletContext servletContext)
Construct a RequestMapper, for the given RequestHandler objects, on the specified ServletContext. This method will call setServletContext() on each RequestMapper, followed immediately by registerPortListener()

Parameters:
requestHandlers - Collection of RequestHandlers which handle requests
servletContext - the webapp ServletContext where this RequestMapper is configured.
Method Detail

addShutdownListener

public void addShutdownListener(ShutdownListener shutdownListener)
Request the shutdownListener object to be notified of ServletContext shutdown.

Parameters:
shutdownListener - the object which needs to have shutdown() called when the ServletContext is destroyed.

addGlobalPreRequestHandler

public void addGlobalPreRequestHandler(RequestHandler requestHandler)
Configure the specified RequestHandler to handle ALL incoming requests before any other normal mapping.

Parameters:
requestHandler - the global PRE RequestHandler

addGlobalPostRequestHandler

public void addGlobalPostRequestHandler(RequestHandler requestHandler)
Configure the specified RequestHandler to handle ALL incoming requests after all other normal mapping has been attempted

Parameters:
requestHandler - the global POST RequestHandler

addRequestHandler

public void addRequestHandler(int port,
                              String host,
                              String path,
                              RequestHandler requestHandler)
Register the RequestHandler to accept requests on the given port, for the specified host and path.

Parameters:
port - the integer port on which the RequestHandler gets requests.
host - the String Host which the RequestHandler matches, or null, if the RequestHandler should match ALL hosts.
path - the String path which the RequestHandler matches, or null, if the RequestHandler should match ALL paths.
requestHandler - the RequestHandler to register.

mapRequest

public RequestHandlerContext mapRequest(javax.servlet.http.HttpServletRequest request)

handleRequest

public boolean handleRequest(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response)
                      throws IOException,
                             javax.servlet.ServletException
Map the incoming request to the appropriate RequestHandler, including the PRE and POST RequestHandlers, if configured.

Parameters:
request - the incoming HttpServletRequest
response - the HttpServletResponse to return data to the client
Returns:
true if a response was returned to the client.
Throws:
javax.servlet.ServletException - for usual reasons.
IOException - for usual reasons.

shutdown

public void shutdown()
notify all registered ShutdownListener objects that the ServletContext is being destroyed.


getRequestPathPrefix

public static String getRequestPathPrefix(javax.servlet.http.HttpServletRequest request)
Extract the request path prefix, as computed at RequestHandler mapping, from the HttpServletRequest object.

Parameters:
request - HttpServlet request object being handled
Returns:
the portion of the original request path which indicated the RequestHandler, including the trailing '/'.

getRequestContextPath

public static String getRequestContextPath(javax.servlet.http.HttpServletRequest request)
Parameters:
request - HttpServlet request object being handled
Returns:
the portion of the incoming path within the RequestHandler handling the request, not including a leading "/", and not including query arguments.

getRequestContextPathQuery

public static String getRequestContextPathQuery(javax.servlet.http.HttpServletRequest request)
Parameters:
request - HttpServlet request object being handled
Returns:
the portion of the incoming path within the RequestHandler handling the request, not including a leading "/", including query arguments.


Copyright © 2005-2011 Internet Archive. All Rights Reserved.