2 Replies Latest reply on Sep 19, 2011 11:49 PM by Flavia Rainone

    Constructor Advice

    David Tucker Newbie

      I've been writing AOP against actions in my ESB pipeline (as we all now know ) and while writing pointcuts against the process methods works fine, I have a need to have advice around the constructors of the actions so that I can populate some metadata.  The problem is that none of the pointcuts I've written seem to do anything.  I've tried various things since it seemed that the ESB might be instantiating the actions via reflection but that didn't seem to work either.  When I wrote advice against the class ActionProcessingPipeline just to see if it would grab any constructor, I got no output from my constructor advice.  Here is my current code:




      {code:xml}<pointcut expr="execution(public com.amentra.*->new(..))" name="NewInstancePC"/>


      <aspect name="ConstructorAdvice" class="com.amentra.aop.advice.ConstructorAdvice" scope="PER_VM"/>


      <bind pointcut="NewInstancePC"> 

              <before aspect="ConstructorAdvice" name="interceptConstructor"/>



      I've also tried doing this via reflection though and extended the appropriate class in my ConstructorAdvice and that also didn't result in anything.  The reflection I tried this way:




      {code:xml}<pointcut expr="call(* java.lang.reflect.Constructor->newInstance())" name="NewInstancePC"/>

      <pointcut expr="call(* java.lang.Class->newInstance())" name="ClassNewInstancePC"/>


      <aspect name="ConstructorAdvice" class="com.amentra.aop.advice.ConstructorAdvice" scope="PER_VM"/>


      <bind pointcut="NewInstancePC OR ClassNewInstancePC">

              <before aspect="ConstructorAdvice" name="interceptConstructor"/>






      package com.amentra.aop.advice;


      import java.lang.reflect.Constructor;


      import org.apache.log4j.Logger;

      import org.jboss.aop.joinpoint.Invocation;

      import org.jboss.aop.reflection.ReflectionAspect;


      public class ConstructorAdvice extends ReflectionAspect {


          Logger LOG = Logger.getLogger(this.getClass());



          protected Object interceptConstructor(Invocation invocation, Constructor<?> constructor, Object[] args) throws Throwable


              LOG.info("****************CONSTRUCTOR ADVICE****************");


              return super.interceptConstructor(invocation, constructor, args);




      Thanks for any help on getting AOP to recognize my constructors.