3 Replies Latest reply on Nov 18, 2010 6:56 AM by Robson Ximenes

    Another Interceptor Problem

    Cleverson Sacramento Newbie

      I'm getting the following error when I try to use my Interceptor: Duplicate interceptor class definition...


      I will provide a example to simulate the error. At first step, I created my InterceptorBinding like this:


      @InterceptorBinding @Target(TYPE) @Retention(RUNTIME)
      public @interface MyInterceptorBinding {
      }



      Then I created my Interceptor:


      @Interceptor @MyInterceptorBinding
      public class MyInterceptor {
      
           @AroundInvoke
           public Object manage(final InvocationContext ctx) throws Exception {
                return ctx.proceed();
           }
      }



      ... and my Stereotype annotation.


      @Stereotype @Named @MyInterceptorBinding @Target(TYPE) @Retention(RUNTIME)
      public @interface MyStereotype {
      }



      The fail occurs when I use my own object.


      public class MyObject {
      }



      This is my managed bean:


      @MyStereotype
      public class MyManagedBean extends MySuperClass<MyObject> {
      
           @Override
           public MyObject perform() {
                return null;
           }
      }



      And this is its super class:


      public abstract class MySuperClass<T> {
      
           public T perform() {
                return null;
           }
      }




      I registered my interceptor in bean.xml.


      <?xml version="1.0"?>
      <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
      
           <interceptors>
                <class>MyInterceptor</class>
           </interceptors>
      </beans>




      When I try to start my servlet container, I get this stack trace:



      # SEVERE: Exception sending context initialized event to listener instance of class org.jboss.weld.environment.servlet.Listener
      org.jboss.interceptor.InterceptorException: Duplicate interceptor class definition when bindingorg.jboss.weld.bean-flat-Interceptor-MyInterceptor on AROUND_INVOKE
           at org.jboss.interceptor.model.InterceptionModelImpl.validateDuplicateInterceptors(InterceptionModelImpl.java:150)
           at org.jboss.interceptor.model.InterceptionModelImpl.appendInterceptorClassesToList(InterceptionModelImpl.java:138)
           at org.jboss.interceptor.model.InterceptionModelImpl.appendInterceptors(InterceptionModelImpl.java:131)
           at org.jboss.interceptor.model.InterceptionModelBuilder$MethodInterceptorDescriptor.with(InterceptionModelBuilder.java:111)
           at org.jboss.weld.bean.AbstractClassBean.initCdiBoundInterceptors(AbstractClassBean.java:435)
           at org.jboss.weld.bean.AbstractClassBean.initialize(AbstractClassBean.java:178)
           at org.jboss.weld.bean.ManagedBean.initialize(ManagedBean.java:365)
           at org.jboss.weld.bootstrap.AbstractBeanDeployer.deploy(AbstractBeanDeployer.java:110)
           at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:151)
           at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:377)
           at org.jboss.weld.environment.servlet.Listener.contextInitialized(Listener.java:171)
           at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
           at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
           at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
           at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
           at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
           at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
           at org.apache.catalina.core.StandardService.start(StandardService.java:516)
           at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
           at org.apache.catalina.startup.Catalina.start(Catalina.java:593)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
           at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)



      But, if I comment the super class method, it works! :P


      public abstract class MySuperClass<T> {
      
           // public T perform() {
           //      return null;
           // }
      }




      If I use a java bluit-in class (like Object, String, Integer) instead of MyObject class, it works too! :P :P




      @MyStereotype
      public class MyManagedBean extends MySuperClass<Object> {
      
           @Override
           public Object perform() {
                return null;
           }
      }



      public abstract class MySuperClass<T> {
      
           public T perform() {
                return null;
           }
      }




      On my tests, I used the folowing Weld version:


      <dependency>
           <groupId>org.jboss.weld</groupId>
           <artifactId>weld-core</artifactId>
           <version>1.0.1-SP4</version>
           <scope>compile</scope>
      </dependency>
      <dependency>
           <groupId>org.jboss.weld.servlet</groupId>
           <artifactId>weld-servlet</artifactId>
           <version>1.0.1-Final</version>
           <scope>compile</scope>
      </dependency>




      ...and this too:


      <dependency>
           <groupId>org.jboss.weld</groupId>
           <artifactId>weld-core</artifactId>
           <version>1.1.0-SNAPSHOT</version>
           <scope>compile</scope>
      </dependency>
      <dependency>
           <groupId>org.jboss.weld.servlet</groupId>
           <artifactId>weld-servlet</artifactId>
           <version>1.1.0-SNAPSHOT</version>
           <scope>compile</scope>
      </dependency>




      Both generate the fail.