| Method from org.apache.struts.chain.ComposableRequestProcessor Detail: |
protected ActionContext contextInstance(HttpServletRequest request,
HttpServletResponse response) throws ServletException {
ActionContext context =
createActionContextInstance(getServletContext(), request, response);
initializeActionContext(context);
return context;
}
Provide the initialized ActionContext instance which
will be used by this request. Internally, this simply calls
createActionContextInstance followed by
initializeActionContext.
|
protected ActionContext createActionContextInstance(ServletContext servletContext,
HttpServletRequest request,
HttpServletResponse response) throws ServletException {
if (this.actionContextClass == null) {
return new ServletActionContext(servletContext, request, response);
}
try {
if (this.servletActionContextConstructor == null) {
return (ActionContext) this.actionContextClass.newInstance();
}
return (ActionContext) this.servletActionContextConstructor
.newInstance(new Object[] { servletContext, request, response });
} catch (Exception e) {
throw new ServletException(
"Error creating ActionContext instance of type "
+ this.actionContextClass, e);
}
}
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.
|
public void destroy() {
// ---------------------------------------------------------- Public Methods
super.destroy();
catalogFactory = null;
catalog = null;
command = null;
actionContextClass = null;
servletActionContextConstructor = null;
}
|
public void init(ActionServlet servlet,
ModuleConfig moduleConfig) throws ServletException {
LOG.info(
"Initializing composable request processor for module prefix '"
+ moduleConfig.getPrefix() + "'");
super.init(servlet, moduleConfig);
initCatalogFactory(servlet, moduleConfig);
ControllerConfig controllerConfig = moduleConfig.getControllerConfig();
String catalogName = controllerConfig.getCatalog();
catalog = this.catalogFactory.getCatalog(catalogName);
if (catalog == null) {
throw new ServletException("Cannot find catalog '" + catalogName
+ "'");
}
String commandName = controllerConfig.getCommand();
command = catalog.getCommand(commandName);
if (command == null) {
throw new ServletException("Cannot find command '" + commandName
+ "'");
}
this.setActionContextClassName(controllerConfig.getProperty(
ACTION_CONTEXT_CLASS));
}
|
protected void initCatalogFactory(ActionServlet servlet,
ModuleConfig moduleConfig) {
if (this.catalogFactory != null) {
return;
}
this.catalogFactory = CatalogFactory.getInstance();
}
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.
|
protected void initializeActionContext(ActionContext context) {
if (context instanceof ServletActionContext) {
((ServletActionContext) context).setActionServlet(this.servlet);
}
context.setModuleConfig(this.moduleConfig);
}
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.
|
public void process(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
// Wrap the request in the case of a multipart request
request = processMultipart(request);
// Create and populate a Context for this request
ActionContext context = contextInstance(request, response);
// Create and execute the command.
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Using processing chain for this request");
}
command.execute(context);
} catch (Exception e) {
// Execute the exception processing chain??
throw new ServletException(e);
}
// Release the context.
context.release();
}
|
protected HttpServletRequest processMultipart(HttpServletRequest request) {
if (!"POST".equalsIgnoreCase(request.getMethod())) {
return (request);
}
String contentType = request.getContentType();
if ((contentType != null)
&& contentType.startsWith("multipart/form-data")) {
return (new MultipartRequestWrapper(request));
} else {
return (request);
}
}
If this is a multipart request, wrap it with a special wrapper.
Otherwise, return the request unchanged.
|
public void setCatalogFactory(CatalogFactory catalogFactory) {
this.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 is called.
|