[jboss-user] [JBoss AOP] - Constructor Advice

David Tucker do-not-reply at jboss.com
Wed Sep 14 09:11:21 EDT 2011


David Tucker [http://community.jboss.org/people/codefox] created the discussion

"Constructor Advice"

To view the discussion, visit: http://community.jboss.org/message/626443#626443

--------------------------------------------------------------
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:


jboss-aop.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"/>
</bind>


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:

jboss-aop.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"/>
</bind>


ConstructorAdvice.java:


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());
        
    @Override
    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.
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/626443#626443]

Start a new discussion in JBoss AOP at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2027]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110914/b36ee093/attachment.html 


More information about the jboss-user mailing list