Hi, At the moment, When Spring is used, JAX-RS resources are always singletons, there's a JIRA though to ensure prototypes are supported. So in such cases contexts are thread-safe. That said, JAX_RS runtime does not support
Exchange injections. Gabo - are you sure it's a RESTful invocation ? I'm not sure how you see it being not null. Can you please print the name of Exchange class instance ? Thanks, Sergey -----Original Message----- From: Daniel Kulp [mailto:[email protected]] Sent: 04 June 2009 17:45 To: [email protected] Cc: Gabo Manuel Subject: Re: [CXF-2.2.2][JAXWS] Resource injection problem On Thu June 4 2009 4:46:25 am Gabo Manuel wrote: > Hi All, > > Problem #1 : > > I am implementing a service with both WS and RS annotations. I encounter > the following problem: > > @Resource > private Exchange exchange; > > @GET > @Path("/") > @WebMethod > @WebResult(name="object") > public Object getObject(long id) { > System.out.println("exchange: " + exchange); > } > > If I try to access it via SOAP, the exchange object IS null; but if I > try to access the method via ReST, the exchange object is NOT null. As a > follow-up question, would the exchange object be different for each > transaction, i.e. thread-safe? The main reason is that JAX-RS, by default, creates a new instance per request and thus is injected per request. JAX-WS, on the other hand, creates a single instance and injects everything up front (and no Exchange is live at that point). You CAN configure in a new factory that WOULD create a new instance per request, but even then I'm not sure if the exchange would get injected. I doubt it. Performance would suffer though. And no, access to the Exchange in that instance would not be thread safe, but with a new instance per request, it doesn't matter. > Problem #2 : > How do I access the context from an interceptor? Given the following: > public class SoapInHandler extends AbstractPhaseInterceptor<SoapMessage>{ > private static Logger logger = Logger.getLogger(SoapInHandler.class); > public SoapInHandler() { > // not sure which phase to use. > // super(Phase.UNMARSHAL); > // super(Phase.PRE_INVOKE); > // super(Phase.READ); > super(Phase.POST_PROTOCOL); > } > > @Override > public void handleMessage(SoapMessage message) throws Fault { > // i need to get the UserPrincipal here... > // i need to get the UserPrincipal here... > try { > SoapHeader security = (SoapHeader)message.getHeader(new > QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurit y-s >ecext-1.0.xsd","Security")); //this always returns empty > logger.info("actor: " + security.getActor()); > } catch(Exception e){ > logger.warn("unable to retrieve actor.." + e.getMessage(), e); > } > } > } Hmmm... that should have worked I would think. Maybe the wss4j removes the header if it's processed? Not really sure. That said, if you run after the Wss4jInInterceptor, you can do one of: Principal p = (Prinicpal)message.get(Wss4jInInterceptor.PRINCIPAL_RESULT) or SecurityContext c = message.get(SecurityContext.class); Principal p = c.getUserPrincipal(); Dan > I tried retrieving the wsse:Security header, but I am not able to > retrieve the username token or any of it's child nodes. > > Any suggestions? > > Again, thanks in advance. > > Gabo -- Daniel Kulp [email protected] http://www.dankulp.com/blog
