Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to ensure AspectJ aspects are LTW'ed by Wildfly's modules?

Yes, it is a bit specific to wildfly but I can talk to what AspectJ does.  I will also call out to an old article I wrote on debugging LTW: http://andrewclement.blogspot.ca/2009/02/load-time-weaving-basics.html (might be useful).

In the source for ClassLoaderWeavingAdaptor you will see three options for files we look for:

META-INF/aop.xml  — the regular one
META-INF/aop-ajc.xml — another option, useful in case you are using -outxml to generate the XML and don’t want to damage some user config you are maintaining (keep user stuff in aop-ajc.xml)
org/aspectj/aop.xml — for OSGi usage but not specific to OSGi, can be used in other scenarios.

Also in the same class you’ll see:

private final static String AOP_XML = Constants.AOP_USER_XML + ";" + Constants.AOP_AJC_XML + ";" + Constants.AOP_OSGI_XML;
String resourcePath = System.getProperty("org.aspectj.weaver.loadtime.configuration", AOP_XML);

So you can override those 3 places and give it the path to something else if you want to by specifying that property. If the thing you provide starts with file then it will actually load direct from there:

if (nextDefinition.startsWith("file:")) {
try {
String fpath = new URL(nextDefinition).getFile();
File configFile = new File(fpath);

If you just run default then it will be making calls to getClassLoader().getResources(name); for those three variants above. So you are at the mercy of whatever the class loader is allowing you to see.

cheers,
Andy

On Oct 21, 2017, at 7:19 PM, Eric B <ebenzacar@xxxxxxxxx> wrote:

So this is probably more of a Wildfly question than an AspectJ question as such, and I have already asked the Wildfly team about it, but I thought I would try to get additional clarity from the AJ pros to understand exactly how the LTW agent works.

My use case is that I want to use use AspectJ to advise some core classes in Wildfly/undertow.  Specifically, I'm trying to advise some of the Undertow HttpSession methods to get some more detailed logging when Sessions are created/expire/etc.

To that extent, I've added AspectJ as a -javaagent which is launched on startup of Wildfly.  I had to follow some of the steps listed at: https://github.com/ChienChingLee/How-to-launch-Wildfly-9.0-with-AspectJ-1.8-LTW.  But it works; I can see that the AJ weaver is loaded and present.

My problem now has to do with the way that the Wildfly classloaders work.  From my understanding, to avoid class conflict issues, the Application Server is designed such that everything is broken down into individual modules, with a separate classloader for each module.  Modules can declare dependencies on other modules if they truly want/need to access classes defined in a different module (see https://docs.jboss.org/author/display/WFLY10/Class+Loading+in+WildFly)

I've tried to configure AJ to have the loader available to all modules, so now my question is how does AJ detect Aspects in the classpath?  Where/how does it search for the aop.xml file?  Does the weaver search every jar that is in the classpath for these files?  How does it determine which files to scan in the classpath?  Does it simply delegate that to the classloader?  (ie: Class.getResourceAsStream("aop.xml"))?  I haven't dug through the AJ code to see exactly what it does.

Right now, I'm a little stuck in that I'm not sure how to ensure that my Aspects are loaded with every module in WF.  I've managed to reconfigure a single module and it works, but the idea of reconfiguring every module individually doesn't make sense.  

I tried to create an independent module in WF for it, and declaring it as a global module but that didn't seem to work.  

I tried to add it to the startup parameters in the WF startup configuration file, specifying it as -classpath path/to/myaspect.jar, but that only advised the startup WF (org.jboss) classes and none of the modules.

Can anyone shed some more light how the LTW works in order to search/find and weave classes?  Or if anyone has any brilliant ideas how I can configure my WF server such that I can drop my asepcts.jar in a "generic" place to make it woven into every module, I would appreciate it.

Thanks!

Eric
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top