11 Replies Latest reply on Oct 11, 2006 2:36 AM by Yong Kiat Ng

    Getting JNDI context fails

    Kai Hackemesser Newbie

      Hello,

      I have a problem connecting my EJB3 client app to a JBoss server. In my development I had no problems connecting the server, as long as it was on the same machine with my client. Recently I switched to a remote JBoss server and since then I can't get my client working. Each time I try to connect I get an exception (client side) telling me that it can't connect to 127.0.0.2 (RMISocketException or such, haven't the stack trace with me.) The server is standalone, just the latest 4.0.4 EJB3-default installation. My app is deployed without problems. Firewall is disabled. If I shut down the server the exception is another, so it looks like something in the RMI handshake is failing. My jndi.properties file looks like a typical example just the server name replaced.

      Any suggestions?

      Kai

        • 1. Re: Getting JNDI context fails
          Peter Johnson Master

          It would help if you posted the exact error message. The IP address 127.0.0.1 is for localhost, I am not familiar with 127.0.0.2. In your client, what is java.naming.provider.url set to?

          • 2. Re: Getting JNDI context fails
            Kai Hackemesser Newbie

            Ok, here comes the stack trace:

            07.09.2006 19:55:19 de.hackemesser.frieshouse.client.Manager getContext
            INFO: Creating jndi context
            javax.naming.CommunicationException [Root exception is java.rmi.ConnectException: Connection refused to host: 127.0.0.2; nested exception is:
             java.net.ConnectException: Connection refused: connect]
             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:722)
             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
             at javax.naming.InitialContext.lookup(Unknown Source)
             at de.hackemesser.frieshouse.client.Manager.getCore(Manager.java:41)
             at de.hackemesser.frieshouse.client.ManagerView.getStocklevel(ManagerView.java:420)
             at de.hackemesser.frieshouse.client.ManagerView.getStockLevelDisplay(ManagerView.java:154)
             at de.hackemesser.frieshouse.client.ManagerView.getMenu(ManagerView.java:144)
             at de.hackemesser.frieshouse.client.ManagerView.initialize(ManagerView.java:117)
             at de.hackemesser.frieshouse.client.ManagerView.<init>(ManagerView.java:106)
             at de.hackemesser.frieshouse.client.Manager.main(Manager.java:20)
            Caused by: java.rmi.ConnectException: Connection refused to host: 127.0.0.2; nested exception is:
             java.net.ConnectException: Connection refused: connect
             at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
             at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
             at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
             at sun.rmi.server.UnicastRef.invoke(Unknown Source)
             at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
             ... 9 more
            Caused by: java.net.ConnectException: Connection refused: connect
             at java.net.PlainSocketImpl.socketConnect(Native Method)
             at java.net.PlainSocketImpl.doConnect(Unknown Source)
             at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
             at java.net.PlainSocketImpl.connect(Unknown Source)
             at java.net.SocksSocketImpl.connect(Unknown Source)
             at java.net.Socket.connect(Unknown Source)
             at java.net.Socket.connect(Unknown Source)
             at java.net.Socket.<init>(Unknown Source)
             at java.net.Socket.<init>(Unknown Source)
             at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
             at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
             ... 15 more



            Here comes the jndi.properties (client side)
            # jndi.properties
            
            java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
            # java.naming.provider.url=localhost
            java.naming.provider.url=jnp\://192.168.0.2\:1099
            java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
            


            this is how I create my context in Manager.class:
            if (ctx == null) {
             log.info("Creating jndi context");
             ctx = new InitialContext();
             }


            and this is my first lookup which fails:
            core = (CoreServiceRemote) getContext().lookup(
             "CoreService/remote");


            Any idea?

            Thanks,
            Kai

            • 3. Re: Getting JNDI context fails
              Peter Johnson Master

              Is 192.168.0.2 the IP address of the host running JBoss? What is the IP address of the client machine? Also, which operatin system are you using?

              I tried pinging 127.0.0.2 and 127.0.0.3 and in both cases ping converted the address to 127.0.0.1. Which leads me to assume that 192.168.0.2 is the IP address of your client machine.

              • 4. Re: Getting JNDI context fails
                Kai Hackemesser Newbie

                Ok, but why and what is connecting to my machine at 127.0.0.2? When I shut down the server or change the IP address in properties I get connection timeout exception. This strange exception comes only if the connection is beeing established.

                • 5. Re: Getting JNDI context fails
                  Peter Johnson Master

                  Still waiting for the answer to my three questions...

                  • 6. Re: Getting JNDI context fails
                    Kai Hackemesser Newbie

                    The IP address of the server is 192.168.0.2. OS is Suse Linux 10.0.
                    The IP adress of my test client is 192.168.0.9. OS is Win XP SP2 .

                    • 7. Re: Getting JNDI context fails
                      Peter Johnson Master

                      Run telnet as follows from your Windows PC:

                      telnet 192.168.0.2 1099

                      The last line of the response should contain the text UnicastRef2 followed by an IP address. Which IP address shows? Here is my last line when I telnet to my Fedora Core 5 system that is running JBoss:

                      UnicastRef2192.59.193.104

                      What are the contents of your /etc/hosts file on the server? Do you have a line that has the IP address of the server? In my /etc/hosts files I have the following line:

                      192.59.193.104 usmv-johnsop1l

                      If I recall correctly (it has been many months since I worked around a similar issue), without this line the telnet response has 127.0.01 as the IP address and this tends to confuse clients.

                      • 8. Re: Getting JNDI context fails
                        Kai Hackemesser Newbie

                        Hi,

                        I found that Suse somewhy adds a line to /etc/hosts setting the server ip as 127.0.0.2. I can't think what for this entry should be good, but after I replaced it with the real IP adress everything started workling :-)

                        Thank you for you help!

                        • 9. Re: Getting JNDI context fails
                          Peter Johnson Master

                          Now you know why I asked for the operating system, I recalled this issue with Linux but didn't want to point you to the /etc/hosts file if you were running Windows only. Glad you are up and running.

                          If I am ever in Stuttgard, you owe me a beer, you sly fox. ;-)

                          • 10. Re: Getting JNDI context fails
                            Kai Hackemesser Newbie

                            Of course :-) But hurry, I am planning to immigrate to New Zealand in the next year :-)

                            • 11. Re: Getting JNDI context fails
                              Yong Kiat Ng Newbie

                              thanks, it solved my problem too!