[jboss-user] [Javassist] - Proxing methods that are called from within the proxy instance itself

Electro Type do-not-reply at jboss.com
Mon May 13 19:59:45 EDT 2013

Electro Type [https://community.jboss.org/people/electrotype] created the discussion

"Proxing methods that are called from within the proxy instance itself"

To view the discussion, visit: https://community.jboss.org/message/817501#817501

Hi, I'm new to Javassist. Thanks a lot to the developers of this project!

I'm pretty sure it's not the first time this question is asked, but I did a search and found nothing.

I'm proxying an abstract class. Something like this (I hope I'm not making any mistakes since this is not the exact code I use) :

ProxyFactory factory = new ProxyFactory();
factory.setFilter(new MethodFilter()
    public boolean isHandled(Method method)
        return true;
MyAbstractClass myInstance = (IDictionary<?>) factory.create(new Class<?>[0], new Object[0], new MyHandler());

MyAbstractClass is :

public abstract class MyAbstractClass
    public String sayHello()
        return "Hello";
    public String sayHelloWord()
        return sayHello() + " World!";

And MyHandler is Something like :

public class MyHandler implements MethodHandler
    public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable
        System.out.println("In invoke()!");
        [ + code to actually call thisMethod on the self object ]

Now, If I call :


The +invoke()+ method will be called first, since I told Javassist to handle all methods. But - and this is my question - when +sayHello()+ is called from say+HelloWord()+, *it is called directly, without going through +invoke()+ first!*

Is there a way to make all methods, even when they are called from within the instance itself, being proxied and going through +invoke()+?

Reply to this message by going to Community

Start a new discussion in Javassist at Community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130513/bf2cc870/attachment.html 

More information about the jboss-user mailing list