4 Replies Latest reply on Mar 7, 2012 6:22 AM by prasad.deshpande

    Error on EJB Invocation from remote clients using JNDI

    lkasprzy

      If I follow with instruction described in https://docs.jboss.org/author/display/AS71/Getting+Started+Developing+Applications+Guide#GettingStartedDevelopingApplicationsGuide-EJB%3AInvocationfromremoteclientsusingJNDI

      using on classpath only jar JBOSS_HOME/bin/client/jboss-client-7.1.0.Final.jar to run org.jboss.as.quickstarts.ejb.remote.client.RemoteEJBClient

      exception is throwed:

       

      Caused by: javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.as.naming.InitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.jboss.as.naming.InitialContextFactory]

       

      I looked into JBOSS_HOME/bin/client/jboss-client-7.1.0.Final.jar and I don't see in them file org.jboss.as.naming.InitialContextFactory.class, only org.jboss.naming.remote.client.InitialContextFactory.class.

       

      File org.jboss.as.naming.InitialContextFactory.class I fouded in jboss-as-naming-7.1.0.Final.jar.

       

      Is JBOSS_HOME/bin/client/jboss-client-7.1.0.Final.jar shoul'd be only one jar  used to remote invocation?

      Is exist some single jar witch contain all classes witch are necessary to remote invocation (in previous version 7.1.0.CR1b was few jars)?

        • 1. Re: Error on EJB Invocation from remote clients using JNDI
          prasad.deshpande

          Łukasz Kasprzyk wrote:

           

          If I follow with instruction described in https://docs.jboss.org/author/display/AS71/Getting+Started+Developing+Applications+Guide#GettingStartedDevelopingApplicationsGuide-EJB%3AInvocationfromremoteclientsusingJNDI

          using on classpath only jar JBOSS_HOME/bin/client/jboss-client-7.1.0.Final.jar to run org.jboss.as.quickstarts.ejb.remote.client.RemoteEJBClient

          exception is throwed:

           

          Caused by: javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.as.naming.InitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.jboss.as.naming.InitialContextFactory]

           

          Can you please check if you have jboss-ejb-client.properties file in your client classpath? That's the most probable reason for you having this exception in your case.

           

          Is JBOSS_HOME/bin/client/jboss-client-7.1.0.Final.jar shoul'd be only one jar  used to remote invocation?

          Yes, if you just want a single jar for remote clients, then that's the one..

          • 2. Re: Error on EJB Invocation from remote clients using JNDI
            jaikiran

            What does your remote client code look like? You shouldn't be using org.jboss.as.naming.InitialContextFactory as your intial context factory for remote clients.

            • 3. Re: Error on EJB Invocation from remote clients using JNDI
              lkasprzy

              Ok, my mistake. I putted org.jboss.as.naming.InitialContextFactory as initial context factory.

               

              So please answer for this questions:

              It is possible to set programatticly all properties witch contain  file jboss-ejb-client.properties (and how I should do this, I didn't found any example)?

              I have one client(installed on tomcat) and few ear applications(on jboss) in diffrent localizations, and client application decide where request is going.

              Now I have:

                      final Hashtable<String, String> p = new Hashtable<String, String>();

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

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

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

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

                      p.put(Context.SECURITY_CREDENTIALS, "password");


              but what with other parameters ?

              How to set them without using any jboss specific api.


              Is necessary to ad static block with  Security.addProvider(new JBossSaslProvider()? In example downloaded from https://github.com/jbossas/quickstart/zipball/master

              in file RemoteEJBClient this block is not removed.





              • 4. Re: Error on EJB Invocation from remote clients using JNDI
                prasad.deshpande

                It is possible to set programatticly all properties witch contain  file jboss-ejb-client.properties (and how I should do this, I didn't found any example)?


                Yes, it is possible to set all properties programatically. all you have to do is create an object of java.util.Properties with all the properties you want to set & pass it to EJBClientContext as follows:

                 

                Properties props = .... // these are the properties that you are setting. You can even read jboss-ejb-client.properties as input stream & create properties out of it..

                final EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration(props);

                final ContextSelector<EJBClientContext> ejbClientContextSelector = new ConfigBasedEJBClientContextSelector(ejbClientConfiguration);

                EJBClientContext.setSelector(ejbClientContextSelector);

                If you are setting properties this way then you don't need to have "jboss-ejb-client.properties" in classpath. Once above code is executed, you can lookup in JNDI normally your beans..

                 

                 

                I have one client(installed on tomcat) and few ear applications(on jboss) in diffrent localizations, and client application decide where request is going.

                Now I have:

                        final Hashtable<String, String> p = new Hashtable<String, String>();

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

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

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

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

                        p.put(Context.SECURITY_CREDENTIALS, "password");


                but what with other parameters ?

                How to set them without using any jboss specific api.

                You can put all these properties in "jndi.properties" file and put that file in your classpath. This way you don't need to hardcode them in your code. When you create InitialContext() with no argument, it will look for jndi.properties in classpath. If these are the properties you are worried about, then it can safely go jndi.properties. However, jboss-ejb-client.properties are different set of properties, If you don't want any JBoss specific code then it's better to keep jboss-ejb-client.propeties in file.

                 

                 

                Is necessary to ad static block with  Security.addProvider(new JBossSaslProvider()? In example downloaded from https://github.com/jbossas/quickstart/zipball/master

                in file RemoteEJBClient this block is not removed.

                No, that static block is not needed anymore with 7.1 release, when initially remoting was introduced, that time it needed.

                1 of 1 people found this helpful