我有两个手动拦截器:
public class MyServiceLoggingInInterceptor extends LoggingInInterceptor {
@Override
public void handleMessage(Message message) throws Fault {
super.handleMessage(message);
}
和
public class InterceptorTest extends AbstractAuthorizingInInterceptor {
@Override
public void handleMessage(Message message) throws Fault {
System.out.println("Yes! handle message in InterceptorTest");
}}
更改拦截器添加到链中的顺序不会对拦截器调用进行任何更改,并且始终首先调用MyServiceLoggingInInterceptor。
server.getInInterceptors().add(new LoggingInInterceptor());
server.getInInterceptors().add(new MyServiceLoggingInInterceptor());
CXF拦截器中是否有任何层次结构?或者对于具有特定订单,我应该做其他事情+
谢谢!
答案 0 :(得分:2)
CXF拦截器有一个阶段,可帮助确定插入过程的位置。
检查this页面以查看入站和出站阶段的顺序。
在你的LoggingInInterceptor示例中,看一看,你会发现它至少有两个构造函数:
public LoggingInInterceptor() {
super(Phase.RECEIVE);
}
和
public LoggingInInterceptor(String phase) {
super(phase);
}
您正在使用第一个,这意味着您处于RECEIVE阶段。 AbstractAuthorizingInInterceptor处于PRE_INVOKE阶段,该阶段之后,因此将始终调用Logging拦截器。
如果要更改它,则需要更改拦截器的阶段。如果两个拦截器处于同一阶段,那么它们的顺序就会被添加。