6 Replies Latest reply on Apr 25, 2007 7:00 AM by Xinhua Gu

    Interceptor Question

    Xinhua Gu Newbie

      Hi all,
      I have a simple Annotation like following:

      @Target(METHOD)
      @Retention(RUNTIME)
      @Interceptors(PrintoutInterceptor.class)
      public @interface Printout {
      }
      


      and the Interceptor class:
      public class PrintoutInterceptor {
      
       @AroundInvoke
       public void printOut(InvocationContext invocation) throws Exception {
       System.out.println("Method "+invocation.getMethod()+" is called");
       invocation.proceed();
       }
      }


      And then i tried to put this annotation on a method,
      ....
      @Printout
      public String register(.....)
      .....
      


      BUT,
      the interceptor doesnot work :(
      can anyone help?
      Thanks !!


        • 1. Re: Interceptor Question
          Jim Hazen Expert

          What Interceptors class are you importing, the Seam or EJB 3? The EJB 3 annotation needs to be run within an EJB 3 context.

          • 2. Re: Interceptor Question
            Xinhua Gu Newbie

            hi, CptnKirk

            the app is running on JBossAS 4.0.5 GA with ejb3 container

            here is my complete codes:

            import javax.interceptor.AroundInvoke;
            import javax.interceptor.InvocationContext;
            
            public class PrintoutInterceptor {
            
             @AroundInvoke
             public void printOut(InvocationContext invocation) throws Exception {
             System.out.println("Method "+invocation.getMethod()+" is called");
             invocation.proceed();
             }
            }
            


            import static java.lang.annotation.ElementType.*;
            import static java.lang.annotation.RetentionPolicy.RUNTIME;
            import java.lang.annotation.*;
            import javax.interceptor.Interceptors;
            
            @Target(METHOD)
            @Retention(RUNTIME)
            @Interceptors(PrintoutInterceptor.class)
            public @interface Printout {
            }
            

            i changed the import like this :
            ....
            import org.jboss.seam.annotations.Interceptors;
            @Target(METHOD)
            @Retention(RUNTIME)
            @Interceptors(PrintoutInterceptor.class)
            public @interface Printout {
            }
            
            


            it still doest work :...(

            • 3. Re: Interceptor Question
              Jim Hazen Expert

              So naturally this

              ....
              @Printout
              public String register(.....)
              .....
              

              method is part of an EJB 3 session bean right?

              • 4. Re: Interceptor Question
                Xinhua Gu Newbie

                 

                "CptnKirk" wrote:
                So naturally this
                ....
                @Printout
                public String register(.....)
                .....
                

                method is part of an EJB 3 session bean right?


                yes. It is a sessionless bean. Actually, when i set up my annotation as ElementType.TYPE and put it on the class definition then it works.

                It does not work if the annotaion is ElementType.METHOD :(

                • 5. Re: Interceptor Question
                  Pete Muir Master

                  IIRC method level seam-interceptors aren't supported in Seam atm (JBSEAM-29) - you'll need to use plain EJB3 interceptors (which do support method level interceptors)

                  • 6. Re: Interceptor Question
                    Xinhua Gu Newbie

                     

                    "petemuir" wrote:
                    IIRC method level seam-interceptors aren't supported in Seam atm (JBSEAM-29) - you'll need to use plain EJB3 interceptors (which do support method level interceptors)


                    Oh, that is pity....
                    standard ejb3 interceptor way @intercpetors(....class) is very urgly. That is why i want to use my own annotation.
                    hm...seems like i must use isAnnotationPresent(Printout.class) to reflect the beans . ....:(