AOP 2GA JBoss 5GA set pointcut not working
attel75 Jan 12, 2009 12:25 PMI am trying to set a pointcut to a field when it gets written, no matter what I do, the set pointcut never seems to work. I am using AOP 2.0GA and JBoss 5.0GA. Here is what I have:
aop.xml:
<?xml version="1.0" encoding="UTF-8"?> <aop xmlns="urn:jboss:aop-beans:1.0"> <aspect class="com.acme.aop.FieldAspect"/> <interceptor class="com.acme.aop.FieldSetterInterceptor"/> <bind pointcut="execution(void $instanceof{com.acme.IMarkMe}->*(..))"> <around aspect="com.acme.aop.FieldAspect" name="log"/> </bind> <bind pointcut="execution($instanceof{com.acme.IMarkMe}->new())"> <around aspect="com.acme.aop.FieldAspect" name="log"/> </bind> <bind pointcut="set(private java.lang.String com.acme.aop.POJO->var2)"> <around aspect="com.acme.aop.FieldAspect" name="log"/> </bind> <bind pointcut="set(private java.lang.String com.acme.aop.POJO->var2)"> <interceptor-ref name="com.acme.aop.FieldSetterInterceptor"/> </bind> </aop>
FieldSetterInterceptor:
package com.acme.aop; import org.apache.log4j.Logger; import org.jboss.aop.advice.Interceptor; import org.jboss.aop.joinpoint.FieldWriteInvocation; import org.jboss.aop.joinpoint.Invocation; public class FieldSetterInterceptor implements Interceptor { private static final Logger LOG = Logger.getLogger(FieldSetterInterceptor.class); public FieldSetterInterceptor() { // TODO Auto-generated constructor stub } @Override public String getName() { // TODO Auto-generated method stub return "FieldSetterInterceptor"; } @Override public Object invoke(Invocation invocation) throws Throwable { if (!(invocation instanceof FieldWriteInvocation)) return invocation.invokeNext(); try { FieldWriteInvocation mi = (FieldWriteInvocation)invocation; LOG.info("<<< Entering SetInterceptor for: " + mi.getField().getName()); return invocation.invokeNext(); } finally { LOG.info(">>> Leaving SetInterceptor"); } } }
FieldAspect:
package com.acme.aop; import java.lang.reflect.Field; import org.apache.log4j.Logger; import org.jboss.aop.joinpoint.ConstructorInvocation; import org.jboss.aop.joinpoint.FieldReadInvocation; import org.jboss.aop.joinpoint.FieldWriteInvocation; import org.jboss.aop.joinpoint.Invocation; import org.jboss.aop.joinpoint.MethodInvocation; public class FieldAspect { private static final Logger LOG = Logger.getLogger(FieldAspect.class); public FieldAspect(){ LOG.debug("FieldAspect being instantiated"); } public Object log(ConstructorInvocation invocation) throws Throwable { try { LOG.info("C: Creating using constructor " + invocation.getConstructor()); LOG.info("C: " + invocation.getArguments()); return invocation.invokeNext(); } finally { LOG.info("C: Done"); } } public Object log(MethodInvocation invocation) throws Throwable { try { LOG.info("M: Calling method " + invocation.getMethod().getName()); LOG.info("M: " + invocation.getArguments()); return invocation.invokeNext(); } finally { LOG.info("M: Done"); } } public Object log(FieldWriteInvocation invocation) throws Throwable { LOG.info("F: setting field " + invocation.getField().getName()); LOG.info("F: New value will be " + invocation.getValue()); try { return invocation.invokeNext(); } finally { LOG.info("F: Done"); } } }
POJO:
package com.acme.aop; public class POJO implements com.acme.IMarkMe { private String var1 = "hello"; private String var2; public static int var3; public String getVar1() { return var1; } public String getVar2() { return var2; } public void setVar2(String str) { var2 = str; } }
I am deploying aop.xml to $JBOSS_HOME/server/all/deploy. I can see the poincuts and the aspect and interceptor classes registered in the jmx console, however when I run the code all the pointcuts work except for both the set pointcuts defined in aop.xml.
Am I doing something wrong?
Thanks for all you help.
Andres.