11 Replies Latest reply on Apr 23, 2008 8:00 PM by Eric H

    Simple interceptor isn't getting activated

    Eric H Novice

      I'm trying to write my first interceptor.  I have the interceptor written but it's not doing anything.


      Here's what I've got:



      import java.util.logging.Logger;
      import javax.interceptor.AroundInvoke;
      import javax.interceptor.InvocationContext;
      
      public class MyInterceptor {
          private static final transient Logger logger =
                  Logger.getLogger("MyInterceptor");
          
          
          @AroundInvoke public Object test(InvocationContext invocation) throws Exception {
              logger.warning(("HELLO MY INTERCEPTOR INVOKED AT: " + new java.util.Date()));
              return invocation.proceed();
          }
      
      }



      So, a very simple interceptor.


      Now my user class:


      @Entity
      @Interceptors(MyInterceptor.class)
      public class User {
         private String name;
         // setters and getters for name
         // and also an ID
      }



      Then I use a Seam component, introduced with a @Name annotation, to persist it, like:


      @Name("userManager") public class UserManager {
         @In private EntityManager entityManager;
      
         public void saveIt() { entityManager.persist(user); }
         
         // etc
      }



      Now, I have a form that uses a h:commandButton to do the saveIt.


      You would think that MyInterceptor would get called somewhere and I would see a log message, but nothing is showing up.


      Any ideas on how to get this simple interceptor to show up?


      Thanks