5 Replies Latest reply on Nov 13, 2014 11:39 AM by nicolacorsaro

    Scoped EJB Client Contexts Question: lookup "ejb:" or "java:"

    nicolacorsaro

      I can't understand why this doesn't work for me:

      Context ejbRootNamingContext = (Context) new InitialContext(props).lookup("ejb:");

       

      But this works:

      Context ejbRootNamingContext = (Context) new InitialContext(props).lookup("java:");

       

      My code is something like this (the example in the JBoss documentation)

      final Properties props = new Properties();

      // mark it for scoped EJB client context

      props.put("org.jboss.ejb.client.scoped.context","true");

      // add other properties

      props.put(....);

      ...

      Context jndiCtx = new InitialContext(props);

      Context ejbRootNamingContext = (Context) jndiCtx.lookup("ejb:");

      try {

          final MyBean bean = ejbRootNamingContext.lookup("app/module/distinct/bean!interface"); // the rest of the EJB jndi string

          bean.doSomething();

      } finally {

          try {

              // close the EJB naming JNDI context

              ejbRootNamingContext.close();

          } catch (Throwable t) {

              // log and ignore

          }

          try {

              // also close our other JNDI context since we are done with it too

              jndiCtx.close();

          } catch (Throwable t) {

              // log and ignore

          }

       

      }

       

      Please, explain me what's the difference between "ejb:" and "java:"

        • 1. Re: Scoped EJB Client Contexts Question: lookup "ejb:" or "java:"
          wdfink

          Hello Nicola,

           

          what kind of client do you use? Also what properties do you pass to the InitialContext?

           

          The difference between "java:" and "ejb:" is that java is a typical JNDI lookup but inside of the JVM, often such lookups will only provide internal references.

          The "ejb:" is special to JBoss/WildFly for EJB lookups and handled different.

          • 2. Re: Scoped EJB Client Contexts Question: lookup "ejb:" or "java:"
            nicolacorsaro

            Thank you very much for you answer.

            The properties are:

            Properties jndiProps = new Properties();

              jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

              jndiProps.put(Context.PROVIDER_URL,"http-remoting://172.16.1.25:8080");

            jndiProps.put(Context.SECURITY_PRINCIPAL, "test");

            jbndiProps.put(Context.SECURITY_CREDENTIALS, "test");

            jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

             

            My program is a Java Swing client. It works very well with JBoss 6 Final.

            Now I've changed to Wildfly 8 and I had to change the lookup.

             

            I've made changes following the documentation and the program now works

            but is slower than the JBoss 6 version.

            Because of this problem with "ejb:" I have the suspect that I've made something wrong.

             

            Please help me. The program is too slow now.

            • 3. Re: Scoped EJB Client Contexts Question: lookup "ejb:" or "java:"
              nicolacorsaro

              I have also this line in my properties

              jndiProps.put("jboss.naming.client.ejb.context", true);

               

              On server side, JNDI names in server.log look like:

                      java:global/ejbxpallet/DatiUtenteBean!it.xteam.application.xpallet.ejb.local.DatiUtenteLocal

                      java:app/ejbxpallet/DatiUtenteBean!it.xteam.application.xpallet.ejb.local.DatiUtenteLocal

                      java:module/DatiUtenteBean!it.xteam.application.xpallet.ejb.local.DatiUtenteLocal

                      java:global/ejbxpallet/DatiUtenteBean!it.xteam.application.xpallet.ejb.remote.DatiUtenteRemote

                      java:app/ejbxpallet/DatiUtenteBean!it.xteam.application.xpallet.ejb.remote.DatiUtenteRemote

                      java:module/DatiUtenteBean!it.xteam.application.xpallet.ejb.remote.DatiUtenteRemote

                      java:jboss/exported/ejbxpallet/DatiUtenteBean!it.xteam.application.xpallet.ejb.remote.DatiUtenteRemote

               

              So,(with Wildfly 8 Final) if I use

              Context ejbRootNamingContext = (Context) new InitialContext(props).lookup("java:");

              it always works

               

              If I use:

              Context ejbRootNamingContext = (Context) new InitialContext(props).lookup("ejb:");

              and jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

              the error is:

              java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling

               

              If I use:

              Context ejbRootNamingContext = (Context) new InitialContext(props).lookup("ejb:");

              without jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

              the error is:

              javax.naming.NameNotFoundException: ejb: -- service jboss.naming.context.java.jboss.exported.ejb:

              • 4. Re: Scoped EJB Client Contexts Question: lookup "ejb:" or "java:"
                wdfink

                As you use the remote-naming approach the "ejb:" prefix is not allowed for lookup.

                Please see teh current document for this Remote EJB invocations via JNDI - EJB client API or remote-naming project

                • 5. Re: Scoped EJB Client Contexts Question: lookup "ejb:" or "java:"
                  nicolacorsaro

                  Ok, thank you very much Wolf. Now I understand the confusion I've made.