In Struts 1.1-1.2.x RequestProcessor contains the processing logic that the Struts controller servlet 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.

Therefore a new new request processor can be plugged in without touching the Servlet. (Users did not like to subclass ActionServlet.) RequestProcessor also made possible to use a different request processor for each module, if needed.

The problem is that RequestProcessor class was still an all-or-nothing object. Extensions like Tiles and Workflow both needed to subclass the RequestProcessor in different ways for their own reasons.

Experience has shown that requiring people to extend a single RequestProcessor class to customize the processing flow is cumbersome, and is particularly challenging when one wants to integrate custom processing from more than one source, because of Java's single inheritance limitations.

This lead to development of ComposableRequestProcessor, which is shipped with Struts 1.3.x.

todo

There was some discussion about whether Struts should move towards a single interface for Request Processor, behind which multiple services could be integrated, or whether a composable request processor would be more useful.

Since then, the StrutsChain project has been developed and added to the contrib branch of Struts source repository. It implements the composable model, and has gotten considerable interest from other developers. In fact, much developer list discussion indicates that it will eventually replace the existing RequestProcessor. See the StrutsChain page for details.

In the meantime, if you are interested in extending org.apache.struts.action.RequestProcessor, some historical information is retained below:

A simple example of a custom RequestProcessor is:

package com.yourco.action;

public class YourCoRequestProcessor extends RequestProcessor {
    protected void processForwardConfig(HttpServletRequest request, HttpServletResponse response, ForwardConfig forward) throws IOException, ServletException {
        System.out.println("In processForwardConfig() method.");
        super.processForwardConfig(request, response, forward);
    }
}

Which would be defined in StrutsConfigXml thus:

<controller processorClass="com.yourco.action.YourCoRequestProcessor" />

See the struts-config.xml DTD for the complete list of attributes accepted by the controller element.

  • No labels