users@jsr311.java.net

Re: Injection scope for message body providers

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Tue, 03 Jun 2008 14:14:21 -0400

On Jun 3, 2008, at 1:21 PM, Sergey Beryozkin wrote:
>
> My understanding is that the JAX-RS spec allows for providers such
> as MessageBodyReaders and MessageBodyWriters to have context values
> injected into @Context annotated fields (either directly or possibly
> through setters).
>
Yes.

> I remember reading on this list that providers are expected to have
> a singleton lifecycle. If so then what are the expectations with
> respect to the visibility of such injected fields in multithreaded
> environments ? For ex, HttpHeaders, SecurityContext, etc will likely
> differ across the invocations...
>
See section 5.1 of the spec:

"When injecting an instance of one of the types listed in section 5.2,
the instance supplied MUST be capable of selecting the correct context
for a particular request. Use of a thread-local proxy is a common way
to achieve this."

Marc.

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.