Customising application layers using AspectJ

Create an AspectJ aspect extending abstract aspect provided with InfraRED, as:

import net.sf.infrared.aspects.aj.AbstractApiAspect;
                        
public aspect LayerOneAspect extends AbstractApiAspect {
    // This pointcut matches execution of all public APIs in 
    // com.my.app.layer1 and subpackages 
    public pointcut apiExecution():
        execution( public *  com.my.app.layer1.*...*(..) );
    
    // InfraRED will record executions of all public APIs in 
    // com.my.app.layer1 and subpackages as Layer One.
    public String getLayer() {
        return "Layer One"; 
    }
}
                       

Compile this aspect with ajc tool that ships with AspectJ. You will have to add infrared-agent-all-servlet-2.4.1.BETA.jar to the CLASSPATH. Also remember to use ajc that ships with AspectJ 5 or later.

Create a file META-INF/aop.xml that can be loaded by the Classloader which loads the application. For a WAR web application, this can be put in WEB-INF/classes (so that we have the file WEB-INF/classes/META-INF/aop.xml). For an EAR application in Weblogic, this can be put in APP-INF/classes (so that we have the file APP-INF/classes/META-INF/aop.xml). For an EAR application in JBoss, this has to be put in the META-INF dir in the root of the ear.

The contents of this file should be:

 
 <aspectj>
    <aspects>
        <aspect name="LayerOneAspect"/>          
    </aspects>
</aspectj>  
                          
                        




Layers are typically identified by packages.

More details on how to identify various layers are given in the Configuration page