users@jersey.java.net

Re: [Jersey] _at_Context annotated field in spring bean with prototype scope.

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 30 Jan 2009 16:47:30 +0100

On Jan 30, 2009, at 4:28 PM, Erick Dovale wrote:

> Paul,
> I didn't know that. Now, if that is the case, that providers can
> only be singletons, how can I get the user locale from a
> MessageBodyWriter?


By the same mechanism. Thread local proxies are injected. So when you
make a call to access the HttpHeaders in a writeTo method the proxy
will defer to an instance stored on the current thread.


> Isn't the MessageBodyWriter the one responsible for writing the
> request entity into the response?

>
> Jersey is not throwing any exception. I guess the reason for this is
> that I have a @PerRequest annotation in my provider and the bean
> definition is a prototype which make both scopes match. Obviously
> there is no enforcement of a particular scope for jersey providers;
> at least for MessageBodyWriter instances.
> I am on jersey-1.0
>

Ah, i think that explains things then. If you move to 1.0.1 you should
get an error.

Note that for 1.0.1 there is no need to annotated spring-based beans
with Jersey-based life-cycle annotations as the life-cycle is
determined by Spring. Thus such Jersey-based annotations will be
ignored.

Paul.

> Thanks again for the quick responses.
>
> Cheers.
>
> Erick.
>
> On Fri, Jan 30, 2009 at 10:15 AM, Paul Sandoz <Paul.Sandoz_at_sun.com>
> wrote:
>
> On Jan 30, 2009, at 3:34 PM, Erick Dovale wrote:
>
> Folks,
> I can't get jersey to inject the HttpHeaders instance in a @Provider
> annotated entity provider (MessageBodyWriter) which is a spring
> managed bean with scope prototype.
>
> You cannot use providers in anything other than the singleton scope.
>
> I am surprised Jersey is not throwing an runtime exception in such a
> case which states:
>
> "The scope of the component <c> must be a singleton"
>
> What version of Jersey are you using?
>
> It is possible to share a simple maven project that reproduces your
> problem?
>
> Paul.
>
>
>
> The bean is defined in a spring context and jersey is successfully
> discovering it, however, jersey fails to inject the HttpHeaders
> instance.
> Has anyone had a similar problem before?
>
>
>
> Thanks.
>
> Erick.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>