struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Hill" <>
Subject RE: Extending RequestProcessor of ActionServlet
Date Mon, 02 Sep 2002 05:20:10 GMT
Hi Bunty,

Most of the time you probably wont actually need to override the
RequestProcessor, however on those occasions when you do need to you will be
glad to hear that it is actually quite a straightforward task.

First you create your own class that extends RequestProcessor, and to make
struts use your subclass you have the following node in your

<controller processorClass="com.mycompany.package.MyProcessor" />

The ActionServlet will call the process() method when a request comes in.
Normally you would not need to override process(), but rather one or more of
the many methods that it calls depending on what behaviour it is that you
are trying to modify.

The best reference you can get to what these methods actually do is the
struts source code itself, so if you haven't downloaded this already I would
strongly recomend that you do so.

When overriding the RequestProcessor, be aware that it is called for all the
requests to your application (not sure about the set up for sub-apps
though).  So be sure that your new behaviour will work for all your actions!

To help you determine what methods you need to override Ive listed in the
order they are called the methods in the RequestProcessor. (You will still
want to look at its source yourself first though to check the exact

-If the request is a POST with content type "multipart/form-data" will
return an org.apache.struts.upload.MultipartRequestWrapper instance which
will wrap the request, otherwise just returns the request back unchanged.
(Multipart forms (used for file uploads) need special parsing to get at the
(POSTed) parameters (parameters added as part of the form action URL on the
other hand are still accessible through the original HttpServletRequest
object) and struts is nice enough to handle this in a semitransparent manner
for you by providing this wrapper class which implements HttpServletRequest.
Unfortunately, the wrapper is only created in this method and not actually
populated until processPopulate() just before the actionForm itself is
populated. This means that for multipart forms the posted request parameters
arent available to any of the RequestProcessor methods that you subclass
that are called before processPopulate.)

-returns the part of the path used later to select an appropriate action to
process the request.

-sets the locale object. (See the source for logic use).

-Sets the default content type in the response based on config.

-Sets the caching stuff in response headers.

-This is an empty hook you can override as needed. It returns a boolean.
Return true to continue processing as normal or false if the response has
now been completed.

-Returns the appropriate ActionMapping from the config for this request.

-For actions protected by roles will chack to see that the user has at least
one of the specified roles. Returns a boolean value (with similar manner to
that returned by processPreProcess).

-Returns the ActionForm instance associated with this mapping. If one doesnt
exist in session or request (as defined in struts-config) will create one as

-Populates the actionForm based on the parameters. (It delagates to
RequestUtils.populate to do this). That is also the place where the
parameters in a MultipartRequestWrapper are populated. (This means that in
the unlikely event you do not have an ActionForm associated with this
request and you are using a multipart form, the parameters in the
MultipartRequestProcessor will NOT be populated! (You are unlikely to find
yourself in this situation though. Im just pointing it out as I did
encounter this issue myself and it took me hours to figure out what was
going wrong!))

-Calls validate() in the actionForm. If there were any errors it returns
false (and the request will be forwarded back to the input), or true if
validation succeeded.

-Processes a forward if the mapping defines one. Also unwraps the
MultipartRequestWrapper (for multipart forms).

-Process an include if defined by mapping. (MultipartRequestWrapper is
unwrapped also)

-Returns the instance of Action that will peform the request.

-Calls execute() method of the action instance. Processes returned
exceptions by calling processException(). Retunrs the ActionForward that is
returned by the actions excute method.

-Forwards or redirects based on the ActionForward returned by the action
when its execute method was called. (If that forward was null, this method
does nothing.)

Hope this is of help to you,

-----Original Message-----
From: Bunty []
Sent: Monday, September 02, 2002 07:07
To: Struts Users Mailing List
Subject: Extending RequestProcessor of ActionServlet

Hi All,

How to extend RequestProcessor class ? Also if someone can elaborate on the
configuration to configure controller.



To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message