[jboss-user] [JBoss AOP] - Prepare statement not picked up, am I missing something?

rubenv do-not-reply at jboss.com
Thu Oct 30 07:39:51 EDT 2008


I'm currently trying to get Dynamic AOP working in JBoss. Apparently, you need to prepare joinpoints. Here's what I'm using as source code:

Main.java:

package test;
  | import org.jboss.aop.AspectManager;
  | import org.jboss.aop.advice.AdviceBinding;
  | import org.jboss.aop.pointcut.ast.ParseException;
  | 
  | public class Main {
  |     public static void main(String[] args) throws ParseException {
  |         Main m = new Main();
  |         m.sayHello();
  | 
  |         AdviceBinding binding = new AdviceBinding("execution(* test.Main->sayHello())", null);
  |         binding.addInterceptor(TracingAspect.class);
  |         AspectManager.instance().addBinding(binding);
  | 
  |         m.sayHello();
  |     }
  | 
  |     private void sayHello() {
  |         System.out.println("Hello!");
  |     }
  | }

TracingAspect.java:

package test;
  | import org.jboss.aop.advice.Interceptor;
  | import org.jboss.aop.joinpoint.*;
  | 
  | public class TracingAspect implements Interceptor {
  |     @Override
  |     public String getName() {
  |         return "Hello tracing!";
  |     }
  | 
  |     @Override
  |     public Object invoke(Invocation invocation) throws Throwable {
  |         System.out.println("Traced hello: " + invocation);
  |         return invocation.invokeNext();
  |     }
  | }

jboss-aop.xml:

<?xml version="1.0" encoding="UTF-8"?>
  | <aop>
  |     <aspect class="test.TracingAspect"/>        
  | 
  |     <prepare expr="execution(* test.Main->sayHello())" />
  | </aop>

I am running this with the following command line parameters:

-javaagent:lib/jboss-aop.jar=-hotSwap -ea -Djboss.aop.path=jboss-aop.xml

Yet still, for some reason, the TracingAspect is never invoked. When I add the following:

<bind pointcut="execution(* test.Main->sayHello())">
  |         <interceptor class="test.TracingAspect" />
  | </bind>

I can see the advice code being run, as expected (once for the first sayHello call, twice for the second one, because the interceptor has been added). This leads me to believe that the prepare isn't being noticed.

Anyone got a clue what I'm doing wrong?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4185684#4185684

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4185684



More information about the jboss-user mailing list