views:

119

answers:

1

Hi, what is the right method to get http headers from CXF POJO Service?

I have folowing code, but it doesn't work:

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
    }
}

Thanks!

A: 

You would need to add an @Resource onto the wsContext variable and also switch to using the JaxWsServerFactoryBean.

Alternatively, use:

PhaseInterceptorChain.getCurrentMessage()

to get the current CXF internal message and grab the headers off there.

Daniel Kulp