users@hk2.java.net

Re: Method Interception with HK2 and Guice

From: John Wells <john.wells_at_oracle.com>
Date: Wed, 12 Mar 2014 11:40:21 -0400

I'm glad you got it working. Some comments in-line:

On 3/12/2014 11:32 AM, cdr53x_at_free.fr wrote:
> Hi,
>
> I just wanted to let you know that I finally managed to solve this
> issue.
> In order to make it work I had to migrate to jersey 2.6, HK2 2.3.0-b01
> and Guice bridge with the same version
>
> Basically my code :
> - uses Guice for my domain code injection and method interception ,
> even the creation of the HK2 InterceptionService instance
> - uses HK2 to bind an HK2 InterceptionService instance in REST
> ressources
> - uses bi-directional guice/hk2 bridge , the InterceptorService using
> code injected by Guice
>
> Also I found that the InterceptionService binding does not work unless
> jersey is upgraded to 2.6 ( maybe 2.5.1 works, but 2.5 definitely does
> not).
Yes, I think this is true. I think this is because the provider of the
proxies changed here, and so you really have to be on the version of
Jersey that is integrated with a high-enough version of HK2.
> So it seems that AOP cannot be used with Jersey 2.5 and lower version.
> I don't know if this is a jersey or HK2 issue ...
I guess it is just a "we added this feature at this level" kind of thing...
>
> Maybe out of topic, and this is only my point of view but compared to
> Guice, HK2 is really too complex. I ended up by setting up the
> InterceptionService with Guice and then simply registering it's
> instance in HK2. The other way around seemed like a pure nightmare to
> me.
I would definitely like to know why this was so difficult for you. What
API were you trying to use? Why was it so difficult to setup in hk2?
Can you provide more specifics so that we can try to make it better in
the future?
> Anyway I really appreciate the fact that HK2 provides the bridges (
> I'll try the spring bridge in the future) , even if they have their
> issues.
> At least they really work fine if one has to integrate a guice injected
> domain into Jersey REST exposition !
Again, glad to hear that you got it working, but I'm sorry that it was
so difficult. We'd really appreciate feedback on things that were
difficult so that we can fix it.
>
> Thanks for reading