8 Replies Latest reply on Apr 15, 2010 4:17 AM by ropalka

    Wrong JNDI context returned from EJB

    ropalka

      Hi EJB team,

       

         This is related to issue: https://jira.jboss.org/jira/browse/JBAS-7888

       

         I'm analyzing this failure:

      http://jbossws.jboss.org:8180/hudson/job/AS-TESTS-AS-6.0.1/113/testReport/

       

      To reproduce the problem, just type:

      cd jbossas/trunk/testsuite

      ./build.sh clean main

      ./build.sh -Dtest=org.jboss.test.ws.jaxws.ejb3Integration.injection.InjectionTestCase one-test

       

      I found it started to fail since:

      http://jbossws.jboss.org:8180/hudson/job/AS-6.0.1/109/

      I think it might be related to:

      https://jira.jboss.org/jira/browse/JBAS-7854

       

      Here are my investigations:

       

      Our archive structure is:

      jbossas/trunk/testsuite/output/lib]>jar -tvf jaxws-injection.ear
           0 Fri Apr 02 12:20:46 CEST 2010 META-INF/
         102 Fri Apr 02 12:20:44 CEST 2010 META-INF/MANIFEST.MF
         602 Fri Apr 02 12:20:46 CEST 2010 META-INF/application.xml
        7367 Fri Apr 02 12:20:46 CEST 2010 jaxws-injection-ejb3.jar
        9000 Fri Apr 02 12:20:46 CEST 2010 jaxws-injection-pojo.war
        2323 Fri Apr 02 13:54:46 CEST 2010 jaxws-injection.jar

       

      Relevant JNDI trees are (from JMX console):

       

      java:comp namespace of the component jboss.j2ee:ear=jaxws-injection.ear,jar=jaxws-injection.jar,name=BeanImpl,service=EJB3 :

       

        +- EJBContext (class: javax.ejb.EJBContext)
        +- TransactionSynchronizationRegistry[link -> java:TransactionSynchronizationRegistry] (class: javax.naming.LinkRef)
        +- UserTransaction (class: org.jboss.ejb3.tx.UserTransactionImpl)
        +- env (class: org.jnp.interfaces.NamingContext)
        +- ORB[link -> java:/JBossCorbaORB] (class: javax.naming.LinkRef)

       


      java:comp namespace of the component jboss.j2ee:ear=jaxws-injection.ear,jar=jaxws-injection-ejb3.jar,name=EJB3Bean,service=EJB3 :

       

        +- EJBContext (class: javax.ejb.EJBContext)
        +- TransactionSynchronizationRegistry[link -> java:TransactionSynchronizationRegistry] (class: javax.naming.LinkRef)
        +- UserTransaction (class: org.jboss.ejb3.tx.UserTransactionImpl)
        +- env (class: org.jnp.interfaces.NamingContext)
        |   +- org.jboss.test.ws.jaxws.ejb3Integration.injection.webservice.AbstractEndpointImpl (class: org.jnp.interfaces.NamingContext)
        |   |   +- testBean2[link -> jaxws-injection/BeanImpl/local-org.jboss.test.ws.jaxws.ejb3Integration.injection.shared.BeanIface] (class: javax.naming.LinkRef)
        |   |   +- bean[link -> jaxws-injection/BeanImpl/local-org.jboss.test.ws.jaxws.ejb3Integration.injection.shared.BeanIface] (class: javax.naming.LinkRef)
        |   +- boolean1 (class: java.lang.Boolean)
        +- ORB[link -> java:/JBossCorbaORB] (class: javax.naming.LinkRef)

       

      In our JBossWS AS Integration layer we're lookuping the JNDI context as:

       

      public Context getJNDIContext(final Endpoint ep) throws NamingException
      {
            final EJBContainer ejb3Container = (EJBContainer)getEjb3Container("jboss.j2ee:ear=jaxws-injection.ear,jar=jaxws-injection-ejb3.jar,name=EJB3Bean,service=EJB3");
            return (Context)ejb3Container.getEnc().lookup("java:env/");
      }

       

      This call used to return proper JNDI tree associated with

      jboss.j2ee:ear=jaxws-injection.ear,jar=jaxws-injection-ejb3.jar,name=EJB3Bean,service=EJB3.

      Unfortunately these days in AS trunk it returns the JNDI tree associated with

      jboss.j2ee:ear=jaxws-injection.ear,jar=jaxws-injection.jar,name=BeanImpl,service=EJB3

       

      IMHO this is a bug in EJB code base.

        • 1. Re: Wrong JNDI context returned from EJB
          wolfc

          It's pretty much undefined what this would return, so it can't be a bug.

          return ejb3Container.getEnc().lookup("java:env/");
          

           

          The test is passing for me locally, but given the above we do have a problem here.

           

          You could do:

          return ejb3Container.getEnc().lookup("env");
          

           

          At least that's the equivelant to java:comp/env, but it's still depending on internals (EJBContainer).

           

          To really fix it you should be looking for the java:comp coming from the naming deployers.

          • 2. Re: Wrong JNDI context returned from EJB
            ropalka

            OK, I'll have a look. Thanks Carlo for information.

            • 3. Re: Wrong JNDI context returned from EJB
              ropalka

              The situation is little bit more complicated.

              First of all I need to verify if the following usecase is valid.

               

              There's a EJB3Bean web service bean

              with the following DD. It defines boolean1 env entry.

               

              <ejb-jar>

                 <enterprise-beans>
                  <session>

                    <ejb-name>EJB3Bean</ejb-name>
                    <ejb-class>org.jboss.test.ws.jaxws.ejb3Integration.injection.webservice.EJB3Bean</ejb-class>

               

                    <env-entry>
                      <env-entry-name>boolean1</env-entry-name>
                      <env-entry-type>java.lang.Boolean</env-entry-type>
                      <env-entry-value>true</env-entry-value>
                    </env-entry>

               

                  </session>

                </enterprise-beans>

              </ejb-jar>

               

              There's a handler associated with this EJB3Bean

               

              @WebService
              @HandlerChain(file = "jaxws-handler.xml")
              @Stateless
              public class EJB3Bean extends AbstractEndpointImpl
              {

               

                 public String echo(String msg)
                 {
                    return super.echo(msg) + ":EJB3Bean";
                 }

               

              }

               

              The content of jaxws-handler.xml is:

               

              <handler-chains>

                <handler-chain>
                  <handler>
                    <handler-name>TestHandler</handler-name>
                    <handler-class>org.jboss.test.ws.jaxws.ejb3Integration.injection.shared.handlers.TestHandler</handler-class>
                  </handler>
                </handler-chain>

              </handler-chains>

               

              This TestHandler tries to access both EJB3Bean and it's env-entry

               

              public final class TestHandler extends GenericSOAPHandler {
                 @Resource private Boolean boolean1;
                 @EJB private BeanIface bean1;

                 ...

              }

               

              Using global JNDI I'm able to fix @EJB injection.

               

              Question for EJB3 team:

              Do you think this JAX-WS handler should see env-entry of EJB3Bean?

              That would mean required access to EJB3Bean specific JNDI context (the reason why we're using it instead of global JNDI).

               

              I'll double check JAX-WS and EE6 specification for clarification, but would like to know your opinion

              • 4. Re: Wrong JNDI context returned from EJB
                ropalka

                Related issue JBWS-2558

                • 5. Re: Wrong JNDI context returned from EJB
                  ropalka

                  Copy/paste from JSR-109, section 6.2.2.2

                   

                  The container must carry out any injections (if any) requested by the handler, typically via the @Resource
                  annotation (see section 2.2 of JSR-250 Common Annotations for Java Platform specification)
                  . After all the
                  injections have been carried out, the container must invoke the method carrying a
                  javax.annotation.PostConstruct annotation.

                   

                  The question is the scoping. Should this EJB3 associated JAX-WS handler

                  (part of WS runtime) see environment entries of particular EJB3 bean?

                  • 6. Re: Wrong JNDI context returned from EJB
                    ropalka

                    <bgeorges> ropalka: I was wondering what is happening with https://jira.jboss.org/jira/browse/JBAS-7888 as we still have regressions with WS
                    <JiraBot> [#JBAS-7888] Investigate EJB3 Injection Integration Issue [Reopened, Major, Richard Opalka]
                    <ropalka> bgeorges, https://community.jboss.org/message/535366#535366
                    <ropalka> bgeorges, I'm waiting for Alessios and Carlos opinion on this topic
                    <bgeorges> ropalka: ok, thank you. carlo: can you have a look
                    <ropalka> bgeorges, However IMHO it's not a blocker for M3 release
                    <carlo> I don't know how a Handler is scoped.
                    <carlo> But JSR-250 injection happens from java:comp
                    <bgeorges> ropalka: that would be good, carlo: wdyt
                    <JiraBot> JIRA at jira.jboss.org reports that JSR-250 does not exist. https://jira.jboss.org/jira/browse/JSR-250
                    <carlo> bgeorges: okay by me
                    <ropalka> carlo, bgeorges If JSR 250 injection happens from java:comp only then I know how to fix it. I'll remove this handler.
                    <ropalka> carlo, bgeorges I'll review also JSR 250 to be 100% sure

                    • 7. Re: Wrong JNDI context returned from EJB
                      wolfc

                      EE.5.2.1 The Application Component’s Environment

                      The container injects entries from the environment into application component fields or methods as specified by the application component’s deployment descriptor or by annotations on the application component class.

                      • 8. Re: Wrong JNDI context returned from EJB
                        ropalka

                        I reviewed JSR 250 but didn't find relevant information but I found it in EJB 3.1 spec.

                         

                        Copy/paste from EJB 3.1 spec. - 16.2 Enterprise Bean’s Environment as a JNDI Naming Context

                         

                        The container must make an enterprise bean’s environment available to any interceptor class
                        and any JAX-WS message handler for the bean as well. The interceptor and web service han-
                        dler classes for an enterprise bean share that bean’s environment.

                         

                        IOW JBossWS implementation is correct in terms it's trying to access EJB 3 specific JNDI context.