Load-Time Weaving for WebSphere Available
Ramnivas and I are working on an interesting project applying AspectJ to do fine-grained security in a WebSphere 6.0 environment. We wanted to use load-time weaving to let us build modules separately in the RAD IDE and then weave our aspects at load-time. We also wanted to mock the EJB container behavior for integration tests. However, WebSphere 6.0 uses IBM's Java 1.4 VM that doesn't support any Java agents for weaving.
However, I was able to track down the details of the WebSphere ClassLoader Plug In API (the hard part) and write a simple Plug In that lets you do load-time weaving with AspectJ 5 for application classes in WebSphere using its embedded Java 1.4 VM. For older WebSphere implementations, this should also work on their Java 1.3 VM's. You can download the jar and also read about how to use it in more detail at the AspectJ bugzilla report in which I contributed it (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=111027).

I am very interested with this WebSphere plugin.
I am working with WebSphere v5.0 and WebSphere 5.1 and I would like to use load time weaving.
I have followed your steps in order to integrate your plugin into WAS.
I would like to log some events within a servlet.
This is what I have done:
steps 1: I have created an Aspect class in order to catch each doGet method.
steps 2: I have created an aop.xml file and added a system properties named aj5.def (this system property points to the xml.file).
steps 3: I have added my aspect class to the classpath.
I am sure that the WebSphere Plugin is called because I have put some trace in it.
But my aspect is never called, am I doing something wrong ?
Posted by: bertrand AVE | October 24, 2005 at 02:50 AM
Hi Bertrand,
I'd love to see the code for your aspect so I can analyze what might be going wrong. Could you send it to me at rbodkin AT NOSPAMnew aspects.com?
Posted by: Ron Bodkin | October 25, 2005 at 10:35 PM
Ron,
Your ClassLoader Plugin works great on Websphere 5.1.
Now that we've got load-time weaving working in the server, we also need it outside the server for some unit tests. this is with the IBM JDK 1.4. I've tried using the WeavingURLClassLoader that comes with aspectj, but there seems to be a problem with the generated closures in around advice (the parent classloader requests they be loaded from disk regardless of the fact that they are cached). Have you encountered this? Any ideas?
Posted by: Matthew Smith | April 06, 2006 at 08:23 AM
Hi Matthew,
I know that the problem can occur in the JSP ClassLoader. I believe that what is happening is that the WebSphere JasperLoader does not look for predefined classes: it checks to see if there is a source file for any class being defined and if it is out of date it either recompiles or if missing assumes the source was deleted. So I don't think there's any way to define generated closures in that ClassLoader. I don't have a copy of WAS 5.1 to test with but that is my best guess.
Do you see this just with the JSP ClassLoader?
For the Glassbox Inspector we are working around the problem by not using around advice that generates a closure. If you can do so, that's the easiest way.
Otherwise, it might be possible to build a custom extension to AspectJ for WebSphere that would use a different strategy for weaving (defining a generated class and interface in the parent ClassLoader and using this in the child ClassLoader), but it would take a bit of effort.
Posted by: Ron Bodkin | April 10, 2006 at 09:56 AM