从 Apache CXF POJO 服务获取 HTTP 标头

发布于 2024-09-02 10:04:05 字数 541 浏览 1 评论 0原文

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

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花细雨 2024-09-09 10:04:05

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

或者,使用:

PhaseInterceptorChain.getCurrentMessage()

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文