org.benow.web.servlet
Class RequestHandler

java.lang.Object
  extended by org.benow.web.servlet.RequestHandler
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
SecureHandler

public abstract class RequestHandler
extends java.lang.Object
implements java.lang.Runnable

RequestHandler is a ControlledThread which handles a single request. The servlet request comes in and a handler is taken from a pool and invoked to handle the request. If no handler is present, a new handler is created. This (pooled) multi-threaded handler approach is more efficient on smp/hyperthread boxen, and each thread is discrete. More memory is used, however.

Author:
andy

Field Summary
static java.lang.String ENV_PARAMS
           
static java.lang.String ENV_REQUEST
           
static java.lang.String ENV_REQUEST_URL
           
static java.lang.String ENV_RESPONSE
           
static java.lang.String ENV_SESSION
           
protected  QueryParams params
           
protected  javax.servlet.http.HttpServletRequest request
           
protected  javax.servlet.http.HttpServletResponse response
           
protected  javax.servlet.http.HttpSession session
           
protected  java.lang.String url
           
 
Constructor Summary
RequestHandler(HandlerServlet servlet)
           
 
Method Summary
protected  boolean beforeRun(RequestHandlerThread thread)
          Override to add to handler thread environment
protected  void dirtyRun()
          Handles the request, throwing any unhandled errors.
protected  java.lang.Object doRun(java.io.OutputStream out)
           
protected  java.lang.Object doRun(java.io.PrintWriter out)
           
protected  java.lang.Object doRun(java.io.Writer out)
           
protected  void dumpError(java.io.PrintWriter out, int code, java.lang.String message, java.lang.Throwable t)
           
 java.lang.String getContentType()
          Gets the default content type if no type has been previously specified (ie in beforeRun)
protected  void handleError(java.io.OutputStream out, int code, java.lang.String message, java.lang.Throwable t)
           
protected  void handleError(java.io.OutputStream out, java.lang.Throwable t)
           
protected  void handleError(java.io.PrintWriter out, int code, java.lang.String message, java.lang.Throwable t)
           
protected  void handleError(java.io.PrintWriter out, java.lang.Throwable t)
           
 void handleRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String url)
          Handle the delivery of the page.
 void run()
           
protected  void startRun(java.io.OutputStream out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENV_SESSION

public static final java.lang.String ENV_SESSION

ENV_PARAMS

public static final java.lang.String ENV_PARAMS

ENV_RESPONSE

public static final java.lang.String ENV_RESPONSE

ENV_REQUEST

public static final java.lang.String ENV_REQUEST

ENV_REQUEST_URL

public static final java.lang.String ENV_REQUEST_URL

params

protected QueryParams params

url

protected java.lang.String url

request

protected javax.servlet.http.HttpServletRequest request

response

protected javax.servlet.http.HttpServletResponse response

session

protected javax.servlet.http.HttpSession session
Constructor Detail

RequestHandler

public RequestHandler(HandlerServlet servlet)
Method Detail

handleRequest

public void handleRequest(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response,
                          java.lang.String url)
                   throws java.lang.Throwable
Handle the delivery of the page. Displays errors that may have been produced by doHandleRequest and flushes out, if it's been taken with getResponseWriter

Parameters:
url -
Throws:
java.lang.Throwable
java.lang.SecurityException
WebException

beforeRun

protected boolean beforeRun(RequestHandlerThread thread)
                     throws WebException
Override to add to handler thread environment

Parameters:
thread -
Returns:
keep going... true to continue processing, false if all processing has been done in this method (ie binary delivery)
Throws:
WebException

run

public void run()
Specified by:
run in interface java.lang.Runnable

dirtyRun

protected void dirtyRun()
                 throws java.lang.Throwable
Handles the request, throwing any unhandled errors. Errors may be handled in descendants. If not handled, they are handled the the default manner.

Throws:
java.lang.Throwable

getContentType

public java.lang.String getContentType()
Gets the default content type if no type has been previously specified (ie in beforeRun)

Returns:

startRun

protected void startRun(java.io.OutputStream out)
                 throws java.lang.Exception
Throws:
java.lang.Exception

handleError

protected void handleError(java.io.OutputStream out,
                           java.lang.Throwable t)

handleError

protected void handleError(java.io.PrintWriter out,
                           java.lang.Throwable t)
                    throws java.io.IOException,
                           RedirectException
Throws:
java.io.IOException
RedirectException

handleError

protected final void handleError(java.io.OutputStream out,
                                 int code,
                                 java.lang.String message,
                                 java.lang.Throwable t)

handleError

protected final void handleError(java.io.PrintWriter out,
                                 int code,
                                 java.lang.String message,
                                 java.lang.Throwable t)
                          throws java.io.IOException,
                                 RedirectException
Throws:
java.io.IOException
RedirectException

dumpError

protected void dumpError(java.io.PrintWriter out,
                         int code,
                         java.lang.String message,
                         java.lang.Throwable t)
                  throws java.io.IOException,
                         RedirectException
Throws:
java.io.IOException
RedirectException

doRun

protected java.lang.Object doRun(java.io.OutputStream out)
                          throws java.lang.Exception
Throws:
java.lang.Exception

doRun

protected java.lang.Object doRun(java.io.Writer out)
                          throws java.lang.Exception
Throws:
java.lang.Exception

doRun

protected java.lang.Object doRun(java.io.PrintWriter out)
                          throws java.lang.Exception
Throws:
java.lang.Exception