8 Replies Latest reply on Nov 6, 2005 6:42 PM by Chris Dollar

    CannotConnectException JBoss4.0.3

    Rafał Sontowski Newbie

      I have problem with connecting to JBoss instance from standalone Java client.
      I have this problem with JBoss 4.0.3 with JBoss 4.0.3RC2 all goes fine.
      I've prepared some classes to replicate this problem.

      session bean class:

      import javax.ejb.Remote;
      import javax.ejb.Stateless;
      @Stateless
      @Remote(HelloWorldRemote.class)
      public class HelloWorldBean implements HelloWorld{
       public String hello(String msg) {
       return "Hello " + msg + " world!";
       }
      }
      


      interface classes:
      public interface HelloWorld {
       String hello(String msg);
      }
      ...
      import javax.ejb.Remote;
      @Remote
      public interface HelloWorldRemote extends HelloWorld{
      
      }
      


      client class:
      import java.util.Properties;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      
      public class HelloWorldClient implements HelloWorld{
      
       public String hello(String msg) {
       // TODO Auto-generated method stub
       return getDelegate().hello(msg);
       }
      
       private HelloWorld getDelegate() {
       try {
       InitialContext ctx1;
       Properties env = new Properties();
       env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
       "org.jboss.security.jndi.JndiLoginInitialContextFactory");
       env.setProperty(Context.SECURITY_PRINCIPAL, "guest");
       env.setProperty(Context.SECURITY_CREDENTIALS, "q");
       ctx1 = new InitialContext(env);
       return (HelloWorld) ctx1.lookup(HelloWorldRemote.class.getName());
       } catch (Throwable e) {
       e.printStackTrace();
       System.exit(1);
       }
       return null;
      
       }
      
       public static void main(String[] args) {
       HelloWorld hello = new HelloWorldClient();
       System.out.println(hello.hello("JBoss4.0.3"));
       }
      }
      


      I'am using JBoss all configuration prepared to use EJB3
      All deploys fine, but when I run client I have to wait couple of second and I can see following Exception on the server side:
      15:18:35,786 ERROR [ServerThread] failed to process invocation.
      java.net.SocketTimeoutException: Read timed out
       at java.net.SocketInputStream.socketRead0(Native Method)
       at java.net.SocketInputStream.read(SocketInputStream.java:129)
       at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
       at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
       at java.io.BufferedInputStream.read(BufferedInputStream.java:313)
       at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2217)
       at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2230)
       at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2698)
       at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:750)
       at java.io.ObjectInputStream.<init>(ObjectInputStream.java:268)
       at org.jboss.remoting.transport.socket.ServerSocketWrapper.createInputStream(ServerSocketWrapper.java:33)
       at org.jboss.remoting.transport.socket.ClientSocketWrapper.getInputStream(ClientSocketWrapper.java:62)
       at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:239)
       at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:285)
       at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:169)
      

      And after few more soconds on the client:
      Exception in thread "main" org.jboss.remoting.CannotConnectException: Can not get connection to server. Problem establishing socket connection.
       at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:230)
       at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:112)
       at org.jboss.remoting.Client.invoke(Client.java:226)
       at org.jboss.remoting.Client.invoke(Client.java:189)
       at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:41)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:46)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:40)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:41)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:88)
       at $Proxy1.hello(Unknown Source)
       at pl.kapital.HelloWorldClient.hello(HelloWorldClient.java:13)
       at pl.kapital.HelloWorldClient.main(HelloWorldClient.java:37)
      Caused by: java.lang.reflect.InvocationTargetException
       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
       at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
       at org.jboss.remoting.transport.socket.SocketClientInvoker.createClientSocket(SocketClientInvoker.java:452)
       at org.jboss.remoting.transport.socket.SocketClientInvoker.getConnection(SocketClientInvoker.java:431)
       at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:226)
       ... 15 more
      Caused by: java.io.EOFException
       at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2232)
       at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2698)
       at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:750)
       at java.io.ObjectInputStream.<init>(ObjectInputStream.java:268)
       at org.jboss.remoting.loading.ObjectInputStreamWithClassLoader.<init>(ObjectInputStreamWithClassLoader.java:43)
       at org.jboss.remoting.transport.socket.ClientSocketWrapper.createInputStream(ClientSocketWrapper.java:40)
       at org.jboss.remoting.transport.socket.ClientSocketWrapper.<init>(ClientSocketWrapper.java:32)
       ... 22 more
      


      What is wrong with the new JBoss?
      Is that a bug or configuration issue.
      What should I do to get it right?

      Rafal

        • 1. Re: CannotConnectException JBoss4.0.3
          jaikiran pai Master

          What is the java.naming.provider.url property set to.
          Usually this is mentioned in jndi.properties file, under the client classpath.

          Typical jndi.properties file would look like:

          java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
          java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
          java.naming.provider.url=jnp://localhost:1099


          • 2. Re: CannotConnectException JBoss4.0.3
            Rafa&#322; Sontowski Newbie

            I throw away any jndi.properies file.
            I have jndi properties hardcoded in client class.
            I changed InitialContext properties as follows:

             private HelloWorld getDelegate() {
             try {
             InitialContext ctx1;
             Properties env = new Properties();
             env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
             "org.jnp.interfaces.NamingContextFactory");
             env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
             env.setProperty(Context.PROVIDER_URL, "jnp://rsontowski:1099");
             ctx1 = new InitialContext(env);
             return (HelloWorld) ctx1.lookup(HelloWorldRemote.class.getName());
             } catch (Throwable e) {
             e.printStackTrace();
             System.exit(1);
             }
             return null;
             }
            

            but it dosn't work.

            My client tries to connect to the server (Exception i thrown at server side) but is unsuccessful with it.

            I've got this problem with EJB2.1 session beans and JBoss 4.0.3 too.
            :-(



            • 4. Re: CannotConnectException JBoss4.0.3
              Pieter-Jan Malfait Newbie

              i'm experiencing the same problem (Timeout exeception on server, CannotConnectException on client) after moving from 4.0.3RC2 to 4.0.3.
              has anyone found a solution for this ?

              i don't think it has something to do with ports/firewall as everything works fine with 4.0.3RC2

              • 5. Re: CannotConnectException JBoss4.0.3
                Rafa&#322; Sontowski Newbie

                I don't know why, but on JBoss4.0.3SP1 all works fine.

                • 6. Re: CannotConnectException JBoss4.0.3
                  Pieter-Jan Malfait Newbie

                  i just upgraded to jboss 4.0.3SP1 and i still experience the CannotConnectException...

                  my setup is as following :
                  Jboss 4.0.3SP1
                  PostgresSQL 8.3
                  External Java Swing Client

                  error on server :

                  java.net.SocketTimeoutException: Read timed out
                  at java.net.SocketInputStream.socketRead0(Native Method)
                  at java.net.SocketInputStream.read(SocketInputStream.java:129)
                  at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
                  at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
                  at java.io.BufferedInputStream.read(BufferedInputStream.java:313)
                  at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2217)
                  at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2230)
                  at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2698)
                  at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:750)
                  at java.io.ObjectInputStream.(ObjectInputStream.java:268)
                  at org.jboss.remoting.transport.socket.ServerSocketWrapper.createInputStream(ServerSocketWrapper.java:33)
                  at org.jboss.remoting.transport.socket.ClientSocketWrapper.getInputStream(ClientSocketWrapper.java:62)
                  at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:239)
                  at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:285)
                  at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:169)

                  error on client:

                  Exception: org.jboss.remoting.CannotConnectException: Can not get connection to server. Problem establishing socket connection.
                  Exception message: Can not get connection to server. Problem establishing socket connection.
                  Exception cause: java.lang.reflect.InvocationTargetException
                  Exception stacktrace:
                  org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:230)
                  org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:112)
                  org.jboss.remoting.Client.invoke(Client.java:226)
                  org.jboss.remoting.Client.invoke(Client.java:189)
                  org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:41)
                  org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
                  org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:46)
                  org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
                  org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:40)
                  org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
                  org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:41)
                  org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
                  org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:88)
                  $Proxy0.getAllEntities(Unknown Source)
                  be.profitplus.client.businessdelegates.support.SupportBD.getAllEntities(SupportBD.java:59)
                  be.profitplus.client.gui.support.SupportObjectPanel.getAllEntities(SupportObjectPanel.java:459)
                  be.profitplus.client.gui.support.SupportObjectPanel.setContentPanel(SupportObjectPanel.java:204)
                  be.profitplus.client.gui.support.SupportObjectPanel.access$0(SupportObjectPanel.java:186)
                  be.profitplus.client.gui.support.SupportObjectPanel$1.valueChanged(SupportObjectPanel.java:176)
                  javax.swing.JTree.fireValueChanged(JTree.java:2399)
                  javax.swing.JTree$TreeSelectionRedirector.valueChanged(JTree.java:2770)
                  javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(DefaultTreeSelectionModel.java:629)
                  javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(DefaultTreeSelectionModel.java:1078)
                  javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(DefaultTreeSelectionModel.java:287)
                  javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(DefaultTreeSelectionModel.java:170)
                  javax.swing.JTree.setSelectionPath(JTree.java:1174)
                  javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(BasicTreeUI.java:2256)
                  javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection(BasicTreeUI.java:3442)
                  javax.swing.plaf.basic.BasicTreeUI$Handler.mousePressed(BasicTreeUI.java:3403)
                  java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:222)
                  java.awt.Component.processMouseEvent(Component.java:5485)
                  javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
                  java.awt.Component.processEvent(Component.java:5253)
                  java.awt.Container.processEvent(Container.java:1966)
                  java.awt.Component.dispatchEventImpl(Component.java:3955)
                  java.awt.Container.dispatchEventImpl(Container.java:2024)
                  java.awt.Component.dispatchEvent(Component.java:3803)
                  java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
                  java.awt.LightweightDispatcher.processMouseEvent(Container.java:3889)
                  java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
                  java.awt.Container.dispatchEventImpl(Container.java:2010)
                  java.awt.Window.dispatchEventImpl(Window.java:1774)
                  java.awt.Component.dispatchEvent(Component.java:3803)
                  java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
                  java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
                  java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
                  java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
                  java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
                  java.awt.EventDispatchThread.run(EventDispatchThread.java:110)


                  anybody has any idea ?
                  thank you very much in advance
                  everything seems to work find with 4.0.3RC2 though

                  • 7. Re: CannotConnectException JBoss4.0.3
                    Martin Cizek Newbie

                    I experiened the same problem. Please upgrade your jboss-remoting.jar on the client side to the server version.

                    • 8. Re: CannotConnectException JBoss4.0.3
                      Chris Dollar Novice

                      I'm having the same problems with 4.0.3 My client can connect to my ejb3 app fine in 4.0.3RC2 but after upgrading to 4.0.3SP1 and upgrading the jboss-remoting.jar file on the client I still get the same error as phon is on both the client and server side. Any other ideas on what I might be missing?