Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-783

@EJB injection fails in @Named bean when interceptor is present

    Details

    • Steps to Reproduce:
      Hide
      • create a stateless session bean
      • create an interceptor which just calls proceed() on the invocation context
      • create a bean annotated with @Named
      • inject the statelss session bean into the @Named bean using @EJB
      • create a method in the @Named bean in which you access the injected stateless session bean
      • bind the created interceptor to that method using @Interceptors annotation
      • stateless session bean shouldn't get injected properly anymore
      Show
      create a stateless session bean create an interceptor which just calls proceed() on the invocation context create a bean annotated with @Named inject the statelss session bean into the @Named bean using @EJB create a method in the @Named bean in which you access the injected stateless session bean bind the created interceptor to that method using @Interceptors annotation stateless session bean shouldn't get injected properly anymore

      Description

      I have a @Named bean in which I'd like to inject a component, using @Inject as well as a stateless session bean, using @EJB. The ejb is accessed using the no-interface view. Both references get injected properly in that case, but when I use an interceptor on one of the methods, only the references annotated with @Inject get injected, whereas those annotated with @EJB don't.

      The interceptor doesn't need to do anything special, this behaviour occurs even if only proceed() is invoked on the invocation context - the interceptor is always invoked correctly.

      The following snippet explains the issue:

      @Named
      public class MyController {

      @EJB
      private MyDao dao;

      @Interceptors(MyInterceptor.class)
      public void control()

      { dao.doDataAccessStuff(); /* NPE */ }

      }

      ---------------------------------------------------------------
      @Stateless
      public class MyDao {

      public void doDataAccessStuff()

      { ... }

      }
      ---------------------------------------------------------------
      public class MyInterceptor {

      @AroundInvoke
      public Object intercept(InvocationContext context) throws Exception

      { return context.proceed(); }

      }

        Gliffy Diagrams

          Activity

          Hide
          alexhanschke Alexander Hanschke added a comment -

          I attached a small NetBeans project that yields the described behaviour

          Show
          alexhanschke Alexander Hanschke added a comment - I attached a small NetBeans project that yields the described behaviour
          Hide
          alesj Ales Justin added a comment -

          I think the problem is how you mix'n'match EJB interceptors with CDI bean.
          The simple mockup test works:

          Show
          alesj Ales Justin added a comment - I think the problem is how you mix'n'match EJB interceptors with CDI bean. The simple mockup test works: https://github.com/alesj/core/blob/weld-783/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/weld783/IgnoredAtEJBTest.java
          Hide
          alesj Ales Justin added a comment -

          I've actually made the mock/test same as yours.
          (my previous was bad since I added the interceptor as CDI interceptor)
          And it works in JBossAS6.0.0.Final.

          So, if you could raise a GlassFish issue and link it to this one.
          e.g. they could reuse the same test/example as me

          Show
          alesj Ales Justin added a comment - I've actually made the mock/test same as yours. (my previous was bad since I added the interceptor as CDI interceptor) And it works in JBossAS6.0.0.Final. So, if you could raise a GlassFish issue and link it to this one. e.g. they could reuse the same test/example as me
          Hide
          alexhanschke Alexander Hanschke added a comment -

          Thank you Ales, I just filed a bug to the Glassfish Jira: http://java.net/jira/browse/GLASSFISH-15528

          Regards,
          Alex

          Show
          alexhanschke Alexander Hanschke added a comment - Thank you Ales, I just filed a bug to the Glassfish Jira: http://java.net/jira/browse/GLASSFISH-15528 Regards, Alex

            People

            • Assignee:
              alesj Ales Justin
              Reporter:
              alexhanschke Alexander Hanschke
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development