3 Replies Latest reply on Jan 5, 2009 2:37 AM by ezani abdul halim

    Remote JNDI connects locally

    Jan Nielsen Newbie

      I have a remote session bean running on one JBoss 4.2.3 + JDK 6 server and would like to connect to it from code running in another JBoss 4.2.3 + JDK 6 server.

      My suggestion to doing this is:

      Hashtable environment = new Hashtable();
      environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      environment.put(Context.URL_PKG_PREFIXES, "org.jboss.naming rg.jnp.interfaces");
      environment.put(Context.PROVIDER_URL, "jnp://192.168.1.10:1099");
      InitialContext context = new InitialContext(enviroment);
      Object bar = context.lookup("foo");


      Even though I have asked to connect to the JNDI server running at 192.168.1.10 by providing the PROVIDER_URL, the lookup seems to be performed on the JNDI server running on the same server as the code (i.e. localhost), and therefore it cannot find what I'm looking for. My conclusion is that PROVIDER_URL is ignored or that something overrides it.

      It think that my setup is very common, and since I can't make it work, there must be some fundamental thing about JNDI that I don't know about, so please, could someone enlighten me? Thanks up front. :-)

        • 1. Re: Remote JNDI connects locally
          Jan Nielsen Newbie

          Let me clarify in case my original description was not clear:

          I am trying to do a simple job of looking an object up in a remote JNDI registry (192.168.1.10, i.e. not the machine itself). When run from the command line, the code above works perfectly by looking the object up in JNDI@192.168.1.10, but when run from within a JBoss server (e.g. in a servlet) running on another server, it is always looked up in the JNDI registry running on the server itself (thereby ignoring my PROVIDER_URL). I've tried looking for a jndi.properties file that may specify another URL but there are none.

          I have nothing to go on at this point and have practically given up. I hope someone can help.

          • 2. Re: Remote JNDI connects locally
            Jan Nielsen Newbie

            I have solved our problems today. We needed to change several things to make it work.

            1) Start JBoss with the option "-b 0.0.0.0". Otherwise, JBoss only binds to localhost. This should usually give "connection refused" when doing remote JNDI through the server's real IP, but it didn't in our case, we just got naming errors. This might be due to network configuration and maybe because we're running under Linux VServer where localhost may have a differnt meaning than usual.

            2) We accidentally were looking up in the java:-namespace. When doing this, the Context.PROVIDER_URL was silently ignored and generates no warnings or errors but does lookups locally.

            I was also told that it is a good idea to set jnp.disableDiscovery = true in the InitialContext environment to ensure that you get the server you're asking for and not a different one, if the server you asked for is unavailable.

            • 3. Re: Remote JNDI connects locally
              ezani abdul halim Newbie

              The -b flag is normally used when configuring the server from a remote client.

              You can also use run.sh -b 192.168.5.78 where 192.168.5.78 is the server address (i.e. bind directly to the server's IP from the remote client).

              I faced the same problem and without the -b, Jboss could not be run (this only applies to managing the server from a remote location).