Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] hooking into app server

Hi Jason,

2008/9/26 Jason Weinstein <Jason.Weinstein@xxxxxxx>

> Question#4: I wish you could configure where to dump the classes??

Dump is only really for when reporting bugs as we may need to debug the woven bytecode - do you find you need that bytecode for something?


What i was thinking was this.

Application has internal jars, e.g GlassFish. I need to modify one(or more) of the jars classes. I do not have source code.

I can run aspectj, package up the changed classes i dump, and place in a new jar (or replace) that precedes the original.

Is there a better way to do this?

Use binary weaving for this, not load time weaving.  LTW isn't the right tool here and in fact will only weave the paths you exercise on that 'run' of the application rather than anything you might exercise in the future.  Running a binary weave of AspectJ is easy:

ajc -inpath <jarfileOfClassfiles> MyAspect.java -outjar <wovenjarfileOfNewClasses>

Then use the woven jar file.  If you have a build process and want to integrate it in, use the iajc Ant task to do the binary weave as a final step.

I believe someone implemented a fix to dump so that it goes into a directory based on the loader/weaver id - but I don't use dump very often so cant remember :)  But that's what we'd do to ensure they don't clash.

Andy.
 

I actually think this is an interesting use.

In my case i want to weave code at runtime as i do not have source, and provides some flexibility. However in a way this could be part of build process because i am thinking weaving has some overhead. After the classes are dumped/produced i can package them up and use them directly. Now i have static weaving which i may want in some cases, but no requirement for the sources.
Also how can you use one dump dir, when multiple classloaders can be loading classes simultaneously. Can this cause problems???

Andy Clement wrote:

> Question#1: I wish i knew all of the -D options, and what they did??
> Question#3: I wish i knew all of the weaver options, and what they did??

-Daj.weaving.verbose=true   is an alternative to including '-verbose' in the weaver options section <weaver options="-verbose"> in the aop.xml file.

The options are discussed (badly) here:

http://www.eclipse.org/aspectj/doc/released/devguide/ltw-configuration.html

I usually stick to just specifying things in the aop.xml file and never use -D.

The important ones being -verbose and -showWeaveInfo



> Question#4: I wish you could configure where to dump the classes??

Dump is only really for when reporting bugs as we may need to debug the woven bytecode - do you find you need that bytecode for something?


>  Questions: What does this mean??


> debug weaving 'com.sun.jbi.filebc.
> extensions.FileExtensionRegistry'
> info AspectJ Weaver Version 1.6.1 built on Thursday Jul 3, 2008 at 18:35:41 GMT                       
> info register classloader com.sun.jbi.framework.CustomClassLoader@1af5d23                                 a) this line

This means a new weaver is being attached to a classloader and will weave all code loaded by that loader. The configuration for the weaver instance is shown on the next line:

> info using configuration file:/C:/glassfish/domains/domain1/lib/aspects-filter.jar!/META-INF/aop.xml


> debug weaving 'com.sun.encoder.MetaRef'                                                                                       b) this line

This means the class is going to go through the weaver, it does *NOT* mean that anything is being woven within the class.  It comes out when -debug is on to help you determine if your includes and excludes are set correctly in your aop.xml file.  To see if the type is actually changed based on matching your pointcuts, you should turn on -showWeaveInfo in the aop.xml.  Then you will get messages about the individual weaving, for example:

[AppClassLoader@1f12c4e] debug not weaving 'A'
[AppClassLoader@1f12c4e] debug not weaving 'I'
[AppClassLoader@1f12c4e] debug weaving 'Extender'
[AppClassLoader@1f12c4e] weaveinfo Join point 'method-execution(int Extender.foo())' in Type 'Extender' (A.java:14) advised by before advice from 'X' (X.java:2)
[AppClassLoader@1f12c4e] debug not weaving 'X'

Here i did not include A, I or X. I only included 'Extender'.  And because I had -showWeaveInfo active in aop.xml, it showed by that Extender as modified by the weaver.

> debug cannot weave 'javax.wsdl.factory.WSDLFactory$1'                                                               c) this line

'cannot weave' means it cannot be woven usually due to an internal restriction like: aspectj does not weave itself, or in this case classes in javax.* and java.* packages cannot be woven.  However.  It is possible to force weaving of javax packages if you really need it by adding: -Xset:weaveJavaxPackages=true to your aop.xml weaver options section.


I know, I know, the doc around this is awful, I'm sorry :(  Any help is appreciated to sort it out !

cheers,
Andy.


2008/9/26 Jason Weinstein <Jason.Weinstein@xxxxxxx>
I am fairly new (just a few days) to aspectj but after some initial problems am now doing this, (but perhaps not doing it the best way).

Here are the things i am doing:

Note: for a while i could not get things to work,. It was hard to find out what was going wrong, e.g. no logs.


* In the Glassfish Admin Console (e.g. port 4848)/Application Server/JVM Settings/JVM Options
I added
-javaagent:<path>\aspectjweaver.jar
-Daj.weaving.verbose=true

Question#1: I wish i knew all of the -D options, and what they did??


* I place my aspects-filter.jar right now in glassfish/domains/domain1/lib
I had better success when i narrowed down my aspect's scope.

Question#2: If i place it in the application classpath MY_APP/WEB-INF/lib will the weaving only apply to the classes loaded by the application classloader


* build.xml

        <iajc srcdir="${src.dir}/aop" destdir="${build.dir}/aop"
            debug="true" source="1.6" target="1.6">
            <classpath refid="compile.class.path" />
        </iajc>

Note: I believe this defaults to 1.3 or something. I had better success after changing this

* WEB-INF/aop.xml

<aspectj>
    <aspects>
        <aspect name="aspects.FilterAspect" />
    </aspects>
    <weaver options="-XmessageHandlerClass:aspects.AspectJMessageHandler">
        <!--
            <weaver options="-verbose -showWeaveInfo">
        -->
        <dump within="blah.*"/>
    </weaver>
</aspectj>

Question#3: I wish i knew all of the weaver options, and what they did??

Question#4: I wish you could configure where to dump the classes??

Note: There are not many good examples of this aop.xml file


* IMessageHandler
I had better success after i started using this.

package aspects;

import org.aspectj.bridge.AbortException;
import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.IMessage.Kind;

public class AspectJMessageHandler implements org.aspectj.bridge.IMessageHandler {
    public void dontIgnore(Kind arg0) {
    }

    public boolean handleMessage(IMessage arg0) throws AbortException {
        // note i actually write the message to a log, basically log(new Date() + " " + arg0)
        return true;
    }

    public void ignore(Kind arg0) {
    }

    public boolean isIgnoring(Kind arg0) {
        return false;
    }
}


* Questions: What does this mean??


debug weaving 'com.sun.jbi.filebc.extensions.FileExtensionRegistry'
info AspectJ Weaver Version 1.6.1 built on Thursday Jul 3, 2008 at 18:35:41 GMT                       
info register classloader com.sun.jbi.framework.CustomClassLoader@1af5d23                                 a) this line
info using configuration file:/C:/glassfish/domains/domain1/lib/aspects-filter.jar!/META-INF/aop.xml
info register aspect aspects.FilterAspect
debug weaving 'com.sun.encoder.MetaRef'                                                                                       b) this line
...
debug weaving 'org.apache.xml.resolver.readers.OASISXMLCatalogReader'
debug weaving 'org.apache.xml.resolver.readers.SAXCatalogParser'
debug cannot weave 'javax.wsdl.factory.WSDLFactory'
debug cannot weave 'javax.wsdl.WSDLException'
debug cannot weave 'javax.wsdl.factory.WSDLFactory$1'                                                               c) this line



Andy Clement wrote:
Hi,

I can't answer the question...  but how to integrate ltw with appserver <insert app server name here> comes up on the list now and again.  So I've created an FAQ entry for it.  If anyone reading this can help me flesh it out from the purely general advice it currently includes (which Ramnivas wrote, thanks Ramnivas!), I will put it in there right away.

Current FAQ entry:
http://www.eclipse.org/aspectj/doc/released/faq.php#q:ltwAppServers

Bug entry where anyone wishing to contribute can add instructions/guidelines for an application server:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=248743

Andy.

2008/9/25 <andymorton@xxxxxxxxxxxxxx>
Hi.

I have a several applications deployed in an application server (sun app server / glassfish) and have written several aspects to hook into the current applications (for logging purposes).

I understand this is done via load time weaving.

However, I added the javaagent into the VM options, and it resulted in my applications not starting up right.

I have exported my aspects as a jar, and want them to become active whenever I put them in a specific directory.
Do i put the aop.xml in this jar? Or does it sit somewhere else??

Im quite confused about the whole deployment issue, but believe that my aspects are working ok...
Can anyone point me in the appropriate direction?

Regards,
Andrew

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


 
_______________________________________________ aspectj-users mailing list aspectj-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/aspectj-users

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



_______________________________________________ aspectj-users mailing list aspectj-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/aspectj-users

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top