在 Spring 中的服务类外部访问 jax-rs (CXF) MessageContext (2.5)

发布于 2024-08-08 15:58:12 字数 678 浏览 5 评论 0原文

我正在尝试访问某个方面的 MessageContext (或 WebServiceContext),以访问 HTTPServletRequest 以进行日志记录。我想像 spring-ws 那样注入上下文,但我还没有找到方法。这是我用于 spring-ws 的内容:

<beans:bean id="transportContext" class="org.springframework.ws.transport.context.TransportContextHolder" factory-method="getTransportContext" scope="request">
 <aop:scoped-proxy/>
 </beans:bean>

我无法在 WebServiceContext 字段/方法上使用 @Resource 注释,因为我不在服务中(无论如何尝试但没有运气)。实例化 WebServiceContext(即 new WebServiceContextImpl())也不起作用,但应该可以,因为这只是包装了一个 threadlocal。我还尝试导入 cxf-extension-jaxws.xml 并使用 id org.apache.cxf.jaxws.context.WebServiceContextImpl 连接 bean,但没有成功(它不为空,但不包含任何内容)有什么想法吗?

谢谢

I'm trying to access the MessageContext (or WebServiceContext) in an aspect to get access to the HTTPServletRequest for logging purposes. I would like to inject the context like I did for spring-ws but I have not found a way to do it. Here is what I used for spring-ws:

<beans:bean id="transportContext" class="org.springframework.ws.transport.context.TransportContextHolder" factory-method="getTransportContext" scope="request">
 <aop:scoped-proxy/>
 </beans:bean>

I can't use the @Resource annotation on WebServiceContext field/method as I am not in the service (tried anyways with no luck). Instantiating the WebServiceContext (ie new WebServiceContextImpl()) doesn't work either, but supposedly should as this just wraps a threadlocal. I've also tried importing cxf-extension-jaxws.xml and wiring the bean with id org.apache.cxf.jaxws.context.WebServiceContextImpl with no luck (it's not null but doesn't hold anything) Any ideas?

thanks

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

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

发布评论

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

评论(1

桃扇骨 2024-08-15 15:58:12

在 spring 配置中(作为 Message 甚至 Map 类型注入)

    <beans:bean id="currentMessage" class="org.apache.cxf.phase.PhaseInterceptorChain" factory-method="getCurrentMessage" scope="request">
<aop:scoped-proxy/>
    </beans:bean> 

然后在接收类中

request = (HttpServletRequest)currentMessage.get("HTTP.REQUEST");

In spring config (injected as Message or even Map type)

    <beans:bean id="currentMessage" class="org.apache.cxf.phase.PhaseInterceptorChain" factory-method="getCurrentMessage" scope="request">
<aop:scoped-proxy/>
    </beans:bean> 

then in receiving class

request = (HttpServletRequest)currentMessage.get("HTTP.REQUEST");

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