5 Replies Latest reply on Apr 5, 2008 5:02 PM by Pete Muir

    Seam interceptor for POJO

    Markus Dahm Novice


      we are NOT using Session Beans in our project, but POJOs annotated with @Name(). Many of those extend the EntityHome bean. Now we'd like to add a simple interceptor to the call
      chain that logs invocation times:

      import org.jboss.seam.annotations.intercept.AroundInvoke;
      import org.jboss.seam.annotations.intercept.Interceptor;
      import org.jboss.seam.core.BijectionInterceptor;
      import org.jboss.seam.core.ConversationInterceptor;
      import org.jboss.seam.ejb.RemoveInterceptor;
      import org.jboss.seam.intercept.AbstractInterceptor;
      import org.jboss.seam.intercept.InvocationContext;
      @Interceptor(stateless = true, around = { BijectionInterceptor.class,
          ConversationInterceptor.class }, within = RemoveInterceptor.class)
      public class LoggingInterceptor extends AbstractInterceptor {
        private static final long serialVersionUID = 1L;
        public Object aroundInvoke(final InvocationContext invocation)
            throws Exception {
          final String methodName = invocation.getMethod().getName();
          final String className = invocation.getTarget().getClass().getName();
          System.err.println("CALLING: " + className + "::" + methodName);
          final long start = System.currentTimeMillis();
          final Object result = invocation.proceed();
          final long end = System.currentTimeMillis();
          final double time = (end - start) / 1000.0;
          System.err.println("CALL took: " + time);
          return result;

      However it is never being called, unfortunately.
      What's wrong with it? Do I have to register the interceptor somewhere with Seam (I found nothing in the docs)?

      As you can see it's the right annotation (Not the EJB3 one).

      Is there any better way to accomplish some some generic tracing (I guess JBoss interceptors won't work here)?