4 Replies Latest reply on Oct 25, 2012 8:25 AM by luksa Branched from an earlier discussion.

    Custom interceptor not being invoked

    vladcrc

      Hi,

       

      I have a somehow similar problem with a custom interceptor.

      In JBoss AS 7.2-SNAPSHOT I have built the following:

       

      - a custom subsystem which is composed by 2 jars;

      - one of the jar contains interfaces and some simple classes, it is a sort of "api" for clients;

      - in this subsystem I have an interceptor. the class is called AppStatusInterceptor. it is placed in the "api" jar.

      - the subsystem has dependencies to "org.jboss.as.ejb3" and "javax.interceptor.api" modules declared in module.xml.

       

      - an application (a simple EJB) with a method annotated "@Interceptors(AppStatusInterceptor.class)"

      - the application has a dependency to my custom subsystem declared in MANIFEST.MF.

       

      The deployment of both subsystem and application runs fine, without errors.

       

      When I call the application from a standalone client, the method is called corectly but the interceptor is not activated/triggered. Again, no error message.

       

      If I put the interceptor class inside the application instead of putting it inside the subsytem then the interceptor is acting fine.

       

      Should it be something I miss ? Maybe some classloading issues ?

       

      Thank you,

      Vlad

        • 1. Re: Custom interceptor not being invoked
          lehvolk

          Interceptors invoked by CDI. Switch on CDI on each deployment subsystem or just on parent one (this means that beans.xml file should be added to META-INF folder, also you have to specify all interceptiors inside beans.xml) . You should check out Weld documentation where placed correct way for declaring Interceptors http://docs.jboss.org/weld/reference/latest/en-US/html/interceptors.html

          • 2. Re: Custom interceptor not being invoked
            vladcrc

            OK, I changed to CDI-style interceptor bindings and I have this:

             

            - a custom subsystem;

            - the subsystem has dependencies to "org.jboss.as.ejb3" and "javax.interceptor.api" modules declared in module.xml.

            - an interceptor binding called "AppStatus".

            - an interceptor. the class is called "AppStatusInterceptor", annotated with "@Interceptor", "@AppStatus" and a method with "@AroundInvoke".

             

            - an application (a simple EJB) with a method annotated with "@AppStatus".

            - the application has a dependency to my custom subsystem declared in MANIFEST.MF.

            - the application has "META-INF\beans.xml" where the "AppStatusInterceptor" is enabled.

             

            When I deploy the application I get the following error:

             

            ------------------------

            org.jboss.weld.exceptions.DeploymentException: WELD-001417 Enabled interceptor class <class>com.xxx.AppStatusInterceptor</class>

            in vfs:/xxx/jboss-as-7.2.0.Alpha1-SNAPSHOT/bin/content/xxx.jar/META-INF/beans.xml@6

            is neither annotated @Interceptor nor registered through a portable extension

            ------------------------

             

            which is not true, because the @Interceptor is present.

             

            I found this

            http://java.net/jira/browse/GLASSFISH-15936

            but it's for Glassfish...

            • 3. Re: Custom interceptor not being invoked
              lehvolk

              I think it is bad exception message. This example works for me:

               

              binding (placed in module):

               

              import java.lang.annotation.ElementType;

              import java.lang.annotation.Retention;

              import java.lang.annotation.RetentionPolicy;

              import java.lang.annotation.Target;

               

              import javax.interceptor.InterceptorBinding;

               

              @InterceptorBinding

              @Target({ ElementType.METHOD, ElementType.TYPE })

              @Retention(RetentionPolicy.RUNTIME)

              public @interface GuiceInjection {

              }

               

              here is interceptor (placed in deployment):

               

              import javax.annotation.PostConstruct;

              import javax.interceptor.Interceptor;

              import javax.interceptor.InvocationContext;

               

              @Interceptor

              @GuiceInjection

              public class BeanInterceptor {

              .....

              }

               

              here is EJB (in deployment too):

               

              @Stateless

              @GuiceInjection

              public class EJBBean{

              }

              • 4. Re: Custom interceptor not being invoked
                luksa

                Vlad, this looks like a classloading/visibility issue.  In Weld 1.1.10.Final there was a major fix in this area. Are you using it?