2010-05-20 48 views
2

從CXF POJO服務獲取http標頭的正確方法是什麼?從Apache 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 
    } 
} 

謝謝!

回答

5

您需要將@Resource添加到wsContext變量並切換到使用JaxWsServerFactoryBean。

備選地,可使用:

PhaseInterceptorChain.getCurrentMessage()

來得到當前CXF內部消息並抓住頭關閉那裏。