Cool Aspects

person Bijeshfolder_openAOPlocal_offer, access_time April 17, 2008

For this project I’ve been working on, I had to inject some additional processing into a web service proxy call. Aspects came to the rescue here. Initially I decided that the best way would be to go ahead and use AspectJ to build the aspects that were needed. There is this neat AspectJ plugin that is available for download.

From the limited reading that I did on AspectJ, I realized that I would have to code the join-points into my aspects. This wouldn’t have worked because the goal was to build a transparent, reusable component and my code should not (cannot) reference class names or method names from the application (let’s call it AppX) that will eventually use my component. Another hurdle was that the plugin did not work with JDeveloper 11, although I was allowed to discover and install this through the “Check for updates” feature.

This is where the Spring-AOP integration sprung – unintended word mash-up:) – to the rescue. Spring, if you know it, already has an AOP framework. And get this. Spring 2.0 supports AspectJ aspects as well.  These can be aspects or classes with annotatios or simple classes with corresponding XML configuration. Given the need for transparency, I decided to go with the XML configuration approach. So essentially, I had a regular Java class with a method meant to be the around advice.

public class WSProxyCallInterceptor { 
     * This is the around advice for the web service proxy call
     * @param pjp ProceedingJoinPoint
     * @throws Exception

    public void interceptProxyCall(ProceedingJoinPoint pjp)
                                              throws Exception {
             // pre processing ..
             //post processing ..
    //other methods


The PJP represent the join point that has been interrupted and allows access to the arguments to the call and other information.

All that AppX needs to do now is configure its Spring bean xml to use this class as an aspect. In my case I needed an Around aspect, so it looked something like this:

   <aop:aspect ref="wsProxyCallInterceptor">
     <aop:pointcut id="proxyCall"
        expression="execution(* *..FulfillOrderPortClient.*(..))"/>
     <aop:around pointcut-ref="proxyCall"

Voila!! I could intercept the proxy calls and do whatever that needed to be done. Although, I can claim to have used Aspects I realise that there is a lot more to AOP than meets the eye. The most important decisions with AOP would be of when to use and when not to use. It is important to first understand how Aspects can add value to application development and maintenance.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>