Hello Sergey,

I see. Thank you again. So do I even need to care about thread-safety on the 
services then or do I have to use the 
SpringResourceFactory here?


Best regards,
Marko

Am 03.04.2012 10:34, schrieb Sergey Beryozkin:
> 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,
>>
>
>


-- 
Marko Voß
ePublishing & eScience
Development & Applied Research
Phone +49 7247 808-744
Fax +49 7247 808-133
[email protected]


FIZ Karlsruhe - Leibniz Institute for Information Infrastructure
Hermann-von-Helmholtz-Platz 1
76344 Eggenstein-Leopoldshafen, Germany

www.fiz-karlsruhe.de


-------------------------------------------------------

Fachinformationszentrum Karlsruhe, Gesellschaft für wissenschaftlich-technische 
Information mbH. 
Sitz der Gesellschaft: Eggenstein-Leopoldshafen, Amtsgericht Mannheim HRB 
101892. 
Geschäftsführerin: Sabine Brünger-Weilandt. 
Vorsitzender des Aufsichtsrats: MinDirig Dr. Thomas Greiner.


Reply via email to