3 Replies Latest reply on Jan 9, 2008 7:34 PM by Tim Evers

    Seam Interceptors

    Tim Evers Master

      Hey,

      I am trying to make an Interceptor so I can do some injection of Spring beans by type.

      However, for some reason my Interceptor never fires.

      Here is my test code.

      package gekko.web.services;
      
      import org.jboss.seam.annotations.intercept.AroundInvoke;
      import org.jboss.seam.annotations.intercept.Interceptor;
      import org.jboss.seam.intercept.AbstractInterceptor;
      import org.jboss.seam.intercept.InvocationContext;
      import org.jboss.seam.log.LogProvider;
      import org.jboss.seam.log.Logging;
      
      @Interceptor
      public class GekkoSpringInjector extends AbstractInterceptor
      {
      
       private static final LogProvider log = Logging.getLogProvider(GekkoSpringInjector.class);
      
       @AroundInvoke
       public Object aroundInvoke(InvocationContext invocation) throws Exception
       {
       log.debug("********************************************");
       throw new Exception("THIS FIRED");
      // return null;
       }
      
      }
      


      Now, obviously I'm missing something. Somehow I need to register this Interceptor, but where/how do I do this. Cause I don't want to have to add and @Interceptor annotation to EVERY class that will need this interceptor.

      Could someone point me in the right direction. I've tried looking at the doco but nothing seems to make this work.

      I know I've probly got some stupid mistake, but thanks for any help. :)


        • 1. Re: Seam Interceptors
          Pete Muir Master

          There is no way currently in Seam to add to the default interceptor stack I'm afraid (there is an open JIRA issue for this).

          You can use a Seam interceptor to make it into an annotation - see the ref manual

          • 2. Re: Seam Interceptors
            Tim Evers Master

            Ok, I've made a bit of progress, and I have a working interceptor.

            Code as follows:
            The actual interceptor:

            package gekko.web.services;
            
            import org.jboss.seam.annotations.intercept.AroundInvoke;
            import org.jboss.seam.annotations.intercept.Interceptor;
            import org.jboss.seam.intercept.AbstractInterceptor;
            import org.jboss.seam.intercept.InvocationContext;
            import org.jboss.seam.log.LogProvider;
            import org.jboss.seam.log.Logging;
            
            @Interceptor
            public class GekkoSpringInjector extends AbstractInterceptor {
            
             private static final LogProvider log = Logging
             .getLogProvider(GekkoSpringInjector.class);
            
             @AroundInvoke
             public Object aroundInvoke(InvocationContext invocation) throws Exception {
             log.debug("********************************************");
             Object result = invocation.proceed();
             return result;
             }
            
            }
            


            The annotation
            package gekko.web.services;
            
            import static java.lang.annotation.ElementType.TYPE;
            import static java.lang.annotation.RetentionPolicy.RUNTIME;
            
            import java.lang.annotation.Retention;
            import java.lang.annotation.Target;
            
            import org.jboss.seam.annotations.intercept.Interceptors;
            
            @Target(TYPE)
            @Retention(RUNTIME)
            @Interceptors(GekkoSpringInjector.class)
            public @interface SeamAutowired {}
            



            My only concern now is that every Seam bean will now have to have this annotation for the interceptor to fire. How can I make this a "default" interceptor? Just like the Bijection Interceptor. Cause as it stands I don't see any way of doing this as the Bijection Interceptor is hard coded as a default interceptor

            • 3. Re: Seam Interceptors
              Tim Evers Master

              oops sorry posted at the same time.


              Thanks for your answer. Hope to see default interceptors soon :)