0 Replies Latest reply on Sep 7, 2017 12:59 PM by meptcs

    Same interceptor called twice

    meptcs

      Hi,

      I have two classes A & B, where B extends A (A is abstract). I have a list of interceptors I1,I2,I3(see below).

      The interceptors try to accomplish the execution of before/after actions for the method 'm'.

      The classes A & B are some beans, where A is a base bean with some common/base methods/functionality (like before/after actions), and other beans (like B) use those methods (in interceptors the 'doStuff' methods call on 'invokeCtx.target' the methods from base bean - A).

       

      I want to 'overwrite' the list of class-level interceptors for class B (meaning that methods from bean B will catch CustomExc and do some stuff with it before to throw further).

      The issue is that for method 'm' the interceptors I1 & I2 are called twice.

      I checked the link https://docs.oracle.com/javaee/7/tutorial/interceptors002.htm  and it said "If the target class has superclasses, any interceptors defined on the superclasses are invoked first, starting with the most general superclass."

      It is possible to disable/ignore calls of the interceptors from parent target class? Or maybe to do in another way what I described above.

      Note that if I put in class B the list of interceptors on method 'm', everything goes fine. But there are many methods in class B so I want to avoid copy-paste.

       

      @Interceptors({I1.class,I2.class})

      public abstract class A{}

       

      @Interceptors({I1.class,I3.class, I2.class})

      public class B extends A

      {   

           public void m(){}

      }

       

      I1

      {

        public Object intercept( InvocationContext invokeCtx ) throws Exception

        { doStuff( invokeCtx ); return invokeCtx.proceed( ); }

      }

       

      I2

      {

        public Object intercept( InvocationContext invokeCtx ) throws Exception

        {

           try{ return invokeCtx.proceed( );}

           finally {doStuff(invokeCtx);}

        }

      }

       

      I3

      {

        public Object intercept( InvocationContext invokeCtx ) throws Exception

        {

           try{return invokeCtx.proceed( );}

           catch(CustomExc e){doStuff(e); throw e;}

         }

      }

       

      For above example, for method 'm' the interceptors are called in the following order I1, I2, I1, I3, I2.

      When I debug and inspect the field 'invokeCtx.interceptors' in I1.intercept, it contains an array like this: [I1, I2, I1, I3, I2]. It seems that it merged the interceptors from parent class with those in child class.

      The server version is: JBoss EAP 7.0.7.GA (WildFly Core 2.1.17.Final-redhat-1)

      Thank you.