0
我有基于Apache CXF的Web服务。我编写了拦截器来记录一些包含http响应代码的特定内容。如何在CXF拦截器中获取HTTP RESPONSE CODE?
public class MyOutInterceptor extends AbstractPhaseInterceptor<Message> {
public MyOutInterceptor() {
super(Phase.SEND);
}
@Override
public void handleMessage(Message message) throws Fault {
Integer responseCode = (Integer) message.get(Message.RESPONSE_CODE);
//...
}
}
但是!!! responseCode
是null
。即使我改变拦截器阶段,它总是null
。
如何在CXF拦截器中获取http响应代码?
UPD。申请春/ CXF配置:https://gist.github.com/alexiuscrow/b5ceb2df7d652a77cd788454e0792211
UPD。治标不治本
@Override
public void handleMessage(Message message) throws Fault {
Integer responseCode = (Integer) message.get(Message.RESPONSE_CODE);
if (null == responseCode) {
HttpServletResponseWrapper responseWrapper =
(HttpServletResponseWrapper) message.get(AbstractHTTPDestination.HTTP_RESPONSE);
responseCode = responseWrapper.getStatus();
}
//...
}
我检查了。它绑定到'outInterceptors'。 – Alexiuscrow
检查第一个解决方案,它与您已经实现的相同,但我想您已经将拦截器注册到不同的解决方案。 –
拦截器配置有JAX-WS。可能是问题的原因?应用程序Spring/CXF配置:https://gist.github.com/alexiuscrow/b5ceb2df7d652a77cd788454e0792211 – Alexiuscrow