glassfish
  1. glassfish
  2. GLASSFISH-15528

EJB injection fails when using method-level interceptor

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: v3.0.1
    • Fix Version/s: None
    • Component/s: cdi
    • Labels:
      None

      Description

      When using a method-level interceptor in a @Named bean, references annotated with @EJB are not injected. Initially I filed a bug to the WELD Jira, but it seems that this is a problem related to Glassfish only (as it works in JBossAS6.0.0.Final).

      The initial issue description can be found at:
      http://issues.jboss.org/browse/WELD-783

      You may use the test from Ales Justin for verification:
      https://github.com/alesj/core/blob/weld-783/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/weld783/IgnoredAtEJBTest.java

      For the purpose of completeness, I just copied the original issue 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(); }

      }

      Regards,
      Alex

        Activity

        Hide
        Sivakumar Thyagarajan added a comment -

        I am not able to reproduce this with 3.1 trunk.
        I added System.out.println in each of your classes in the netbeans project attached in WELD-783.
        Here is the server.log output during deployment, showing that the EJB injection using @Inject is successful [SomeDAO is a SLSB].

        [#|2011-01-13T17:17:59.976+0530|INFO|glassfish3.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=72;_ThreadName=Thread-1;|Portable JNDI names for EJB InitializingBean : [java:global/interceptor-bug/InitializingBean!de.alexander_hanschke.test.interceptor.InitializingBean, java:global/interceptor-bug/InitializingBean]|#]

        [#|2011-01-13T17:17:59.985+0530|INFO|glassfish3.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=72;_ThreadName=Thread-1;|Portable JNDI names for EJB SomeDao : [java:global/interceptor-bug/SomeDao, java:global/interceptor-bug/SomeDao!de.alexander_hanschke.test.interceptor.SomeDao]|#]

        [#|2011-01-13T17:18:00.001+0530|INFO|glassfish3.1|org.hibernate.validator.engine.resolver.DefaultTraversableResolver|_ThreadID=20;_ThreadName=Thread-1;|Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.|#]

        [#|2011-01-13T17:18:00.137+0530|INFO|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=72;_ThreadName=Thread-1;|InitializingBean:postConstruct|#]

        [#|2011-01-13T17:18:00.138+0530|INFO|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=72;_ThreadName=Thread-1;|SomeInterceptor:: intercept *********|#]

        [#|2011-01-13T17:18:00.138+0530|INFO|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=72;_ThreadName=Thread-1;|SomeController::control|#]

        [#|2011-01-13T17:18:00.141+0530|INFO|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=72;_ThreadName=Thread-1;|SomeDAO::doDataAccessStuff|#]

        [#|2011-01-13T17:18:00.179+0530|INFO|glassfish3.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=72;_ThreadName=Thread-1;|WEB0671: Loading application [interceptor-bug] at [/interceptor-bug]|#]

        [#|2011-01-13T17:18:00.192+0530|INFO|glassfish3.1|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=72;_ThreadName=Thread-1;|interceptor-bug was successfully deployed in 322 milliseconds.|#]

        Marking this as closed. Please re-open should you still see this issue.

        Show
        Sivakumar Thyagarajan added a comment - I am not able to reproduce this with 3.1 trunk. I added System.out.println in each of your classes in the netbeans project attached in WELD-783. Here is the server.log output during deployment, showing that the EJB injection using @Inject is successful [SomeDAO is a SLSB] . [#|2011-01-13T17:17:59.976+0530|INFO|glassfish3.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=72;_ThreadName=Thread-1;|Portable JNDI names for EJB InitializingBean : [java:global/interceptor-bug/InitializingBean!de.alexander_hanschke.test.interceptor.InitializingBean, java:global/interceptor-bug/InitializingBean] |#] [#|2011-01-13T17:17:59.985+0530|INFO|glassfish3.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=72;_ThreadName=Thread-1;|Portable JNDI names for EJB SomeDao : [java:global/interceptor-bug/SomeDao, java:global/interceptor-bug/SomeDao!de.alexander_hanschke.test.interceptor.SomeDao] |#] [#|2011-01-13T17:18:00.001+0530|INFO|glassfish3.1|org.hibernate.validator.engine.resolver.DefaultTraversableResolver|_ThreadID=20;_ThreadName=Thread-1;|Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.|#] [#|2011-01-13T17:18:00.137+0530|INFO|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=72;_ThreadName=Thread-1;|InitializingBean:postConstruct|#] [#|2011-01-13T17:18:00.138+0530|INFO|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=72;_ThreadName=Thread-1;|SomeInterceptor:: intercept *********|#] [#|2011-01-13T17:18:00.138+0530|INFO|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=72;_ThreadName=Thread-1;|SomeController::control|#] [#|2011-01-13T17:18:00.141+0530|INFO|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=72;_ThreadName=Thread-1;|SomeDAO::doDataAccessStuff|#] [#|2011-01-13T17:18:00.179+0530|INFO|glassfish3.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=72;_ThreadName=Thread-1;|WEB0671: Loading application [interceptor-bug] at [/interceptor-bug] |#] [#|2011-01-13T17:18:00.192+0530|INFO|glassfish3.1|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=72;_ThreadName=Thread-1;|interceptor-bug was successfully deployed in 322 milliseconds.|#] Marking this as closed. Please re-open should you still see this issue.

          People

          • Assignee:
            Sivakumar Thyagarajan
            Reporter:
            alexhanschke
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Due:
              Created:
              Updated:
              Resolved: