从Apache CXF POJO服务获取HTTP标头

cha*_*dex 3 cxf http pojo

从CXF POJO服务获取http标头的正确方法是什么?

我有下面的代码,但它不起作用:

ServerFactoryBean svrFactory = new ServerFactoryBean();
svrFactory.setServiceClass(TestService.class);
svrFactory.setAddress("http://localhost:8080/test");
svrFactory.getServiceFactory().setDataBinding(new AegisDatabinding());
svrFactory.create();

public class TestService {

    protected javax.xml.ws.WebServiceContext wsContext;

    public void someMethod() {
       // the problem is that wsContext.getMessageContext() is null
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

Dan*_*ulp 6

您需要将@Resource添加到wsContext变量,并切换到使用JaxWsServerFactoryBean.

或者,使用:

PhaseInterceptorChain.getCurrentMessage()

获取当前的CXF内部消息并从中获取标头.