users@jersey.java.net

Re: [Jersey] Simplifying Jersey life-cycle and IoC integration

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 25 Nov 2008 09:59:59 +0100

On Nov 24, 2008, at 10:46 PM, Gili wrote:

>
>
> Paul Sandoz wrote:
>>
>> BTW i verified the the case for Spring does as you point out.
>>
>
> In other words, it returns the proxy instead of the real object? Or
> are you
> saying it works just fine?
>

The former. In the following sub-resource locator of a proxied spring
resource:

     @Path("subresource")
     public ProxiedSubResource getSubResource(@Context ResourceContext
rc) {
         ProxiedSubResource psr =
rc.getResource(ProxiedSubResource.class);
         return psr;
     }

a System.out.println(psr.getClass()) will output something like:

        class com.sun.jersey.spring25.ProxiedSubResource$$EnhancerByCGLIB$
$f91d1f34


>
> Paul Sandoz wrote:
>>
>> I see your point. Is this not part of a larger issue in that CGLIB
>> does not preserve annotations? Are we not attempting to work around a
>> bug in CGLIB in this respect?
>>
>
> I don't think it's clear yet that this is something that can or
> should be
> fixed in CGLIB (but yes, we all agree CGLIB is breaking
> compatibility).
>
> 1) http://code.google.com/p/google-guice/issues/detail?id=201
> indicates
> copying annotations would involve a lot of work
>
> 2) I'm wondering if it's *always* safe to copy annotations down to the
> subclass. Isn't it possible that 3rd-party tools might want to act on
> annotations at runtime and they will mistakenly fire the same action
> once on
> the proxy and once on the actual class? In other words, if some
> annotations
> are "actionable" using a Annotation Processor at load-time then we
> have no
> way of knowing which annotations are safe to copy and which are not.
>

Are you referring to the JDK annotation processor? i thought that only
worked on class files and not on class loading.

In any case you are probably right about there being cases where
copying will not work. There is really no way to satisfy all
requirements except by actually re-writing Java class byte code at
runtime, but that may still have side effects w.r.t. Java reflection,
depending on what you do.

Paul.