users@jersey.java.net

Re: [Jersey] UriInfo inside MessageBodyWriter?

From: Marc Hadley <marc.hadley_at_oracle.com>
Date: Fri, 16 Apr 2010 16:51:13 -0400

On Apr 16, 2010, at 1:06 PM, Laird Nelson wrote:

> Is there any way to get a UriInfo inside a MessageBodyWriter that
> could be called reliably from writeTo()?
>
Yes, just add a field @Context UriInfo uriInfo;

> I am not clear on whether a UriInfo object, injected into a
> MessageBodyWriter field, is supposed to be injected once or not. Its
> Javadoc leads me to believe that using it in a MessageBodyWriter is a
> no-no.
>
What in the Javadoc leads you to believe that ?

What gets injected is a thread-local proxy which allows the UriInfo to reflect different information for each thread/request being served.

See: https://jsr311.dev.java.net/nonav/releases/1.1/spec/spec3.html#x3-530005.1

Marc.