[jboss-user] [JBoss AOP] - Help with simple Interceptor please

hgo do-not-reply at jboss.com
Thu Jun 14 06:09:43 EDT 2007


hi guys,

i'm trying to setup an interceptor that that intercepts all method calls to classes in a specified package and then does some logging... i just can't get it to work...

No errors are thrown when JBoss starts up but it's not calling my Interceptor at runtime...

please assist, many thanks!


here's what i tried:
jboss version: jboss-4.0.5.GA

my class (i packaged this class into a jar & put the jar in my server/default/lib):
package za.co.rmb.redi.common.aop;
  | 
  | import org.apache.commons.logging.Log;
  | import org.apache.commons.logging.LogFactory;
  | import org.jboss.aop.advice.Interceptor;
  | import org.jboss.aop.joinpoint.Invocation;
  | import org.jboss.aop.joinpoint.MethodInvocation;
  | 
  | public class LogInterceptor implements Interceptor {
  |     private Log log = null;
  | 
  |     public String getName() {
  |         return "LogInterceptor";
  |     }
  | 
  |     public Object invoke(Invocation invocation) throws Throwable {
  |         Object result = null;
  |         if (invocation instanceof MethodInvocation) {
  |             MethodInvocation mi = (MethodInvocation) invocation;
  |             if (log == null) {
  |                 log = LogFactory.getLog(mi.getTargetObject().getClass());
  |             }
  |             String methodName = mi.getMethod().getName();
  |             log.debug("START - " + methodName);
  |             result = invocation.invokeNext();
  |             log.debug("END - " + methodName);
  |         }
  |         return result;
  |     }
  | }

my descriptor (it's name is redi-aop.xml and it's in server/default/deploy):
<?xml version="1.0" encoding="UTF-8"?>
  | <!DOCTYPE aop PUBLIC
  |    "-//JBoss//DTD JBOSS AOP 1.0//EN"
  |    "http://www.jboss.org/aop/dtd/jboss-aop_1_0.dtd">
  | 
  | <aop>
  |     <interceptor name="LogInterceptor"
  |                  class="za.co.rmb.redi.common.aop.LogInterceptor"
  |                  scope="PER_CLASS"/>
  | 
  |     <bind pointcut="execution(* za.co.rmb.*->*(..))">
  |         <interceptor-ref name="LogInterceptor"/>
  |     </bind>
  | </aop>
  | 

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

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



More information about the jboss-user mailing list