HttpServletRequest在Apache cxf拦截器中变为null

时间:2017-05-26 04:22:54

标签: java rest cxf webservice-client

我需要匹配请求及其相应的响应,因此我尝试使用会话ID来匹配每个请求及其响应。 我在构造函数中使用Phase.PRE_STREAM

我试图在我的拦截器

中使用HttpServletRequest和session id
public void handleMessage(Message msg) {
    HttpServletRequest req = (HttpServletRequest)msg.get("HTTP.REQUEST");
}

但我的价值是空的。有人能告诉我如何在apache cxf中使用HttpServletRequest吗?

我是否需要在创建client时设置会话ID。我按以下方式创建我的客户端

JAXRSClientFactoryBean sf = new JAXRSClientFactoryBean();
sf.setResourceClass(CustomerService.class);
sf.setAddress("http://localhost:9000/");
BindingFactoryManager manager = sf.getBus().getExtension(BindingFactoryManager.class);
JAXRSBindingFactory factory = new JAXRSBindingFactory();
factory.setBus(sf.getBus());
manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, factory);
CustomerService service = sf.create(CustomerService.class);
WebClient wc = sf.createWebClient();

1 个答案:

答案 0 :(得分:0)

像这样实现SOAP Handler:

public class SOAPRequestHandler implements SOAPHandler<SOAPMessageContext>

并实现你的处理程序:

public boolean handleMessage(SOAPMessageContext msgContext)
{
    HttpServletRequest request = (HttpServletRequest) msgContext.get("HTTP.REQUEST");
...
}