users@jersey.java.net

Re: Injectable fields not set on target object for proxied resource (using cglib)

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 17 Mar 2008 15:57:17 +0100

Martin Grotzke wrote:
> Hi,
>
>> We may need another method on ComponentProvider e.g. Object
>> getInjectableInstance(Object resource) that Jersey can call and
>> perform injection on the returned instance. Or we have to provide a
>> context as before.
> Yep, s.th. like that would be nice. Would getInjectableInstance be
> invoked for all components, or just those that were created by the
> custom (spring) ComponentProvider?
>

The plan is Jersey would do something like this:

   ComponentProvider cp = ...
   Object o = cp.getInstance(...);
   Object io = cp.getInjectableInstance(o);
   // Inject Jersey specific stuff
   inject(io);

for all components. And the Spring component provider would do something
like this:

   public Object getInjectableInstance(Object o) {
       if (AopUtils.isAopProxy(o)) {
          Advised aopResource = (Advised) o;
          return aopResource.getTargetSource().getTarget();
       } else {
          return o;
       }
   }

i.e. if the Object 'o' is not recognized as cglib proxied then it just
returns what was passed in.

Paul.

> Cheers,
> Martin
>
>
> On Fri, 2008-03-07 at 22:29 +0100, Paul Sandoz wrote:
>> On Mar 7, 2008, at 6:41 PM, Duncan Eley wrote:
>>
>>> Hi Paul,
>>>
>>> I've not looked in any great detail at the new component provider
>>> but I can't see how the AOP trick can be applied using it. The
>>> getInstance() method in the SPI by Marc gave access to a
>>> ResourceProviderContext. This allowed me to inject dependencies on
>>> the proxy's target object and then return the proxied object itself
>>> from getInstance(). The target object cannot be the object returned
>>> from getInstance().
>>>
>>> Using the component provider, how can we do the DI on the target
>>> object? Or there there some other solution to this that I'm not
>>> aware of?
>>>
>>>
>>
>> Ah! you are right, can you please log an issue so that i don't forget
>> about this?
>>
>>
>> We may need another method on ComponentProvider e.g. Object
>> getInjectableInstance(Object resource) that Jersey can call and
>> perform injection on the returned instance. Or we have to provide a
>> context as before.
>>
>>
>> Thanks,
>> Paul.
>>
>>
>>> Many thanks,
>>>
>>> Duncan Eley
>>>
>>>
>>> ----- Original Message ----
>>> From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
>>> To: users_at_jersey.dev.java.net; dunk_e_at_yahoo.co.uk
>>> Sent: Friday, 7 March, 2008 4:55:04 PM
>>> Subject: Re: Injectable fields not set on target object for proxied
>>> resource (using cglib)
>>>
>>> Duncan Eley wrote:
>>>> The above example uses the SPI described here:
>>>> http://weblogs.java.net/blog/mhadley/archive/2007/09/integrating_jer.html.
>>>> This demonstrates how to get at the cglib proxied object using
>>>> Spring. However, I'm aware that the Jersey SPI has changed quite a
>>>> bit since I did this.
>>> Yes, you should be able to do the same AOP trick with the component
>>> provider [1].
>>>
>>>
>>>> It would be really nice, if at some point, Jersey had an optional
>>>> library for users wanting to integrate with Spring.
>>>>
>>> Very much agree. I would like to consider something like that for
>>> 0.7
>>> (see my blog on the 0.6 release), my concern is Marc, Jakub and I
>>> are a
>>> little maxed out so i was wondering if anyone would like to
>>> volunteer to
>>> contribute Spring & Guice stuff to the Jersey distribution ?
>>>
>>> Paul.
>>>
>>> [1] http://blogs.sun.com/sandoz/entry/integrating_jersey_and_spring_take
>>>
>>> --
>>> | ? + ? = To question
>>> ----------------\
>>> Paul Sandoz
>>> x38109
>>> +33-4-76188109
>>>
>>>
>>>
>>>
>>>
>>> ____________________________________________________________________
>>> Sent from Yahoo! Mail.
>>> The World 's Favourite Email.

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109