3 Replies Latest reply on Nov 4, 2015 2:47 AM by wdfink

    Jboss 7.1.1

    prajwalnagabhushan

      Hi All,

       

      How can I see the remote lookup using Jndi.properties file for Jboss 7.1.1.

       

      As i am trying to lookup from jndi, I am getting a class not found Exception.

      Is there any way that i can lookup remotely from the client.

       

       

      Thanks,
      Prajwal

        • 1. Re: Jboss 7.1.1
          jaysensharma

          Hello Prajwal,

           

              JBoss AS 7.1.1 is tooooo old. It is better to use at least JBossAS 7.2 or If you can use WildFly then is it much better from various perspectives.

           

              Assuming you use JBoss AS 7.2 then its easy to lookup "Remotely" resources deployed on JBoss AS with a JNDI name prefixed with "java:jboss/exported". Remember for remote lookup (lookup outside of the same JVM is possible if the JNDI name has the mentioned prefix)

           

              Example:

          ===========

          import javax.naming.Context;
          import javax.naming.InitialContext;
          import javax.naming.NamingException;
          import java.util.Properties;
          import java.util.Random;
          
          public class Test {
              public static void main(String[] args) {
                  Properties properties = new Properties();
                  properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
                  properties.put(Context.PROVIDER_URL, "remote://localhost:4447");     // remoting port
                  properties.put(Context.SECURITY_PRINCIPAL, "employee");                // ApplicationRealm User
                  properties.put(Context.SECURITY_CREDENTIALS, "welcome1");
                  properties.put("jboss.naming.client.ejb.context", true);
          
                  try {
                      Context context = new InitialContext(properties);
                      Company company = (Company) context.lookup("TestEAR/EJBJar/Company!model.logic.Company");
                  } catch (NamingException e) {
                      e.printStackTrace();
                  }
              }
          }
          
          • 2. Re: Jboss 7.1.1
            jaysensharma

            In Later version of JBossAS7 you can also use the "jndi.properties" file as following:

             

            You can also try adding the following kind of "jndi.properties" in the client Classpath in order to set the InitialContext environment.

             

            java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
            java.naming.provider.url=remote://localhost:4447
            java.naming.security.principal=testuser
            java.naming.security.credentials=testpwd1!
            jboss.naming.client.ejb.context=true
            

             

            With the above kind of jndi.properties in your client classpath you can do the JNDI lookup in your client code as following:

             

                                    Context context = new InitialContext(); 
                                    Object ref =  context.lookup(JNDI_NAME);
            

             

             

            Better to upgrade to WildFly ... AS 7.1.1 is really too old and not that matured.

            • 3. Re: Jboss 7.1.1
              wdfink

              I would recommend to use the jboss-ejb-client.properties file instead (or additional to) the jndi.properties.

              The approach from Jay can be used, but it is not recommended as the "remote://" context does not provide all features of the ejb invocation and you might run into problems later on and need to change the approach.

               

              For AS7 you find the example here EJB invocations from a remote client using JNDI

              But as recommeded if you use Wildfly the doc is here EJB invocations from a remote client using JNDI - WildFly 9