users@jersey.java.net

Re: [Jersey] Injection question - Guice + HttpServletRequest

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 07 Oct 2009 10:48:44 +0200

Hi,

Moises is referring to the Guice Provider interface:

   http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/Provider.html

So you should be able to do:

   @Inject
   public MyClass(Provider<HttpServletRequest> request)

See here:

http://code.google.com/docreader/#p=google-guice&s=google-
guice&t=ServletModule

and notice the following in the "Available Injections" section:

   Note that if you want access to any of the request or session
scoped classes from singletons or other wider-
   scoped instances, you should inject a Provider<T> instead.


Unfortunately it is not possible to mix Jersey-based and Guice-based
injection with constructors. This happens to be a particular tricky
area. Furthermore Guice has some limitations that makes it impossible
for Jersey to provide a module that declared bindings for the JAX-RS
annotations to work with @Inject.

You can inject JAX-RS/Jersey stuff on non-_at_Inject fields/setter methods.

Paul.

On Oct 6, 2009, at 10:40 PM, DirkM wrote:

>
>
> Moises Lejter wrote:
>>
>> Would marking it as a Provider work? That would prompt jersey to do
>> injection on the instance, when it creates one...
>>
>
> Thanks for the quick response Moises.
>
> The class is actually a connection class that is used to call
> another web
> service in the depths of the application. So I don't think it makes
> sense
> for it to be a provider. However perhaps it can use a provider
> somehow?
>
> When I was looking at possible solutions I found some posts about
> PerRequestTypeInjectableProvider, which I think may be what I need.
> I must
> admit I got very confused about how all the Annotations and
> ComponentContexts and so on fit together. Can I create an
> implementation of
> this interface somehow that will provide me HttpHeaders at request
> time?
>
> Thanks again,
> Dirk
> --
> View this message in context: http://n2.nabble.com/Injection-question-Guice-HttpServletRequest-tp3777894p3777987.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>