6 Replies Latest reply on Aug 22, 2017 4:43 PM by diogocarleto

    Reusable Container Interceptor Packaging

    jfisherdev

      I am currently developing a container interceptor that I want the applications I am deploying to a WildFly server to be able to use by specifying the container interceptor in a jboss-ejb3.xml descriptor.

       

      I have created a module for the interceptor and made it a global module in the standalone.xml file, as I expect a majority of the applications to use this.

       

      I am finding that the interceptor life cycle methods are not being executed. If I package the interceptor class with the application, the interceptor methods are invoked as expected.

       

      Do the interceptor classes need to be packaged with the deployed archive, or is it possible for the interceptor classes to be packaged in a module that applications can depend on as described?

       

      I am fairly new to CDI and Java EE interceptors, so there may be something trivial I am overlooking.

       

      Any information about this would be very much appreciated.

        • 1. Re: Reusable Container Interceptor Packaging
          jaikiran

          jfisherdev wrote:

           

           

          I have created a module for the interceptor and made it a global module in the standalone.xml file, as I expect a majority of the applications to use this.

           

          It's been a while since I was involved in the implementation specifics of WildFly server. So I might be misremembering or might not be aware of the current expected semantics of the "global" modules in the EE subsystems. But from what I can recollect, the "global" modules in the EE system was essentially an (internal) hack (at that time) to get past certain implementation issues. It wasn't (and I think even now, isn't) meant to be used by applications for cases like these.

           

          jfisherdev wrote:

          I am finding that the interceptor life cycle methods are not being executed. If I package the interceptor class with the application, the interceptor methods are invoked as expected.

           

          Do the interceptor classes need to be packaged with the deployed archive, or is it possible for the interceptor classes to be packaged in a module that applications can depend on as described?

          You can create a module out of those interceptors and then have a (module) dependency in each application (via MANIFEST.MF or jboss-deployment.xml) to refer to this module. I think that should work. You _don't_ have to package them in each application.

          • 2. Re: Reusable Container Interceptor Packaging
            jaikiran

            jfisherdev wrote:


            I am fairly new to CDI and Java EE interceptors, so there may be something trivial I am overlooking.

             

             

            Just a note - about the container interceptors in WildFly (Container interceptors - WildFly 9 - Project Documentation Editor). These are *not* portable interceptors i.e. they are *not* specified by any Java EE or CDI specifications. These are just WildFly specific interceptors which allow you to run certain code on the server side before the calls end up to the target EJB on that server.

            • 3. Re: Reusable Container Interceptor Packaging
              ctomc

              how do you configure global modules?

              • 4. Re: Reusable Container Interceptor Packaging
                jfisherdev

                Are you referring to how to do this in general or my specific configuration?

                 

                Global modules are described in the Global Modules section of this document Class Loading in WildFly - WildFly 9 - Project Documentation Editor

                 

                My understanding is that they essentially define implicit module dependencies and that this is analogous to using the "lib" directory in earlier versions of JBoss AS.

                 

                There is nothing unique about the global module configuration in my case.

                 

                I generally have avoided using global modules, as I prefer to make the dependencies of each deployment clear (although, usually I am not dealing with a module that almost every deployment will use); however, I am not sure if there is a better way to do this. If there is a better way to do this, I would like to know.

                • 5. Re: Reusable Container Interceptor Packaging
                  jaikiran

                  I read your original post again and I think the only thing that's probably missing is that you haven't created Jandex (annotation index) for your module resources. I can't find the thread which has instructions on how to do it, but if you could search these forums, I guess you might find some hints on how to create one.

                  • 6. Re: Reusable Container Interceptor Packaging
                    diogocarleto

                    Hi Josh, what you need to load interceptors from you module is add on MANIFEST.MF the Dependencies as below:

                     

                    Dependencies: banana.modules.utils annotations

                     

                    The annotations flag is needed when the module dependency contains annotations that need to be processed during annotation scanning, such as when declaring EJB interceptors. Without this, an EJB interceptor declared in a module cannot be used in a deployment. There are other situations involving annotation scanning when this is needed too.

                     

                    More info in https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.0/html/development_guide/c…