com.bea.web
Class ControllerServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.bea.web.ControllerServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig

public class ControllerServlet
extends HttpServlet

A servlet that delegates user input (in the HTTP request object) from an HTML form to a handler method on a com.bea.web.RequestHandler instance. The com.bea.web.RequestHandler is stored in the session under the key "handler". This class uses reflection to determine which method to invoke on the request handler. This provides a simple MVC architecture where this object serves as the controller component and the request handler serves as the model component. Obviously, the HTML/JSP pages provide the view. Prior to invoking the form handling method on the request handler, this class performs a coarse-grained validation of the input fields.

See Also:
Serialized Form

Constructor Summary
ControllerServlet()
           
 
Method Summary
protected  String debug(HttpServletRequest request)
           
protected  void debugCookies(PrintStream stream, HttpServletRequest request)
           
protected  void debugRequest(PrintStream stream, HttpServletRequest request)
           
protected  void debugRequestHeader(PrintStream stream, HttpServletRequest request)
           
protected  void debugRequestInfo(PrintStream stream, HttpServletRequest request)
           
protected  void debugRequestParameters(PrintStream stream, HttpServletRequest request)
           
protected  void debugSession(PrintStream stream, HttpSession session)
           
protected  void doAction(HttpServletRequest request, HttpServletResponse response)
          Used to invoke a method on the request handler
protected  void doGet(HttpServletRequest request, HttpServletResponse response)
           
protected  void doPost(HttpServletRequest request, HttpServletResponse response)
           
 SecurityException findSecurityException(com.bea.util.AbstractExceptionContainer aec)
          Locates a nested SecurityException; may return null
protected  String getContainedExceptionMessages(com.bea.util.AbstractExceptionContainer aec)
          Appends messages from contained exceptions; don't pass null
protected  String getExceptionInfo(Throwable t)
           
 String getExceptionMessage(Throwable t)
          Gets an exception message that is suitable for a UI; if there is a SecurityException nested any where in the tree, only its message is returned.
protected  RequestHandler getRequestHandler(HttpServletRequest request)
          Retrieves a RequestHandler from the session; if one is not available in the session, a new instance is created.
 void init(ServletConfig config)
           
protected  void loadRequestHandler(HttpServletRequest request)
          Used to load the request handler.
protected  String processRequest(String strDo, HttpServletRequest request, RequestHandler handler, String strUnvalidatedRequestParameters)
          Invokes the strDo method on the handler instance.
protected  boolean validateRequest(String strDo, HttpServletRequest request, RequestHandler handler, StringBuffer sbUnvalidatedRequestParameters)
           
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ControllerServlet

public ControllerServlet()
Method Detail

init

public void init(ServletConfig config)
          throws ServletException
Specified by:
init in interface Servlet
Overrides:
init in class GenericServlet
Throws:
ServletException

doGet

protected void doGet(HttpServletRequest request,
                     HttpServletResponse response)
              throws ServletException,
                     IOException
Overrides:
doGet in class HttpServlet
Throws:
ServletException
IOException

doPost

protected void doPost(HttpServletRequest request,
                      HttpServletResponse response)
               throws ServletException,
                      IOException
Overrides:
doPost in class HttpServlet
Throws:
ServletException
IOException

loadRequestHandler

protected void loadRequestHandler(HttpServletRequest request)
                           throws ServletException
Used to load the request handler. In order to use this method a 'command' parameter must be set on the request object. The command should specify 'loadrequest'.

Throws:
ServletException

doAction

protected void doAction(HttpServletRequest request,
                        HttpServletResponse response)
                 throws ServletException,
                        IOException
Used to invoke a method on the request handler

Throws:
ServletException
IOException

processRequest

protected String processRequest(String strDo,
                                HttpServletRequest request,
                                RequestHandler handler,
                                String strUnvalidatedRequestParameters)
                         throws ServletException
Invokes the strDo method on the handler instance.

Returns:
the next page to display to the user which is determined by the outcome of invoking the action on the request handler.
Throws:
ServletException

getExceptionMessage

public String getExceptionMessage(Throwable t)
Gets an exception message that is suitable for a UI; if there is a SecurityException nested any where in the tree, only its message is returned.


findSecurityException

public SecurityException findSecurityException(com.bea.util.AbstractExceptionContainer aec)
Locates a nested SecurityException; may return null


getContainedExceptionMessages

protected String getContainedExceptionMessages(com.bea.util.AbstractExceptionContainer aec)
Appends messages from contained exceptions; don't pass null


validateRequest

protected boolean validateRequest(String strDo,
                                  HttpServletRequest request,
                                  RequestHandler handler,
                                  StringBuffer sbUnvalidatedRequestParameters)
                           throws UnsupportedEncodingException
Throws:
UnsupportedEncodingException

getRequestHandler

protected RequestHandler getRequestHandler(HttpServletRequest request)
                                    throws ServletException
Retrieves a RequestHandler from the session; if one is not available in the session, a new instance is created. A RequestHandler is responsible for "handling" user input from HTML forms.

Throws:
ServletException

getExceptionInfo

protected final String getExceptionInfo(Throwable t)

debug

protected String debug(HttpServletRequest request)

debugRequest

protected void debugRequest(PrintStream stream,
                            HttpServletRequest request)

debugRequestHeader

protected void debugRequestHeader(PrintStream stream,
                                  HttpServletRequest request)

debugRequestInfo

protected void debugRequestInfo(PrintStream stream,
                                HttpServletRequest request)

debugRequestParameters

protected void debugRequestParameters(PrintStream stream,
                                      HttpServletRequest request)

debugCookies

protected void debugCookies(PrintStream stream,
                            HttpServletRequest request)

debugSession

protected void debugSession(PrintStream stream,
                            HttpSession session)