10 Replies Latest reply on Apr 17, 2003 5:57 AM by pinky

    JNDI problem

    quantic

      Hi,

      I am developing a Java application runs on Win2K and this application uses JNDI to look up and work with an EJB component on a Linux server (with JBoss 2.1 installed). When called, the EJB component will open a connection with PostgreSQL database (installed on same Linux server) to do some SQL operations.

      If the Linux server (Linux 7.0, JBoss 2.1) is installed with DHCP/DNS configuration, then the Java client application running on Win2K successfully lookups and calls to the EJB on the server. (In this case, I set the context url in jndi.properties as "jnp://<linux server name>:1099)

      If the Linux server (Linux 7.0, JBoss 2.1) is installed WITHOUT DHCP/DNS configuration (i.e. I specify fixed IP address), then the Java client application running on Win2K fails at the context.lookup("xxx") command. (In this case, I set the context url in jndi.properties as "jnp://<linux server address>:1099). The error shows something wrong with rmi (socket connect refused). Of course, I can ping the Linux server address successfully.

      Do you know why the client app fails to lookup EJB when Linux server is not configured with DHCP/DNS support? And how can I resolve this problem? (I am in very urgent to fix it, so please reply...)

      Thank you very much,
      Huy Dao

        • 1. Re: JNDI problem
          cxtinac

          Hi -- Did you ever get a reply to this post? This sounds rather like the problem we are having. (RH 7.1 static IP JBoss server, Win 98 DHCP client fails to connect with a Connection Refused error)...

          • 2. Re: JNDI problem
            bezdicek

            Hi,

            you have to put the hostname in your hosts file something like this:

            127.0.0.1 localhost
            192.168.0.1 myServerName, anotherName

            hope it helps (solved my problem :) )

            tom

            • 3. Re: JNDI problem
              aepshteyn

              > Hi,
              >
              > I am developing a Java application runs on Win2K and
              > this application uses JNDI to look up and work with
              > an EJB component on a Linux server (with JBoss 2.1
              > installed). When called, the EJB component will open
              > a connection with PostgreSQL database (installed on
              > same Linux server) to do some SQL operations.
              >
              > If the Linux server (Linux 7.0, JBoss 2.1) is
              > installed with DHCP/DNS configuration, then the Java
              > client application running on Win2K successfully
              > lookups and calls to the EJB on the server. (In this
              > case, I set the context url in jndi.properties as
              > "jnp://<linux server name>:1099)
              >
              > If the Linux server (Linux 7.0, JBoss 2.1) is
              > installed WITHOUT DHCP/DNS configuration (i.e. I
              > specify fixed IP address), then the Java client
              > application running on Win2K fails at the
              > context.lookup("xxx") command. (In this case, I set
              > the context url in jndi.properties as "jnp:// server address>:1099). The error shows something
              > wrong with rmi (socket connect refused). Of course, I
              > can ping the Linux server address successfully.
              >
              > Do you know why the client app fails to lookup EJB
              > when Linux server is not configured with DHCP/DNS
              > support? And how can I resolve this problem? (I am in
              > very urgent to fix it, so please reply...)
              >
              > Thank you very much,
              > Huy Dao


              I ran into a very similar problem. Did anyone figured it out?

              Thanks,
              Alex

              • 4. Re: JNDI problem

                Look at the previous post.

                If you are not using a DNS you either need to
                specify the IP address or put the host name in the
                host table.

                Regards,
                Adrian

                • 5. Re: JNDI problem
                  aepshteyn

                  I do have an IP address and port specified for java.naming.provider.url in the jndi.properties, so it must be something else.

                  By the way, when I telnet to 1099 on the JBoss machine, i get back this:

                  ¬ísrjava.rmi.MarshalledObject|½—ícü>IhashlocBytest[BobjBytesq~xp˜ÆÍ®ur[B¬óTàxp#¬íthttp://iliag:8083/q~q~uq~À¬ísr org.jnp.server.NamingServer_Stubxrjava.rmi.server.RemoteStubéþÜÉ‹áexrjava.rmi.server.RemoteObjectÓa´‘
                  a3xpw4
                  UnicastRef2 127.0.0.1ëUF‘â€xConnection closed by foreign host.
                  [alex@iliag alex]$

                  Perhaps I am dreaming and guessing, but does the stub contain localhost reference (notice 127.0.0.1)

                  Any ideas?

                  Thanks,
                  Alex

                  • 6. Re: JNDI problem

                    On the client you should have something like
                    jnp://xxx.xxx.xxx.xxx:1099

                    See
                    http://www.jboss.org/online-manual/HTML/ch05s10.html

                    Don't set this property on the server!

                    Regards,
                    Adrian

                    • 7. Re: JNDI problem
                      aepshteyn

                      I do have it setup like that, it is clearly something else.

                      This is the output of building and running InterestClient, with added code to print environment, and actual address changed to xxx.xxx.xxx.xxx :

                      C:\jboss-examples\build>ant intro-interest-client
                      Buildfile: build.xml

                      validate-servlet:

                      validate-jboss:

                      fail_if_not_valid:

                      init:
                      [echo] Using JBoss directory=c:\jboss-3.0.0alpha
                      [echo] Using base classpath=C:\jboss-3.0.0alpha\client\jboss-j2ee.jar;C:\jb
                      oss-3.0.0alpha\client\jaas.jar;C:\jboss-3.0.0alpha\client\jbosssx-client.jar;C:\
                      jboss-3.0.0alpha\client\jboss-client.jar;C:\jboss-3.0.0alpha\client\jnp-client.j
                      ar;C:\jboss-examples\COULD_NOT_FIND_SERVLET_JAR
                      [echo] Using Source directory=C:\jboss-examples
                      [echo] Using Build directory=C:\jboss-examples/build-examples

                      intro-interest-client:

                      compile:

                      interest-client:
                      [java] Got context
                      [java] {java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                      , java.naming.provider.url=xxx.xxx.xxx.xxx:1099, java.naming.factory.url.pkgs=org.
                      jboss.naming:org.jnp.interfaces}
                      [java] javax.naming.CommunicationException [Root exception is java.rmi.Conn
                      ectException: Connection refused to host: 127.0.0.1; nested exception is:
                      [java] java.net.ConnectException: Connection refused: no further inform
                      ation]

                      BUILD SUCCESSFUL

                      Total time: 5 seconds

                      • 8. Re: JNDI problem

                        There's something strange going on with your
                        rmi/hosts/ip configuration.

                        Even when I "telnet 127.0.0.1 1099" I see the remote
                        ip address. First time I ever tried that ;-)

                        I've searched the rmi faq, the rmi spec, google,
                        and a quick scan on the java developer connection.
                        I can't find anything similar, but that assumes
                        search engines work :-)

                        You could try adding -Djava.rmi.server.hostname to
                        in run.bat, this will force rmi to use host names
                        rather than ip addresses. But you will need a DNS
                        or configure the hosts names on each machine.

                        This is very strange, I've never seen it before.

                        I can tell you are running windows, but perhaps you
                        can give some other relevant configuration, e.g.
                        JBoss version, JDK version, what is the server
                        running, etc.

                        Regards,
                        Adrian

                        • 9. Re: JNDI problem
                          aepshteyn

                          > There's something strange going on with your
                          > rmi/hosts/ip configuration.
                          >

                          Yep, problem solved, but first my configuration:

                          Client is on windows98, connecting to JBoss on Linux (RH 6.2), with hostname iliag, both machines with JBoss 3.0 alpha.

                          The problem was related to the /etc/hosts on linux machine, which looked like this:

                          127.0.0.1 localhost.localdomain localhost iliag
                          xxx.xxx.xxx.xxx iliag

                          The first line resulted in 127.0.0.1 included in the reference to the Naming Service, which client had hard time using :-).

                          Looks like there are (at least) two ways to deal with the problem(tested both):

                          1) remove iliag from the first line of /etc/hosts

                          127.0.0.1 localhost.localdomain localhost
                          xxx.xxx.xxx.xxx iliag

                          In this case a correct address will be returned in the reference, as you can see in telnet to 1099, with real address changed to xxx for secrecy :-)

                          ¬ísrjava.rmi.MarshalledObject|½—ícü>IhashlocBytest[BobjBytesq~xp,š2>ur[B¬óTàxpt¬ítSfile:/home/alex/jboss-3.0.0alpha/tmp/deploy/ServiceDeployer/deploy.17/jnpserver.jarthttp://iliag:8083/q~uq~Ĭísr org.jnp.server.NamingServer_Stubxrjava.rmi.server.RemoteStubéþÜÉ‹áexrjava.rmi.server.RemoteObjectÓa´‘
                          a3xpw8
                          xxx.xxx.x.xxx?É:ëY¬Uõ€x UnicastRef2

                          2) As per Adrian's suggestion add in run.sh

                          -Djava.rmi.server.hostname=iliag

                          In this case hostname is returned

                          ¬ísrjava.rmi.MarshalledObject|½—ícü>IhashlocBytest[BobjBytesq~xp³G(ur[B¬óTàxpt¬ítSfile:/home/alex/jboss-3.0.0alpha/tmp/deploy/ServiceDeployer/deploy.17/jnpserver.jarthttp://iliag:8083/q~uq~¼¬ísr org.jnp.server.NamingServer_Stubxrjava.rmi.server.RemoteStubéþÜÉ‹áexrjava.rmi.server.RemoteObjectÓa´‘
                          a3xpw0
                          UnicastRef2iliagN[ëYŠ¸€x

                          and everything works just fine. I think this is the right way, and wonder why returning full domain name is not a default behaviour in RMI.
                          Looks like it is a default for codebase(http://iliag:8083) which is always returned as a name.

                          Adrian, thanks a lot for your help!

                          Cheers,
                          Alex

                          • 10. Re: JNDI problem
                            pinky

                            Hi,
                            I have the same setup. when i am doing the following i am getting NullPointerException, the lookup is getting failed. This is happening on linux machine only.
                            -------------------------------------------------------------------
                            Properties prop = new Properties();
                            prop.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.Nam
                            ingContextFactory");
                            prop.put(Context.PROVIDER_URL,"jnp://192.168.175.42:1099");
                            prop.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.inte
                            rfaces");
                            ctx = new InitialContext(prop);
                            System.out.println("OBJECT---" + ctx);
                            //ctx = new InitialContext();
                            ds =(DataSource)ctx.lookup(java:/MSSQL);
                            -----------------------------------------------------------------

                            can u please help me. i am really facing this problem from past 1 week.

                            rgds
                            -kaladhar