public class ComposableRequestProcessor extends RequestProcessor
ComposableRequestProcessor uses the Chain Of Resposibility design pattern (as implemented by the commons-chain package in Jakarta Commons) to support external configuration of command chains to be used. It is configured via the following context initialization parameters:
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_CONTEXT_CLASS
Token for ActionContext clazss so that it can be stored in the
ControllerConfig.
|
protected org.apache.commons.chain.Catalog |
catalog
The
Catalog containing all of the available command chains
for this module. |
protected org.apache.commons.chain.CatalogFactory |
catalogFactory
The
CatalogFactory from which catalog containing the the
base request-processing Command will be retrieved. |
protected org.apache.commons.chain.Command |
command
The
Command to be executed for each request. |
protected static org.apache.commons.logging.Log |
LOG
The
Log instance for this class. |
actions, INCLUDE_PATH_INFO, INCLUDE_SERVLET_PATH, log, moduleConfig, servlet
Constructor and Description |
---|
ComposableRequestProcessor() |
Modifier and Type | Method and Description |
---|---|
protected ActionContext |
contextInstance(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Provide the initialized
ActionContext instance which
will be used by this request. |
protected ActionContext |
createActionContextInstance(javax.servlet.ServletContext servletContext,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Create a new instance of
ActionContext according to
configuration. |
void |
destroy()
Clean up in preparation for a shutdown of this application.
|
void |
init(ActionServlet servlet,
ModuleConfig moduleConfig)
Initialize this request processor instance.
|
protected void |
initCatalogFactory(ActionServlet servlet,
ModuleConfig moduleConfig)
Establish the CatalogFactory which will be used to look up the
catalog which has the request processing command.
|
protected void |
initializeActionContext(ActionContext context)
Set common properties on the given
ActionContext
instance so that commands in the chain can count on their presence. |
void |
process(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Process an
HttpServletRequest and create the
corresponding HttpServletResponse . |
protected javax.servlet.http.HttpServletRequest |
processMultipart(javax.servlet.http.HttpServletRequest request)
If this is a multipart request, wrap it with a special wrapper.
|
void |
setCatalogFactory(org.apache.commons.chain.CatalogFactory catalogFactory)
Set the
CatalogFactory instance which should be used to
find the request-processing command. |
doForward, doInclude, getInternal, getServletContext, internalModuleRelativeForward, internalModuleRelativeInclude, processActionCreate, processActionForm, processActionPerform, processCachedMessages, processContent, processException, processForward, processForwardConfig, processInclude, processLocale, processMapping, processNoCache, processPath, processPopulate, processPreprocess, processRoles, processValidate
public static final String ACTION_CONTEXT_CLASS
Token for ActionContext clazss so that it can be stored in the ControllerConfig.
protected static final org.apache.commons.logging.Log LOG
The Log
instance for this class.
protected org.apache.commons.chain.CatalogFactory catalogFactory
The CatalogFactory
from which catalog containing the the
base request-processing Command
will be retrieved.
protected org.apache.commons.chain.Catalog catalog
The Catalog
containing all of the available command chains
for this module.
protected org.apache.commons.chain.Command command
The Command
to be executed for each request.
public void destroy()
Clean up in preparation for a shutdown of this application.
destroy
in class RequestProcessor
public void init(ActionServlet servlet, ModuleConfig moduleConfig) throws javax.servlet.ServletException
Initialize this request processor instance.
init
in class RequestProcessor
servlet
- The ActionServlet we are associated withmoduleConfig
- The ModuleConfig we are associated with.javax.servlet.ServletException
- If an error occurs during initializationprotected void initCatalogFactory(ActionServlet servlet, ModuleConfig moduleConfig)
Establish the CatalogFactory which will be used to look up the catalog which has the request processing command.
The base implementation simply calls CatalogFactory.getInstance(), unless the catalogFactory property of this object has already been set, in which case it is not changed.
servlet
- The ActionServlet we are processingmoduleConfig
- The ModuleConfig we are processingpublic void process(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
Process an HttpServletRequest
and create the
corresponding HttpServletResponse
.
process
in class RequestProcessor
request
- The servlet request we are processingresponse
- The servlet response we are creatingIOException
- if an input/output error occursjavax.servlet.ServletException
- if a processing exception occursprotected ActionContext contextInstance(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException
Provide the initialized ActionContext
instance which
will be used by this request. Internally, this simply calls
createActionContextInstance
followed by
initializeActionContext
.
request
- The servlet request we are processingresponse
- The servlet response we are creatingjavax.servlet.ServletException
- if a processing exception occursprotected ActionContext createActionContextInstance(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException
Create a new instance of ActionContext
according to
configuration. If no alternative was specified at initialization, a
new instance ServletActionContext
is returned. If an
alternative was specified using the ACTION_CONTEXT_CLASS
property, then that value is treated as a classname, and an instance of
that class is created. If that class implements the same constructor
that ServletActionContext
does, then that constructor will
be used: ServletContext, HttpServletRequest,
HttpServletResponse
; otherwise, it is assumed that the class has
a no-arguments constructor. If these constraints do not suit you,
simply override this method in a subclass.
servletContext
- The servlet context we are processingrequest
- The servlet request we are processingresponse
- The servlet response we are creatingjavax.servlet.ServletException
- if a processing exception occursprotected void initializeActionContext(ActionContext context)
Set common properties on the given ActionContext
instance so that commands in the chain can count on their presence.
Note that while this method does not require that its argument be an
instance of ServletActionContext
, at this time many common
Struts commands will be expecting to receive an ActionContext
which is also a ServletActionContext
.
context
- The ActionContext we are processingprotected javax.servlet.http.HttpServletRequest processMultipart(javax.servlet.http.HttpServletRequest request)
If this is a multipart request, wrap it with a special wrapper. Otherwise, return the request unchanged.
processMultipart
in class RequestProcessor
request
- The HttpServletRequest we are processingpublic void setCatalogFactory(org.apache.commons.chain.CatalogFactory catalogFactory)
Set the CatalogFactory
instance which should be used to
find the request-processing command. In the base implementation, if
this value is not already set, then it will be initialized when initCatalogFactory(org.apache.struts.action.ActionServlet, org.apache.struts.config.ModuleConfig)
is called.
catalogFactory
- Our CatalogFactory instanceCopyright © 2000–2016 Apache Software Foundation. All rights reserved.