com.scooterframework.web.controller
Class BaseRequestProcessor

java.lang.Object
  extended by com.scooterframework.web.controller.BaseRequestProcessor
Direct Known Subclasses:
RestfulRequestProcessor

public class BaseRequestProcessor
extends java.lang.Object

BaseRequestProcessor contains the processing logic that the MainActionServlet performs as it receives each servlet request from the container. You can customize the request processing behavior by subclassing this class and overriding the method(s) whose behavior you are interested in changing.


Field Summary
static java.lang.String DEFAULT_CONTROLLER_CLASS
           
static java.lang.String EXECUTION_INTERRUPTED
           
protected  LogUtil log
           
 
Constructor Summary
BaseRequestProcessor()
          Constructor
 
Method Summary
 void displayHttpRequest(javax.servlet.http.HttpServletRequest request)
          Displays all parameter names and theirs values in a HTTP request.
protected  void doForward(java.lang.String uri, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Do a forward to specified URI using a RequestDispatcher.
protected  void doForwardToCompileErrorPage(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  void doForwardToErrorPage(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  java.lang.String executeControllerAction(java.lang.Object controller, java.lang.reflect.Method method)
          Invokes an action method of a controller.
 java.lang.String executeRequest(ActionProperties aps, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Process an HttpServletRequest.
protected  java.lang.reflect.Method getActionMethod(java.lang.Class<?> controllerClass, java.lang.String actionName)
          Returns a method instance related to an action of a controller.
protected  java.lang.String getControllerClassName(java.lang.String controllerPath)
          Returns a controller class name.
protected  java.lang.Object getControllerInstance(java.lang.String controllerClassName)
          Returns a controller instance.
protected  java.lang.String getDefaultControllerClassName()
          Returns class name of default controller.
protected  java.lang.String getDefaultViewFilesDirectoryName()
          Returns default view file directory name.
protected  java.lang.String getRealPath()
          Returns RealPath
protected  javax.servlet.ServletContext getServletContext()
          Returns ServletContext
protected  java.lang.String getViewURI(java.lang.String controller, java.lang.String action)
          Returns a default view URI.
protected  boolean interpretException(java.lang.Exception ex)
           
protected  boolean isLocalRequest(javax.servlet.http.HttpServletRequest request)
          Checks if a request is local.
protected  boolean isRootAccess(java.lang.String requestPath)
          Checks if a request path is a root access.
 ActionProperties prepareActionProperties(java.lang.String requestPath, java.lang.String requestHttpMethod, javax.servlet.http.HttpServletRequest request)
          Sets up action properties for the action execution.
 void process(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Process an HttpServletRequest and create the corresponding HttpServletResponse or dispatch to another resource.
protected  void processCompileError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Processes a compile error message.
protected  void processError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String error)
          Processes an error message.
protected  void processException(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Exception ex)
          Processes an exception.
protected  void processLocale(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  void processNotNullResult(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ActionProperties aps, java.lang.String result)
          Processes not-null result of an action method.
protected  void processNullResult(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ActionProperties aps)
          Processes null result.
protected  void processResultContentForRequestFormatType(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String content, java.lang.String format)
           
protected  void processResultError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String result)
          Processes error result.
protected  void processResultForward(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String result)
          Processes forward result.
protected  void processResultRedirect(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String result)
          Processes redirect result.
protected  void processRootAccess(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Processes root access.
protected  void registerActionProperties(javax.servlet.http.HttpServletRequest request, ActionProperties aps)
          Puts some action properties in request object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected LogUtil log

DEFAULT_CONTROLLER_CLASS

public static final java.lang.String DEFAULT_CONTROLLER_CLASS
See Also:
Constant Field Values

EXECUTION_INTERRUPTED

public static final java.lang.String EXECUTION_INTERRUPTED
See Also:
Constant Field Values
Constructor Detail

BaseRequestProcessor

public BaseRequestProcessor()
Constructor

Method Detail

process

public void process(javax.servlet.http.HttpServletRequest request,
                    javax.servlet.http.HttpServletResponse response)
             throws java.io.IOException,
                    javax.servlet.ServletException

Process an HttpServletRequest and create the corresponding HttpServletResponse or dispatch to another resource.

Parameters:
request - The servlet request we are processing
response - The servlet response we are creating
Throws:
java.io.IOException
javax.servlet.ServletException

executeRequest

public java.lang.String executeRequest(ActionProperties aps,
                                       javax.servlet.http.HttpServletRequest request,
                                       javax.servlet.http.HttpServletResponse response)
                                throws java.io.IOException,
                                       javax.servlet.ServletException

Process an HttpServletRequest.

Parameters:
aps - properties of request
request - The servlet request we are processing
response - The servlet response we are creating
Returns:
execution result
Throws:
java.io.IOException
javax.servlet.ServletException

prepareActionProperties

public ActionProperties prepareActionProperties(java.lang.String requestPath,
                                                java.lang.String requestHttpMethod,
                                                javax.servlet.http.HttpServletRequest request)
Sets up action properties for the action execution. The properties are wrapped up in an ActionProperties instance.

Parameters:
request - The servlet request we are processing
Returns:
an ActionProperties instance

registerActionProperties

protected void registerActionProperties(javax.servlet.http.HttpServletRequest request,
                                        ActionProperties aps)
Puts some action properties in request object.


isLocalRequest

protected boolean isLocalRequest(javax.servlet.http.HttpServletRequest request)
Checks if a request is local. Subclass can override this method if a different logic is used to determine local request.

Parameters:
request - HttpServletRequest
Returns:
true if the request is from a localhost

processLocale

protected void processLocale(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response)

getControllerClassName

protected java.lang.String getControllerClassName(java.lang.String controllerPath)
Returns a controller class name.

Parameters:
controllerPath - controller path
Returns:
controller class name

getControllerInstance

protected java.lang.Object getControllerInstance(java.lang.String controllerClassName)
Returns a controller instance.

Parameters:
controllerClassName - controller class name
Returns:
controller instance

getDefaultControllerClassName

protected java.lang.String getDefaultControllerClassName()
Returns class name of default controller. This default controller is used when application specific controller is not available and the auto.crud property is set to true in the environment.properties file. Subclass must override this method if a different default controller class is used.


getActionMethod

protected java.lang.reflect.Method getActionMethod(java.lang.Class<?> controllerClass,
                                                   java.lang.String actionName)
Returns a method instance related to an action of a controller.

Parameters:
controllerClass - a controller class type
actionName - name of the action method
Returns:
the method instance

executeControllerAction

protected java.lang.String executeControllerAction(java.lang.Object controller,
                                                   java.lang.reflect.Method method)
Invokes an action method of a controller.

Parameters:
controller - The controller instance to be invoked
method - The action method
Returns:
execution result

processNotNullResult

protected void processNotNullResult(javax.servlet.http.HttpServletRequest request,
                                    javax.servlet.http.HttpServletResponse response,
                                    ActionProperties aps,
                                    java.lang.String result)
                             throws java.io.IOException,
                                    javax.servlet.ServletException

Processes not-null result of an action method. "not-null" result is a result string tagged by one of the supporting tags. All supported tags are documented in ActionResult.

 Examples of not-null results:

 Forward result to a view:
   forwardTo=>/WEB-INF/views/jsp/sayit.jsp

 Display result in html format:
   html=>

Good morning

Return xml formatted document: xml=>Java Programming$50 Return plain-text document: text=>This is a small world.

Parameters:
request - HTTP servlet request
response - HTTP servlet response
aps - properties of request
result - tagged result of an action
Throws:
java.io.IOException
javax.servlet.ServletException

processResultContentForRequestFormatType

protected void processResultContentForRequestFormatType(javax.servlet.http.HttpServletRequest request,
                                                        javax.servlet.http.HttpServletResponse response,
                                                        java.lang.String content,
                                                        java.lang.String format)
                                                 throws java.io.IOException,
                                                        javax.servlet.ServletException
Throws:
java.io.IOException
javax.servlet.ServletException

processResultError

protected void processResultError(javax.servlet.http.HttpServletRequest request,
                                  javax.servlet.http.HttpServletResponse response,
                                  java.lang.String result)
                           throws java.io.IOException,
                                  javax.servlet.ServletException
Processes error result.

Parameters:
request - HTTP servlet request
response - HTTP servlet response
result -
Throws:
java.io.IOException
javax.servlet.ServletException

processResultRedirect

protected void processResultRedirect(javax.servlet.http.HttpServletRequest request,
                                     javax.servlet.http.HttpServletResponse response,
                                     java.lang.String result)
                              throws java.io.IOException,
                                     javax.servlet.ServletException
Processes redirect result.

Parameters:
request - HTTP servlet request
response - HTTP servlet response
result - result of action
Throws:
java.io.IOException
javax.servlet.ServletException

processResultForward

protected void processResultForward(javax.servlet.http.HttpServletRequest request,
                                    javax.servlet.http.HttpServletResponse response,
                                    java.lang.String result)
                             throws java.io.IOException,
                                    javax.servlet.ServletException
Processes forward result. Forwards to a URI denoted by the result.

Parameters:
request - HTTP servlet request
response - HTTP servlet response
result - result of action
Throws:
java.io.IOException
javax.servlet.ServletException

processNullResult

protected void processNullResult(javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response,
                                 ActionProperties aps)
                          throws java.io.IOException,
                                 javax.servlet.ServletException
Processes null result. Forwards to a default URI derived based on controller and action names. See getDefaultViewUri method.

Parameters:
request - HTTP servlet request
response - HTTP servlet response
aps - properties of request
Throws:
java.io.IOException
javax.servlet.ServletException

processRootAccess

protected void processRootAccess(javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response)
                          throws java.io.IOException,
                                 javax.servlet.ServletException
Processes root access. Forwards to a default URI derived based on controller and action names. See getDefaultViewUri method.

Parameters:
request - HTTP servlet request
response - HTTP servlet response
Throws:
java.io.IOException
javax.servlet.ServletException

processError

protected void processError(javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response,
                            java.lang.String error)
                     throws java.io.IOException,
                            javax.servlet.ServletException
Processes an error message.

Parameters:
request - HTTP servlet request
response - HTTP servlet response
error - an error message
Throws:
java.io.IOException
javax.servlet.ServletException

processCompileError

protected void processCompileError(javax.servlet.http.HttpServletRequest request,
                                   javax.servlet.http.HttpServletResponse response)
                            throws java.io.IOException,
                                   javax.servlet.ServletException
Processes a compile error message.

Parameters:
request - HTTP servlet request
response - HTTP servlet response
Throws:
java.io.IOException
javax.servlet.ServletException

processException

protected void processException(javax.servlet.http.HttpServletRequest request,
                                javax.servlet.http.HttpServletResponse response,
                                java.lang.Exception ex)
                         throws java.io.IOException,
                                javax.servlet.ServletException
Processes an exception.

Parameters:
request - HTTP servlet request
response - HTTP servlet response
ex -
Throws:
java.io.IOException
javax.servlet.ServletException

interpretException

protected boolean interpretException(java.lang.Exception ex)

getViewURI

protected java.lang.String getViewURI(java.lang.String controller,
                                      java.lang.String action)
Returns a default view URI. This URI is actually a real view file associated with the controller and the action method name.

Parameters:
controller - the name of the controller
action - the action method
Returns:
view URI.

getDefaultViewFilesDirectoryName

protected java.lang.String getDefaultViewFilesDirectoryName()
Returns default view file directory name.

Returns:
default view file directory name.

doForwardToErrorPage

protected void doForwardToErrorPage(javax.servlet.http.HttpServletRequest request,
                                    javax.servlet.http.HttpServletResponse response)
                             throws java.io.IOException,
                                    javax.servlet.ServletException
Throws:
java.io.IOException
javax.servlet.ServletException

doForwardToCompileErrorPage

protected void doForwardToCompileErrorPage(javax.servlet.http.HttpServletRequest request,
                                           javax.servlet.http.HttpServletResponse response)
                                    throws java.io.IOException,
                                           javax.servlet.ServletException
Throws:
java.io.IOException
javax.servlet.ServletException

doForward

protected void doForward(java.lang.String uri,
                         javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response)
                  throws java.io.IOException,
                         javax.servlet.ServletException

Do a forward to specified URI using a RequestDispatcher. This method is used by all internal method needing to do a forward.

Parameters:
uri - Context-relative URI to forward to
request - HTTP servlet request
response - HTTP servlet response
Throws:
java.io.IOException
javax.servlet.ServletException

displayHttpRequest

public void displayHttpRequest(javax.servlet.http.HttpServletRequest request)
Displays all parameter names and theirs values in a HTTP request.

Parameters:
request -

getServletContext

protected javax.servlet.ServletContext getServletContext()
Returns ServletContext


getRealPath

protected java.lang.String getRealPath()
Returns RealPath


isRootAccess

protected boolean isRootAccess(java.lang.String requestPath)
Checks if a request path is a root access. A root access means the requestPath is either "/" or starts with "/index".

Parameters:
requestPath -
Returns:
true if the request path is root path.