Let’s I have two interceptors. Input interceptor at Phase.RECEIVE and output interceptor at Phase.SETUP_ENDING
public class BeforeInterceptor extends AbstractPhaseInterceptor<Message>
{
public BeforeInterceptor()
{
super(Phase.RECEIVE);
}
and
public class AfterInterceptor extends AbstractPhaseInterceptor<Message>
{
public AfterInterceptor()
{
super(Phase.SETUP_ENDING);
}
and now i want know: how many time was between this two phases?
I must call System.currentTimeMillis(); in BeforeInterceptor, tranfser this value to AfterInterceptor, and call
System.currentTimeMillis() - valueFromBeforeInterceptor in after interceptor.
But how can I transfer data from one interceptor ti another?
To pass data between two interceptors that are in the same chain (i.e. two “in” interceptors or two “out” interceptors) you can store arbitrary values on the
MessageIf one interceptor is in the “in” chain and the other is in the “out” chain then you can use the
Exchangefor the same purpose:Whichever one you use, it’s a good idea to pick keys that you are sure won’t clash with any other interceptors, e.g. by using Java package-style hierarchical names.