Skip to Content

In some cases, extending the Agentry Product JARs (like the SAPWM-x.x.x.x.jar) in an object oriented way is not an easy task and it can be tiresome if you want to add some generic functionality like adding additional (trace) logging, error handing, monitoring and so forth to “every” StepHandler/BAPI/etc.-class. If you do not want to touch the actual SAPWM-x.x.x.x.jar, you might want to consider using AspectJ load-time weaving. I will not explain the basic concepts of AspectJ here as there are plenty of tutorials and examples in the net. If you are new to aspect-oriented coding, I strongly recommend, you get your feet wet with some standalone Java application first. In the following, I just want to explain, how to set up AspectJ for the Agentry Java Backend of the SMP 3.0.

First, you need some tools and libraries:

  • AspectJ Development Tools for Eclipse
  • From the aspectj-x.x.x.jar:
    • lib/aspectjrt.jar
    • lib/aspectjweaver.jar

Basic configuration of the SMP for AspectJ:

  • Put the aspectjrt.jar into the Agentry Application Java folder (where the Agentry-v5.jar is located)
    • You need to modify the META-INF/MANIFEST.MF in the aspectjrt.jar:
      • Add the following line to make the JAR osgi compatible

                        Export-Package: org.aspectj.lang;org.aspectj.runtime

  • Add ;.\Java\aspectjrt.jar to your Agentry.ini classpath property.
  • Put the aspectjweaver.jar in the SMPs Server folder (not in the Server\lib folder)
  • Add the following lines to the SMPs Server/props.ini file in the jvm section (the -D options can be removed / set to false, once you are confident you have everything set up properly)
    • -javaagent:.\aspectjweaver.jar
    • -Dorg.aspectj.weaver.showWeaveInfo=true
    • -Daj.weaving.verbose=true

Write your AspectJ code (or use the attached code), compile and JAR it (e.g. as aopdemo.jar) and put it into the Agentry Application Java folder (where the Agentry-v5.jar is located). Don’t forget to add your JAR to the Agentry.ini classpath property (e.g. ;./Java/aopdemo.jar).

  • Now, upon SMP startup, you should be able to see some AspectJ initialization logging in the <SERVER>-smp-server.log (assuming you have aj.weaving.verbose set to true). Look for the following lines:

AppClassLoader@142e6767 info AspectJ Weaver Version 1.8.2 built on Thursday Aug 14, 2014 at 21:45:02 GMT

AppClassLoader@142e6767 info register classloader sun.misc.Launcher$AppClassLoader@142e6767

AppClassLoader@142e6767 info using configuration file:/…/aopdemo.jar!/META-INF/aop.xml     

AppClassLoader@142e6767 info register aspect aopdemo.MyAspect


  • As soon as some aspect code is woven in, you should be able so see something like this (you might have to synchronize or perform the proper actions on the Agentry client, depending on your pointcut definitions; for the aopdemo.MyAspect this is not required):

AgentryApplicationClassLoader@7cc49e01 weaveinfo Join point ‘method-execution(java.util.ArrayList com.syclo.sap.bapi.GetUserProfileDataBAPI.processResults())’ in Type ‘com.syclo.sap.bapi.GetUserProfileDataBAPI’ (GetUserProfileDataBAPI.java:68) advised by around advice from ‘aopdemo.MyAspect‘ (MyAspect.aj:42)


  • For the aopdemo.MyAspect, there should be a lot of console output like this:

[AOP] (BAPIFactory.java:34)                    boolean com.syclo.sap.BAPIFactory.validateClass(String, String) returns java.lang.Boolean: true
[AOP] (BAPIFactory.java:34)                    boolean com.syclo.sap.BAPIFactory.validateClass(String, String)
[AOP] (BAPIFactory.java:34)                      arg java.lang.String: WorkorderTransferBAPI
[AOP] (BAPIFactory.java:34)                      arg java.lang.String: com.syclo.sap.component.workorder.bapi.WorkorderTransferBAPI
[AOP] (BAPIFactory.java:82)                      void com.syclo.sap.BAPIFactory.register(String, String)
[AOP] (BAPIFactory.java:82)                        arg java.lang.String: WorkorderTransferBAPI
[AOP] (BAPIFactory.java:82)                        arg java.lang.String: com.syclo.sap.component.workorder.bapi.WorkorderTransferBAPI
[AOP] (BAPIFactory.java:82)                      void com.syclo.sap.BAPIFactory.register(String, String) returns <null>
[AOP] (BAPIFactory.java:34)                    boolean com.syclo.sap.BAPIFactory.validateClass(String, String) returns java.lang.Boolean: true

For the aopdemo.MyAspect, the client sync should be extremely slow due to the amount of logging data. Your next step should be to change the AspectJ code to reduce the number of join points by adjusting the pointcut definition. This should lead to less logging and better performance.

If you have been able to reproduce the above steps for your SMP installation, you have done it. From here on, its up to you, to identify those extensions, that are a pain with the object-oriented approach and can be done nicely by using aspect-orientation.


I would be interested to hear about your ideas on where AspectJ can be beneficial. Feel free to post them here…

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply