You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by "Kok, Arjan" <Ar...@nl.compuware.com> on 2001/01/08 10:22:42 UTC
RE: cvs commit: jakarta-struts/src/share/org/apache/struts/action
ActionServlet.java
Hello Struts-developers,
Could you also reconsider my proposal for a postprocessing hook in this
area? See a previous mail:
"Struts contains a general purpose preprocessing hook in the ActionServlet
that is called before every action. However, there is no postprocessing hook
at the moment. I would like to use the preprocessing and postprocessing hook
to display some tracing information to the developer, for example the amount
of seconds it took to process the action (we make use of a possibly remote
EJB tier)."
Thanks, Arjan Kok.
> -----Original Message-----
> From: craigmcc@apache.org [mailto:craigmcc@apache.org]
> Sent: Saturday, January 06, 2001 11:00 PM
> To: jakarta-struts-cvs@apache.org
> Subject: cvs commit: jakarta-struts/src/share/org/apache/struts/action
> ActionServlet.java
>
>
> craigmcc 01/01/06 14:00:03
>
> Modified: src/share/org/apache/struts/action ActionServlet.java
> Log:
> Refactor the processActionPerform() method to split out the
> process of
> calling the Action class from processing the ActionForward that is
> returned. Now, you can override either or both of these methods, as
> needed, for adding customized post-processing of the Action.
>
> Revision Changes Path
> 1.51 +44 -14
> jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java
>
> Index: ActionServlet.java
> ===================================================================
> RCS file:
> /home/cvs/jakarta-struts/src/share/org/apache/struts/action/Ac
> tionServlet.java,v
> retrieving revision 1.50
> retrieving revision 1.51
> diff -u -r1.50 -r1.51
> --- ActionServlet.java 2001/01/03 19:22:55 1.50
> +++ ActionServlet.java 2001/01/06 22:00:02 1.51
> @@ -1,7 +1,7 @@
> /*
> - * $Header:
> /home/cvs/jakarta-struts/src/share/org/apache/struts/action/Ac
> tionServlet.java,v 1.50 2001/01/03 19:22:55 craigmcc Exp $
> - * $Revision: 1.50 $
> - * $Date: 2001/01/03 19:22:55 $
> + * $Header:
> /home/cvs/jakarta-struts/src/share/org/apache/struts/action/Ac
> tionServlet.java,v 1.51 2001/01/06 22:00:02 craigmcc Exp $
> + * $Revision: 1.51 $
> + * $Date: 2001/01/06 22:00:02 $
> *
> *
> ====================================================================
> *
> @@ -227,7 +227,7 @@
> * </ul>
> *
> * @author Craig R. McClanahan
> - * @version $Revision: 1.50 $ $Date: 2001/01/03 19:22:55 $
> + * @version $Revision: 1.51 $ $Date: 2001/01/06 22:00:02 $
> */
>
> public class ActionServlet
> @@ -1423,8 +1423,13 @@
> return;
> }
>
> - // Call the action instance itself
> - processActionPerform(actionInstance, mapping, formInstance,
> + // Call the Action instance itself
> + ActionForward forward =
> + processActionPerform(actionInstance, mapping,
> formInstance,
> + request, response);
> +
> + // Process the returned ActionForward (if any)
> + processActionForward(forward, mapping, formInstance,
> request, response);
>
> }
> @@ -1552,9 +1557,11 @@
>
>
> /**
> - * Ask the specified Action instance to handle this request.
> + * Forward to the specified destination, by the
> specified mechanism,
> + * if an <code>ActionForward</code> instance was
> returned by the
> + * <code>Action</code>.
> *
> - * @param action The Action to process this request
> + * @param forward The ActionForward returned by our action
> * @param mapping The ActionMapping we are processing
> * @param formInstance The ActionForm we are processing
> * @param request The servlet request we are processing
> @@ -1563,18 +1570,13 @@
> * @exception IOException if an input/output error occurs
> * @exception ServletException if a servlet exception occurs
> */
> - protected void processActionPerform(Action action,
> + protected void processActionForward(ActionForward forward,
> ActionMapping mapping,
> ActionForm formInstance,
> HttpServletRequest request,
>
> HttpServletResponse response)
> throws IOException, ServletException {
>
> - // Perform the requested action
> - ActionForward forward =
> - action.perform(mapping, formInstance, request, response);
> -
> - // Obey any returned ActionForward
> if (forward != null) {
> String path = forward.getPath();
> if (forward.getRedirect()) {
> @@ -1587,6 +1589,34 @@
> rd.forward(request, response);
> }
> }
> +
> + }
> +
> +
> + /**
> + * Ask the specified Action instance to handle this
> request. Return
> + * the <code>ActionForward</code> instance (if any) returned by
> + * the called <code>Action</code>.
> + *
> + * @param action The Action to process this request
> + * @param mapping The ActionMapping we are processing
> + * @param formInstance The ActionForm we are processing
> + * @param request The servlet request we are processing
> + * @param response The servlet response we are creating
> + *
> + * @exception IOException if an input/output error occurs
> + * @exception ServletException if a servlet exception occurs
> + */
> + protected ActionForward processActionPerform(Action action,
> + ActionMapping mapping,
> + ActionForm formInstance,
> + HttpServletRequest request,
> +
> HttpServletResponse response)
> + throws IOException, ServletException {
> +
> + ActionForward forward =
> + action.perform(mapping, formInstance, request, response);
> + return (forward);
>
> }
>
>
>
>
>
Re: cvs commit:
jakarta-struts/src/share/org/apache/struts/actionActionServlet.java
Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
"Kok, Arjan" wrote:
> Hello Struts-developers,
>
> Could you also reconsider my proposal for a postprocessing hook in this
> area? See a previous mail:
>
> "Struts contains a general purpose preprocessing hook in the ActionServlet
> that is called before every action. However, there is no postprocessing hook
> at the moment. I would like to use the preprocessing and postprocessing hook
> to display some tracing information to the developer, for example the amount
> of seconds it took to process the action (we make use of a possibly remote
> EJB tier)."
>
The controller servlet code was recently refactored a little, to make this
easier. For example, if you just wanted to log how long it took to execute the
selected action, you would subclass the controller servlet and do this:
protected ActionForward processActionPerform(Action action,
ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
long startTime = System.currentTimeMillis();
ActionForward forward =
super.processActionPerform(action, mapping, form,
request, response);
long stopTime = System.currentTimeMillis();
... log the difference ...
return (forward);
}
The stuff that actually processes the forward was migrated to a different hook
(processActionForward).
Doesn't this meet your needs? You can pre-process and post-process around the
functionality actually being performed for any of the controller servlet's
"perform" methods in a similar manner.
>
> Thanks, Arjan Kok.
>
Craig McClanahan