Accessing jax-rs (CXF) MessageContext outside service class in Spring (2.5)
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
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");
精彩评论