4 Replies Latest reply on Oct 16, 2015 5:58 PM by matthieu.brouillard

    MDB not intercepted when annotation is put dynamically

    matthieu.brouillard

      Hi,

       

      I have an issue with CDI and MDBs.

      I have a CDI extension that dynamically add an interception annotation to managed beans. Unfortunately on MDBs the intercptor is not called.

       

      In the provided/attached project I have simplified as much as I could the example, can someone confirm that it is a bug, I'll then open a JIRA.

       

      Example description:

      • it is a maven based project
      • it requires a local Wilfly installation running on standard ports
      • using cli create the expected queue:

      /subsystem=messaging/hornetq-server=default/jms-queue=LoggerMessages/:add(entries=["java:/queue/Logger/messages"])

      • execute arquillian test

      mvn verify -DUSER_NAME=adminuser -DUSER_PASSWORD=adminpassword


      In the example, a MDB (that should be intercepted) when receiving a message delegates stuff to an EJB (that should be intercepted).

      The test, send a message to the MDB queue and verifies that there were 2 interceptions.


      Currently it fails because only the stateless has been intercepted.

      If instead of putting the annotation dynamically with the extension you set it directly on the MDB & on the Stateless (and deactivate the extension) then the test works.

       

      It looks like only dynamicaly set annotations are not taken into account on MDB.

       

      Can someone confirm the problem?

       

      Thanks.

       

      Update:

      I added a version of the project that is git enabled with 2 tags:

      • dynamic: interception annotation are put dynamically by the CDI extension and the test fails
      • static: interception annotation are put directly on the classes, the extension is deactivated and the test succeeds
        • 1. Re: MDB not intercepted when annotation is put dynamically
          tremes

          Hi Matthieu,

          Which WidlFly version do you use? And which weld version do you use? Reproducer looks good on the first glance. I'll try and will let you know.

          • 2. Re: MDB not intercepted when annotation is put dynamically
            matthieu.brouillard

            Hi Tomas,

             

            the Wildfly version is 8.2.1.Final with Weld 2.2.6.Final.

             

            Also something I have noticed is that the MDB class is not listed when Observing CDI ProcessBean events:

             

                <T> void processBean(@Observes ProcessBean<T> bean) {

                    LOGGER.error("CDI process bean: {}", bean.getAnnotated().getBaseType().toString());

                }

             

            Adding that to the Extension does not show the MDB class that should be intercepted but shows for example the stateless class.

            • 3. Re: MDB not intercepted when annotation is put dynamically
              tremes

              Yes ProcessBean event is not observed, because MDB is not CDI managed bean and that's likely also the reason why your dynamically added interceptor doesn't work. If you read Java EE 7 spec (JSR-000342 Java EE 7 Final Release for Evaluation) chapter "EE.5.24 Support for Dependency Injection" there is following:

               

              .......

              Note that using these steps causes the container to create a non-contextual

              instance, which is not managed by CDI but rather by the Java EE container.

              1. Obtain a BeanManager instance.

              2. Create an AnnotatedType instance for the component into which injection is to

              occur.

              ........

               

              So your MDB is likely not contextual instance in this case and there is likely no way how the given AnnotatedType could change.

              • 4. Re: MDB not intercepted when annotation is put dynamically
                matthieu.brouillard

                Thank you Tomas, I'll have a deeper into the spec to understand why such a difference between MDBs and SLSB.

                I someone knows a way to do what I want event if I need to hook into Wildfly internals/modules instead of CDI I would also be glad to hear a voice there.

                 

                Thanks for your help and hints.