4 Replies Latest reply on Mar 2, 2014 1:18 PM by invincible_virus Branched from an earlier discussion.

    EJB lookup from remote client

    nandi g Newbie

      Hi

       

      I am a new bie in EJB3.x .I am writing JUNIT test cases for ejb which is deployed in JBOSS7.1 FINAL using remote client.

      I have used all the maven dependency https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

      I have jboss-ejb-client.properties in my class path.

       

       

       

      and when i browsed through internet i found one option


        System.out.println(getClass().getClassLoader().getResourceAsStream(

        "jboss-ejb-client.properties"));

       

      it returns

      java.io.BufferedInputStream@6267fe80

       

       

      Following is the jboss-ejb-clent.properties

       

      --------------

       

      endpoint.name=client-endpoint

      remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

       

      remote.connections=default

      remote.connection.default.host=localhost

       

      remote.connection.default.port = 4447

      #remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

       

      remote.connection.default.username=admin123

      remote.connection.default.password=jboss

       

      java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory

      java.naming.factory.url.pkgs=org.jboss.ejb.client.naming

      java.naming.provider.url=remote://localhost:4447

      jboss.naming.client.ejb.context=true

      remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=true

      remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=JBOSS-LOCAL-USER

      remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false

      log4j.logger.org.jboss.ejb.client=TRACE

       

       

      --------------------

       

      But i get the following error when i try to run the test cases.

       

      ----------------

      javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

           at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)

           at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)

           at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)

           at javax.naming.InitialContext.lookup(InitialContext.java:392

      ------------------

       

       

      Please help in solving this error

      Thanks in advance

        • 1. Re: EJB lookup from remote client
          jaikiran pai Master

          It looks like you are not using the correct JNDI name to do the lookup. What does the client code look like?

          • 2. Re: EJB lookup from remote client
            nandi g Newbie

            Hi Jai

             

            client code looks like

             

            Properties props = new Properties();

             

                                          props.put("java.naming.factory.url.pkgs",

              "org.jboss.ejb.client.naming");

             

                                          InitialContext ic = new InitialContext(props);

             

                                          AdminServiceRemote homeInterface = (AdminServiceRemote) ic

                                                              .lookup("ejb:/MFiWeb-0.0.1-SNAPSHOT//AdminBean!com.apple.ist.mfi.service.bean.admin.remote.AdminServiceRemote");

             

             

            when i deploy the application server log is as follows:

             

             

             

            18:18:34,961 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named AdminBean in deployment unit deployment "MFiWeb-0.0.1-SNAPSHOT.war" are as follows:

             

             

                      java:global/MFiWeb-0.0.1-SNAPSHOT/AdminBean!com.apple.ist.mfi.service.bean.admin.remote.AdminServiceRemote

                      java:app/MFiWeb-0.0.1-SNAPSHOT/AdminBean!com.apple.ist.mfi.service.bean.admin.remote.AdminServiceRemote

                      java:module/AdminBean!com.apple.ist.mfi.service.bean.admin.remote.AdminServiceRemote

                      java:jboss/exported/MFiWeb-0.0.1-SNAPSHOT/AdminBean!com.apple.ist.mfi.service.bean.admin.remote.AdminServiceRemote

                      java:global/MFiWeb-0.0.1-SNAPSHOT/AdminBean!com.apple.ist.mfi.service.bean.admin.local.AdminServiceLocal

                      java:app/MFiWeb-0.0.1-SNAPSHOT/AdminBean!com.apple.ist.mfi.service.bean.admin.local.AdminServiceLocal

                      java:module/AdminBean!com.apple.ist.mfi.service.bean.admin.local.AdminServiceLocal

             

             

             

            And I am looking for

             

            public static final String LOOKUPNAME_ADMIN = "java:module/AdminBean!com.apple.ist.mfi.service.bean.admin.remote.AdminServiceRemote";

            • 3. Re: EJB lookup from remote client
              nandi g Newbie

              Hi

              Any help to solve the issue.....??

              • 4. Re: EJB lookup from remote client
                invincible_virus Newbie

                While this issue would have been resolved by now, still I want to share the approach I followed (this might help others facing similar issue).

                 

                Client code

                Properties prop = System.getProperties();

                final Hashtable jndiProperties = new Hashtable();

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

                jndiProperties.put(Context.PROVIDER_URL, "remote://localhost:4447");

                // username

                jndiProperties.put(Context.SECURITY_PRINCIPAL, "remote");

                // password

                jndiProperties.put(Context.SECURITY_CREDENTIALS, "remotepwd");

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

                Context ctx = new InitialContext(jndiProperties);

                 

                1. Add the jboss-client.jar in the classpath of client application
                2. Create an Application user named 'remote' using add-user.sh
                3. Lookup for the JNDI name without "java:jboss/exported", e.g. in this case "MFiWeb-0.0.1-SNAPSHOT/AdminBean!com.apple.ist.mfi.service.bean.admin.remote.AdminServiceRemote"