Jonas Bonér bio photo

Jonas Bonér

Specialist at Large.
Entrepreneur.
Hacker.
Public Speaker.
Powder Skier.
Obsessive Learner.
Jazz Addict.
Wannabee Musician.

Twitter LinkedIn Github

The idea

After implementing the AW Proxy extension to AspectWerkz I figured, why not hook into the most widely used proxy implementation out there: cglib and let AspectWerkz weave in the aspects that are around just before the proxy is returned to the user.

The solution

So, this is all that this cglib extension does: asks AspectWerkz if it has anything to say about the class that has just been proxied. If so, then let the AspectWerkz weaver do its job, e.g. weave in the aspects that are currently deployed (on the classpath), and when returns the proxy to the user.

If no AspectWerkz aspects are found that has pointcuts that matches the class being proxied then nothing happens.

All that was needed to make this work was to add 30 lines of code to one single cglib class.

How do I use it?

This means that all you need to do to make any cglib based applications, and there are many: Geronimo, dynaop, Spring AOP, Hibernate etc., become “aspectwerkz-aware” is to replace one single class in the cglib.jar jar.

Or.

If you can’t or don’t want to patch the cglib.jar jar, you can just put the class before the jar on the classpath.

What is the impact on my existing code?

If no AspectWerkz aspects are found that has pointcuts that matches the class being proxied then nothing happens.
And if AspectWerkz is not available then the whole process is skipped. So basically, there is nothing to loose, it is pay as you go (or should I rather say: gain as you go ;-) ).

How do I get it?

The single file you need can be found in the AspectWerkz RC2 distribution, which you can find here.

The cglib extension is in the ./src/cglib-ext dir (in the root of the AspectWerkz distribution). So step into this directory and type ant dist and it will compile the class and put it in a jar that is to be found in the ./src/cglib-ext/target. This jar only contains one single class file (which you either put in the cglib.jar jar or make sure that it is before the jar on the classpath).

In the ./src/cglib-ext dir you also have a sample that you can run. This sample is just a sample taken from the cglib distribution, but it has a tracing aspect on the classpath, that is weaved into the proxy. You can run this test by invoking ant samples:trace.

Enjoy.