Hi Marko
On 03/04/12 11:25, Voß, Marko wrote:
Hello,

We have to use @Context to get access to MessageContext and/or any of the other 
supported classes.

We cannot use @Context in the method signatures of the JAX-RS interfaces, 
because of these interfaces should be reused
on the client-side.

So we have to use @Context on class fields, which leads to the problem of 
thread-safety.

Even if I setup the service beans to be prototypes, they are still singletons, 
which is most-likely happening because of
the implementation of:

org.apache.cxf.jaxrs.JAXRSServiceFactoryBean#setResourceClassesFromBeans

Which is not following the rules of the spring beans, I guess.


You'd need to use SpringResourceFactory to get the bean scopes properly enforced, see http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-FromSpring

Also, when debugging this, I noticed that even the MessageContext instance was 
the same instance for multiple threads.
It's a thread-local proxy
So if I change the HttpHeaders in one thread, this will affect the HttpHeaders 
in another thread.

The thread safety is enforced via a thread local proxy, so it should not be the case


How am I supposed to use @Context, reuse the JAX-RS interface on client-side 
and be thread-safe? Any ideas?

Inject contexts in fields and this should be OK for proxies :-). From 2.5.3 it will be possible to use proxies with Contexts in the method signatures too, proxies would need to set 'null'

HTH, Sergey


Best regards,



--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to