在 Spring 中的服务类外部访问 jax-rs (CXF) MessageContext (2.5)
我正在尝试访问某个方面的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 spring 配置中(作为 Message 甚至 Map 类型注入)
然后在接收类中
request = (HttpServletRequest)currentMessage.get("HTTP.REQUEST");
In spring config (injected as Message or even Map type)
then in receiving class
request = (HttpServletRequest)currentMessage.get("HTTP.REQUEST");