Help needed: Adding Guice support to Jersey 2.0

1,654 views
Skip to first unread message

Gili

unread,
Sep 25, 2013, 10:38:27 AM9/25/13
to google...@googlegroups.com
Hi,

I authored Guice integration for Jersey 1.0 a few years ago but times have changed and I no longer have as much free time as I used to. Jersey 2.0 is out, with Spring support but Guice support is nowhere in sight: https://java.net/jira/browse/JERSEY-1950

I tried applying pressure on the Jersey authors but got no response at all. Is anyone able to help out by picking up this issue and running with it? For everyone else, I would appreciate your vote for this issue.

Thank you,
Gili

Marshall Pierce

unread,
Sep 25, 2013, 9:45:29 PM9/25/13
to google...@googlegroups.com, Gili
I'm definitely interested in Guice support for Jersey 2. I don't have a
lot of free time, but I'm happy to help how I can. The lack of Guice
support is one of the few issues preventing me from adopting Jersey 2.

-Marshall

cowwoc

unread,
Sep 25, 2013, 11:09:16 PM9/25/13
to Marshall Pierce, google...@googlegroups.com
Hi Marshall,


In theory we should be able to leverage javax.inject.Inject to
provide a consistent implementation for all compliant injectors. In
practice, it's not that simple. The devil in the details is GuiceFilter.

The problem is that HK2 requires us to construct a ServletContainer
to get a ServiceLocator, then pass that into the HK2-Guice bridge and
get back an Injector. In the flip side, Guice wants us to construct
GuiceFilter to get an Injector, and use it to inject ServletContainer.
Each framework assumes it comes first. It's not clear how they solved
this problem for Spring, but my guess is they don't have the equivalent
of GuiceFilter.

When I implemented Guice integration for Jersey 1.0, the first
thing I did was examine the Spring implementation. I suggest we begin by
doing the same here. I'll try to take a look over the next two days.
Please try to do the same on your end.

PS: The lack of Guice support is also one of the few issues preventing
me from adopting Jersey 2.

Thanks,
Gili

cowwoc

unread,
Oct 27, 2013, 10:57:23 AM10/27/13
to Marshall Pierce, google...@googlegroups.com
Hi Again,

So it turns out I don't have a working solution for Guice <-> HK2
after all. Have you made any progress on your end?

Gili

Shane Witbeck

unread,
Oct 28, 2013, 1:43:30 PM10/28/13
to google...@googlegroups.com, Marshall Pierce
I've been struggling with this as well using the guice-bridge. Looks like there's been some churning over this topic:

cowwoc

unread,
Oct 28, 2013, 7:29:11 PM10/28/13
to google...@googlegroups.com

    The only way we're going to see this fixed is if Guice users voice their opinion on the Jersey mailing list. Part of the problem is that only 2-3 users have voiced their concerns on the mailing list (in spite of the bug tracker showing almost 20 votes). If the Jersey committers understand that this is a high-priority concern that affects many users they will prioritize accordingly.

    The author of HK2 has been very helpful but I suspect that the problem will need to be fixed in Jersey, not HK2, and I haven't received a single response from the Jersey team.

Gili
--
You received this message because you are subscribed to a topic in the Google Groups "google-guice" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-guice/Qrai0osMCzI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.

jwtodd

unread,
Sep 9, 2014, 2:59:07 AM9/9/14
to google...@googlegroups.com
hey gili, et al -

i'm a long time guice fan and have used a clean jetty/jersey/jackson stack for years.

well, jersey2 is here and i am just now discovering these sticky wicket issues.

on one hand, i am relieved in this thread as it expresses my concerns/hopes perfectly.

on the other hand, i am bummed it is a dated thread yet surfaces quite high in my google searches :|

i also found the hk2-guice bridge i plan to try out : https://hk2.java.net/2.3.0-b03/guice-bridge.html

question: is this the optimal path forward, at this point in time?

again, i am really happy to find this thread and the individuals participating, namely gili.

fully disclosure, one day i hope to try out dagger ... but that is for another day and entirely bonus.

best,

- james

cowwoc

unread,
Sep 9, 2014, 7:55:55 AM9/9/14
to google...@googlegroups.com
Hi James,

There is http://stackoverflow.com/a/25348422/14731 but I have not tried it myself. I originally invested a lot of time in trying to get this to work but ended up with https://bitbucket.org/cowwoc/pouch/ because it was a better fit for me. Pouch is like Dagger-lite, IoC without the automated code generation... Surprisingly, this turned out to be rather trivial to implement and all the debugging/configuring headaches totally went away (I get sane stack-traces now). This also has a nice side-effect of being very efficient at runtime.

Please let me know if you try out the Squarespace project. I am especially interested in knowing whether it is possible to use construction injection of HK2 types into Guice-injected types (e.g. UriInfo into MyService) and vice versa (MyService into Jersey-injected resource constructors).

Good luck,
Gili

jwtodd

unread,
Sep 10, 2014, 4:27:46 PM9/10/14
to google...@googlegroups.com
thx gili!

i'll go w/ squarespace per your recommendation, given i have read a bit about your perspectives on this challenge *and* your prior work in this space.

fallback will be the hk2-guice-bridge [ https://hk2.java.net/guice-bridge/ ]

  q: thoughts re this route?

i'm actually optimistic about the squarespace path, knowing what i know at present.

i'll follow up my findings here.

thx again!


best,

- james

Roger Kapsi

unread,
Sep 10, 2014, 5:13:12 PM9/10/14
to google...@googlegroups.com
Hey Gili,

Constructor injection of HK2 types such as UriInfo* into Guice works. Ditto for the other direction (HK2's Just-In-Time resolver is backed by Guice).

-Roger

* Guice bindings for the following types exist out of the box: ServiceLocator, Application, Providers, UriInfo, HttpHeaders, SecurityContext and Request. 

cowwoc

unread,
Sep 10, 2014, 6:14:23 PM9/10/14
to google...@googlegroups.com
Last I checked (6 months ago) HK2's bridge was almost unusable for construction injection. I wouldn't consider this path.

Gili

cowwoc

unread,
Sep 10, 2014, 6:14:26 PM9/10/14
to google...@googlegroups.com
Hi Roger,

Are you saying this works in the standard HK2 bridge? Or in the Squarespace bridge?

Thanks,
Gili
Reply all
Reply to author
Forward
0 new messages