0 Replies Latest reply on May 12, 2012 5:19 AM by Christoph Albrecht

    Problem with @Interceptors on generic bean methods, JBAS7

    Christoph Albrecht Newbie

      Hello all,

       

      Migrating my application from JBoss 4.2.3-GA to JBoss 7.1.1-Final I stumpled upon following issue.

      What is working fine for me with JB-4.2.3 does not with JB-7.1.1.

       

      I want an interceptor be triggered on a stateless session bean method that is an implementation of a generic superinterface method declaration.

       

      @Stateless
      @Remote(TestBeanService.class)
      public class TestBean implements TestBeanService {
          
      
          @Interceptors(TestInterceptor.class)
          public void simpleFoo() {
              System.out.println("doing simple foo");
          }
      
      
          @Override
          @Interceptors(TestInterceptor.class)
          public void genericFoo(SomeClass entity) {
              System.out.println("doing generic foo");
          }
      
      }
      
      
      //====================================================
      
      public interface TestBeanService extends GenericService<SomeClass> {
          
          public void simpleFoo();
          
      }
      
      
      //====================================================
      
      public interface GenericService<T> {
      
          public void genericFoo(T entity);
      }
      
      //====================================================
      
      
      public class TestInterceptor {
      
          @AroundInvoke
          public Object intercept(InvocationContext invocation) throws Exception {
      
              try {
                  System.out.println("intercepting method invocation: " + invocation.getMethod());
                  Object object = invocation.proceed();
                  return object;
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      
      }
      

       

      If the genericFoo() method is called from a client the invocation is not being intercepted on JB-7.1.1 (on JB-4.2.3 it is). The simpleFoo() method invocation is intercepted without problems.

       

      The only way I found making genericFoo() be intercepted on JB-7.1.1 is either to declare the @Interceptors(TestInterceptor.class) annotation on top of the bean class (on the cost of making every method in the bean class be intercepted):

       

      @Stateless
      @Remote(TestBeanService.class)
      @Interceptors(TestInterceptor.class) 
      public class TestBean implements TestBeanService {
       //...
      }
      

       

      The other way around is to add an extra genericFoo() method declaration in the TestBeanService interface, what I was expecting should be unnecessary:

       

      public interface TestBeanService extends GenericService<SomeClass> {
          
          public void simpleFoo();
      
          public void genericFoo(SomeClass entity);
          
      }
      

       

      Don't know, is this an known/new issue with JBoss (EJB) or am I missing something?

       

      https://issues.jboss.org/browse/EJBTHREE-2231

       

      https://issues.jboss.org/browse/EJBTHREE-471

       

      https://community.jboss.org/message/557649#557649

       

      Regards