Correct it was a typo.

I have modified my Interceptor with the following internal class:

private class TimerPreResultListener 
implements PreResultListener {
  private long started;
  private Logger log = LogManager.getLogger(TimerInterceptor.class);
  public TimerPreResultListener() {
    started = System.currentTimeMillis();
  }
  @Override
  public void beforeResult(ActionInvocation invocation, String result) {
    long timeDiff = System.currentTimeMillis() - started;
    ActionContext ac = invocation.getInvocationContext();
    ac.getParameters().put(Constants.REQUEST_TIME_KEY,new Long(timediff));
    ac.getValueStack().setValue(Constants.REQUEST_TIME_KEY,new Long(timediff));
    log.debug("Request Execution Time: " + timeDiff + " milliseconds.");
  }
}

The interceptor's intercept method now looks like this:

@Override
public String intercept(ActionInvocation actionInvocation) 
throws Exception {                              
  actionInvocation.addPreResultListener(new TimerPreResultListener());
  return actionInvocation.invoke();             
}

The problem I face is I still cannot get the value to print in my JSP using the 
s:property tag.  Constants.REQUEST_TIME_KEY = 'seekRequestTimeKey'.

Thoughts?

-----Original Message-----
From: John Orr [mailto:webskate...@googlemail.com] 
Sent: Friday, February 19, 2010 10:46 AM
To: Struts Users Mailing List
Subject: Re: Interceptor

Yes, I think this is exactly the issue raised in my last post. Your
result is being processed before the lines that follow the action
invocation. Insert a PreResultListener and it can do the job of
updating.

(BTW, your method is called interceptor() but it should be Intercept()
- I'm guessing that's probably a typo.)

John


On Fri, Feb 19, 2010 at 10:39 AM, CRANFORD, CHRIS
<chris.cranf...@setech.com> wrote:
>
> My RequestTimerInterceptor is very basic and looks just like this below.  
> What I find is that if I use a <s:debug/> tag in my JSP, the action context 
> parameter is being set to 0 but the update at the end of the interceptor 
> isn't applied.
>
> What have I missed?
>
> public String interceptor(ActionInvocation actionInvocation)
> throws Exception {
>  // Get objects
>  ActionContext ac = actionInvocation.getInvocationContext();
>  Map parameters = ac.getParameters();
>  // Initialize variables
>  parameters.put(Constants.REQUEST_TIME_KEY,new Long(0));
>  ac.getValueStack().setValue(Constants.REQUEST_TIME_KEY,new Long(0));
>  // Get start time
>  Calendar started = Calendar.getInstance();
>  started.setTime(new Date());
>  // Invoke
>  String result = actionInvocation.invoke();
>  // Get end time and difference
>  Calendar ended = Calendar.getInstance();
>  Ended.setTime(new Date());
>  long diffMS = (ended.getTimeInMillis()-started.getTimeInMillis());
>  // Set values with total time
>  parameters.put(Constants.REQUEST_TIME_KEY,new Long(diffMS));
>  ac.getValueStack().setValue(Constants.REQUEST_TIME_KEY,new Long(diffMS));
>  return(result);
> }
>
> Chris
>
> -----Original Message-----
> From: Cimballi [mailto:cimballi.cimba...@gmail.com]
> Sent: Friday, February 19, 2010 10:16 AM
> To: Struts Users Mailing List
> Subject: Re: Interceptor
>
> Look at ParameterRemoverInterceptor for example, you can access the
> action context like this :
> ActionContext ac = invocation.getInvocationContext();
>
> And then you can set values in the value stack. Didn't test it but should 
> work.
>
> Cimballi
>
>
> On Fri, Feb 19, 2010 at 11:10 AM, CRANFORD, CHRIS
> <chris.cranf...@setech.com> wrote:
>> Is it possible to set a value in the request or valuestack from an
>> interceptor that contains the total time it took for the action to be
>> invoked and executed?  I have a requirement to show this on the JSP page
>> and didn't know if I could do this within the Interceptor or if I have
>> to do this in my base action object.
>>
>> Chris
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>> For additional commands, e-mail: user-h...@struts.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to