Thanks for the reply Ian.

I did see this approach being used by the default interceptors, however I found 
out that the out/outFault messages are always null when the "in" interceptor is 
invoked so the interceptor chains aren't available to add new interceptors to.

I haven't found an example of any interceptors that add interceptors to 
different interceptor chains.

Is there a way of doing what you are saying, perhaps by creating the out 
messages earlier?

Cheers.

-----Original Message-----
From: Ian Roberts [mailto:[EMAIL PROTECTED]
Sent: 21 September 2008 12:50
To: [email protected]
Subject: Re: "Around" interceptor

Quilleash, Michael (IT) wrote:
> I would need to have:
>
> In Interceptor - start timing
> Out/InFault/OutFault interceptors - stop timing
>
> To catch all the possible code paths.  Is there any easier way of
> doing this?

A trick used in a number of CXF built-in interceptors is to have a main 
interceptor which is added to the chain explicitly, but then have that 
interceptor add others to the relevant chains for that exchange during its 
handleMessage.  For example (pseudo-code):

class TimingInterceptor {
  private Interceptor stopTiming = new StopTimingInterceptor();

  handleMessage(Message m) {
    Exchange ex = m.getExchange();
    ex.put("startTime", System.currentTimeMillis());
    ex.getOutMessage().getInterceptorChain().add(stopTiming);
    ex.getOutFaultMessage().getInterceptorChain().add(stopTiming);
  }

  static class StopTimingInterceptor {
    handleMessage(Message m) {
      Exchange ex = m.getExchange();
      long startTime = ex.get("startTime");
      // ...
    }
  }
}

You only need to add the TimingInterceptor to your input chain and it will 
manage the rest for you.

Ian

--
Ian Roberts               | Department of Computer Science
[EMAIL PROTECTED]  | University of Sheffield, UK
--------------------------------------------------------

NOTICE: If received in error, please destroy and notify sender. Sender does not 
intend to waive confidentiality or privilege. Use of this email is prohibited 
when received in error.

Reply via email to