Getting the underlying object behind a proxy

145 views
Skip to first unread message

Gili

unread,
Nov 24, 2008, 10:49:42 AM11/24/08
to google-guice
Hi,

Is there a Guice API for getting at the underlying instance behind a
proxy? Jersey needs to inspect @Path annotations on the original class
instead of the CGLIB proxy. If I could pass Jersey a copy of the
original class somehow then it will be happy.

Thank you,
Gili

Robbie Vanbrabant

unread,
Nov 24, 2008, 11:07:49 AM11/24/08
to google...@googlegroups.com
This issue tracks your problem: http://code.google.com/p/google-guice/issues/detail?id=201

Robbie

Gili Tzabari

unread,
Nov 24, 2008, 11:48:02 AM11/24/08
to google...@googlegroups.com
Robbie,

I'd like to implement a workaround in the meantime (this is the only
issue preventing me from releasing the jersey-guice integration module).

Does CGLIB build a proxy implementation that redirects method calls to
the unproxied object? Or does the CGLIB proxy contain the actual data
itself?

Thank you,
Gili

tzwoenn

unread,
Nov 25, 2008, 9:18:06 AM11/25/08
to google-guice
A simpler (but as dirty!) solution would look like iterating over the
inherated types looking for the first one, which is no proxy. CGLIB
generated types are created using a naming strategy (as far as I
remember guice uses something like "ByGuice" for generated classes
name), so it might be possible to find proxy classed by checking their
class names against this phrase.

BR, Sven


On Nov 24, 5:48 pm, Gili Tzabari <gili.tzab...@gmail.com> wrote:
> Robbie,
>
>         I'd like to implement a workaround in the meantime (this is the only
> issue preventing me from releasing the jersey-guice integration module).
>
>         Does CGLIB build a proxy implementation that redirects method calls to
> the unproxied object? Or does the CGLIB proxy contain the actual data
> itself?
>
> Thank you,
> Gili
>
> Robbie Vanbrabant wrote:
> > This issue tracks your problem:
> >http://code.google.com/p/google-guice/issues/detail?id=201
>
> > Robbie
>

Gili Tzabari

unread,
Nov 25, 2008, 12:09:33 PM11/25/08
to google...@googlegroups.com

That's essentially what I'm doing, but first I need to understand if
CGLIB proxies work the way I understand or not. That is, do they contain
the data or do they redirect calls to another instance as Hibernate does
(at least, I remember it doing so)?

Gili

Stuart McCulloch

unread,
Nov 25, 2008, 1:19:27 PM11/25/08
to google...@googlegroups.com
2008/11/26 Gili Tzabari <gili.t...@gmail.com>
       That's essentially what I'm doing, but first I need to understand if
CGLIB proxies work the way I understand or not. That is, do they contain
the data or do they redirect calls to another instance as Hibernate does
(at least, I remember it doing so)?

...it depends, you could have a CGLIB proxy that always delegates to
its superclass, which means the data would be contained in the proxy

or you could have a CGLIB proxy that redirects calls to various other
objects, in which case the data could be spread out amongst them

   http://cglib.sourceforge.net/apidocs/net/sf/cglib/proxy/Callback.html

in Guice I guess it would depend what method interceptors you used
 



--
Cheers, Stuart
Reply all
Reply to author
Forward
0 new messages