You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bunty <gp...@gpuri.com> on 2002/09/02 01:07:20 UTC

Extending RequestProcessor of ActionServlet

Hi All,

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

Thanks

Bunty


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Extending RequestProcessor of ActionServlet

Posted by Bunty <gp...@gpuri.com>.
Hi Andrew,

Thanks a lot for being so elaborate.
I have another question. I need to implement single sign on based on
what user ID one logs into their windows workstation. I have written the
code
to get the userID, now I need to put it in ActionServlet/RequestProcessor.
My question is which method is the best to override for this purpose ?

Thanks again

Bunty


----- Original Message -----
From: "Andrew Hill" <an...@gridnode.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Cc: "Daniel D'Cotta" <da...@gridnode.com>
Sent: Monday, September 02, 2002 12:20 AM
Subject: RE: Extending RequestProcessor of ActionServlet


> 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
> struts-config.xml:
>
> <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
> details):
>
>
> processMultipart()
> -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.)
>
>
> processPath()
> -returns the part of the path used later to select an appropriate action
to
> process the request.
>
>
> processLocale()
> -sets the locale object. (See the source for logic use).
>
>
> processContent()
> -Sets the default content type in the response based on config.
>
>
> processNoCache()
> -Sets the caching stuff in response headers.
>
>
> processPreProcess()
> -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.
>
>
> processMapping()
> -Returns the appropriate ActionMapping from the config for this request.
>
>
> processRoles()
> -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).
>
>
> processActionForm()
> -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
> appropriate.
>
>
> processPopulate()
> -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!))
>
>
> processValidate()
> -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.
>
>
> processForward()
> -Processes a forward if the mapping defines one. Also unwraps the
> MultipartRequestWrapper (for multipart forms).
>
>
> processInclude()
> -Process an include if defined by mapping. (MultipartRequestWrapper is
> unwrapped also)
>
>
> processActionCreate()
> -Returns the instance of Action that will peform the request.
>
>
> processActionPerform()
> -Calls execute() method of the action instance. Processes returned
> exceptions by calling processException(). Retunrs the ActionForward that
is
> returned by the actions excute method.
>
>
> processActionForward()
> -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,
> regards
> Andrew
>
>
> -----Original Message-----
> From: Bunty [mailto:gpuri@gpuri.com]
> 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
> struts-config.xml
> configuration to configure controller.
>
> Thanks
>
> Bunty
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Extending RequestProcessor of ActionServlet

Posted by Andrew Hill <an...@gridnode.com>.
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
struts-config.xml:

<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
details):


processMultipart()
-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.)


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


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


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


processNoCache()
-Sets the caching stuff in response headers.


processPreProcess()
-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.


processMapping()
-Returns the appropriate ActionMapping from the config for this request.


processRoles()
-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).


processActionForm()
-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
appropriate.


processPopulate()
-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!))


processValidate()
-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.


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


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


processActionCreate()
-Returns the instance of Action that will peform the request.


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


processActionForward()
-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,
regards
Andrew


-----Original Message-----
From: Bunty [mailto:gpuri@gpuri.com]
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
struts-config.xml
configuration to configure controller.

Thanks

Bunty


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>