users@jersey.java.net

[Jersey] Injection question - Guice + HttpServletRequest

From: DirkM <dirk_at_olx.com>
Date: Tue, 6 Oct 2009 13:24:44 -0700 (PDT)

I'm using Guice as the IoC framework with Jersey.

I am creating a ResourceFilterFactory, which if I'm not mistaken gets
created at application time.

It has a dependency on MyClass, whose constructor takes an
HttpServletRequest object as a parameter:
I want to inject the HttpServletRequest object, however if I do so, Guice
complains that it is request scope only.
@Inject
public MyClass(HttpServletRequest request)


If I understand correctly, Jersey has a nifty mechanism for solving this
problem by using a proxy that throws an IllegalStateException from it's
methods until request time, at which point the object is bound to a real
implementation. This can be injected using @Context:
public MyClass(@Context HttpHeaders headers)


The problem is that @Context doesn't seem to be available outside of
Resource classes:
com.google.inject.CreationException: Guice creation errors:
1) No implementation for javax.ws.rs.core.HttpHeaders was bound.
  while locating javax.ws.rs.core.HttpHeaders

Am I missing something with the way the bindings are set up? Is there a way
I can get to HttpHeaders outside of the Resource class?

Thanks,
Dirk
-- 
View this message in context: http://n2.nabble.com/Injection-question-Guice-HttpServletRequest-tp3777894p3777894.html
Sent from the Jersey mailing list archive at Nabble.com.