Question

I have two manual interceptors:

public class MyServiceLoggingInInterceptor extends LoggingInInterceptor {   

@Override
public void handleMessage(Message message) throws Fault {
    super.handleMessage(message);
}

and

public class InterceptorTest extends AbstractAuthorizingInInterceptor {


@Override
public void handleMessage(Message message) throws Fault {
    System.out.println("Yes! handle message in InterceptorTest");

}}  

Changing the order in adding the interceptors to the chain makes no change in interceptors call and always MyServiceLoggingInInterceptor is called first.

server.getInInterceptors().add(new LoggingInInterceptor());
server.getInInterceptors().add(new MyServiceLoggingInInterceptor());

Is there any hierarchy in CXF interceptors? Or for having a specific order I should do something else+

Thanks!

Was it helpful?

Solution

CXF interceptors have a phase that helps determine where in the process they are inserted.

Check this page to see the order of the inbound and outbound phases.

In your example of the LoggingInInterceptor, take a look and you'll see it has at least two constructors:

public LoggingInInterceptor() {
    super(Phase.RECEIVE);
}

and

public LoggingInInterceptor(String phase) {
    super(phase);
}

You are using the first one, which means you're in the RECEIVE phase. The AbstractAuthorizingInInterceptor is in the PRE_INVOKE phase, which is after, so the Logging interceptors will always be called before.

If you want to change that, you need to change the phases of your interceptors. If two interceptors are in the same phase, then the order they are added in matters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top