2 Replies Latest reply on Feb 13, 2012 10:55 AM by pi4630 Branched to a new discussion.

    EJB invocation from remote client via JNDI

    pi4630

      Hello,

       

      I am doing EJB related concepts works on JBoss7.1.0CR1b.

      I consulted Jaikiran's documentation here, but I get a

      {noformat}

      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{noformat}

       

      I have a HelloMessage.jar deployed. It contains the interface ITalkRemote (carries @Remote annotation) and a SLSB named Talker that implements it. The deployment is OK (I start the JBoss7.1 full config)

      My client code is this:

       

      {code}

      private static ITalkRemote lookupService() throws NamingException {

                          ITalkRemote service = null;

                          final Hashtable jndiProperties = new Hashtable();

                          jndiProperties.put(Context.URL_PKG_PREFIXES,

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

                          final Context context = new InitialContext(jndiProperties);

       

                          final String appName = "";

       

                          final String moduleName = "HelloMessage";

       

                          final String distinctName = "";

       

                          final String beanName = "Talker";

       

                          final String viewClassName = ITalkRemote.class.getName();

                          service = (ITalkRemote) context.lookup("ejb:" + appName + "/"

                                              + moduleName + "/" + distinctName + "/" + beanName + "!"

                                              + viewClassName);

       

       

                          return service;

                }

      {code}

       

      On the package level of the client class, I've put a jboss-ejb-client.properties that carries the following elements:

       

      {noformat}

      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.two.host=localhost

      remote.connection.two.port = 4447

      remote.connection.two.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

      {noformat}

       

      The client's build path includes the libraries of the JBoss 7.1 Runtime (it's a JavaProject in eclipse).

       

      If I set

       

      {code}

      jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");{code}

      I get a

       

      {noformat}Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]{noformat}

       

      Thanks for caring,

        • 1. Re: EJB invocation from remote client via JNDI
          prasad.deshpande

          What jars are you using in your client classpath? Can you please list them? If you could try to use individual jar files listed in Jaikiran's blog for CR1b release.

          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

           

          You'd get this error mostly when you are missing jboss-ejb-client.properties in the classpath.. can you try getClass().getClassLoader().getResourceAsStream("jboss-ejb-client.properties"); to see if you get input stream?

           

          jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

           

           

          Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]

           

          That is avialble in modules/org/jboss/remote-naming/main/jboss-remote-naming-1.0.0.Final.jar But that is very unlikely to be available in CR1b release..

           

           

          I'd suggest you use latest nightly build which has a special client jar in <jboss_home>/bin/client/jboss-client-7.1.0.Final-SNAPSHOT.jar that has got all the required classes & that is the only jar you'd need to use in remote client classpath for communicating with jboss.

          • 2. Re: EJB invocation from remote client via JNDI
            pi4630

            Thanks Prasad,

             

            for some reason I did not consider/saw the jar list Jaikiran has put there.

             

            I've created a User Library with those jars, put that to my project's path and now it works.

             

            Thanks again,