4 Replies Latest reply on Apr 23, 2007 11:55 AM by Sharath Komarla

    Remoting problem

    Sharath Komarla Newbie

      I deployed an slsb from the EJB3Trail samples. I can access the EJB via local lookup, but can't seem to do so using a remote lookup. when accessed remotely, I get the following exception.

      EJBClient start
      Exception in thread "main" org.jboss.remoting.CannotConnectException: Can not get connection to server. Problem establishing socket connection for InvokerLocator [socket://localhost:3873/]
      at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:525)
      at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:122)
      at org.jboss.remoting.Client.invoke(Client.java:1544)
      at org.jboss.remoting.Client.invoke(Client.java:530)
      at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:62)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.aspects.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:48)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:61)
      at $Proxy0.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:628)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:590)
      at javax.naming.InitialContext.lookup(InitialContext.java:351)
      at test.EJBClient.main(EJBClient.java:28)
      Caused by: java.net.ConnectException: Connection refused: connect
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:364)
      at java.net.Socket.connect(Socket.java:507)
      at org.jboss.remoting.transport.socket.SocketClientInvoker.createSocket(SocketClientInvoker.java:187)
      at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.getConnection(MicroSocketClientInvoker.java:796)
      at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:521)
      at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:122)
      at org.jboss.remoting.Client.invoke(Client.java:1544)
      at org.jboss.remoting.Client.invoke(Client.java:530)
      at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:62)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.aspects.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:48)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:61)
      at $Proxy0.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:628)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:590)
      at javax.naming.InitialContext.lookup(InitialContext.java:351)
      at test.EJBClient.main(EJBClient.java:28)
      at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:74)
      ... 9 more


      Client code is pretty straight forward:
      package test;

      import java.util.Properties;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;

      import trail.RemoteCalculator;

      public class EJBClient
      {
      /**
      * @param args
      */
      public static void main(String[] args)
      {
      System.out.println("EJBClient start");

      Properties properties = new Properties();

      properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.JBossRemotingContextFactory");
      properties.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      properties.setProperty(Context.PROVIDER_URL, "socket://localhost:3873");

      try
      {
      Context ctx = new InitialContext(properties);
      RemoteCalculator cal = (RemoteCalculator)ctx.lookup("EJB3Trail/RemoteCalculator");

      String serverInfo = cal.getServerInfo();

      System.out.println("got server info: " + serverInfo);
      }
      catch (NamingException e)
      {
      e.printStackTrace();
      System.exit(-1);
      }
      System.out.println("exiting");
      }
      }


      Server code:
      ....
      public static void main(String[] args)
      {
      try
      {
      Bootstrap.getInstance().bootstrap();

      AssembledDirectory jar = AssembledContextFactory.getInstance().create("calc.jar");
      jar.addClass(Calculator.class);
      jar.addClass(LocalRemoteCalculator.class);
      jar.addClass(RemoteCalculator.class);
      jar.addClass(StatelessCalculator.class);

      Bootstrap.getInstance().deploy(jar);
      }
      catch (DeploymentException e1)
      {
      e1.printStackTrace();
      System.exit(1);
      }

      // attempt a local lookup
      Context ctx;
      try
      {
      ctx = new InitialContext();
      Calculator cal = (Calculator)ctx.lookup("EJB3Trail/LocalCalculator");

      double val = cal.calculate(10,20,10,10);

      System.out.println("got calculated value: " + val);


      }
      catch (NamingException e1)
      {
      e1.printStackTrace();
      System.exit(1);
      }

      // wait for remote invocations..
      ....

        • 1. Re: Remoting problem
          Rustam Bogubaev Newbie

          does your remote machine accepts connections through 3873 port? firewall issue? can you establish connection using telnet to localhost:3873?

          in my projects I use :

          java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
          java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
          


          and in remote client :

          Context ctx = new InitialContext(properties);
          RemoteCalculator cal = (RemoteCalculator)ctx.lookup("EJB3Trail/RemoteCalculator/remote");
          


          --
          rustam bogubaev

          • 2. Re: Remoting problem
            Sharath Komarla Newbie

            Thanks for the reply:

            "pyctam" wrote:
            does your remote machine accepts connections through 3873 port? firewall issue? can you establish connection using telnet to localhost:3873?


            Both server and client are on the same machine. The server machine is setup with the following in remoting-service.xml

            <server>
             <mbean code="org.jboss.remoting.transport.Connector"
             name="jboss.remoting:type=Connector,name=DefaultEjb3Connector,handler=ejb3">
             <attribute name="InvokerLocator">socket://${jboss.bind.address}:3873</attribute>
             <attribute name="Configuration">
             <handlers>
             <handler subsystem="AOP">org.jboss.aspects.remoting.AOPRemotingInvocationHandler</handler>
             </handlers>
             </attribute>
             </mbean>
            </server>
            


            so 3873 should be accepting connections. telneting to port 3873 on the same machine does not connect. my server app also binds to other ports and telnet to those does indeed connect.

            I don't have a firewall running on the machine and since I can bind and connect to other ports of my server, I don't believe that I have security policy issues.

            "pyctam" wrote:

            in my projects I use :

            java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
            java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
            


            and in remote client :

            Context ctx = new InitialContext(properties);
            RemoteCalculator cal = (RemoteCalculator)ctx.lookup("EJB3Trail/RemoteCalculator/remote");
            



            What does your remoting-service.xml look like that allows remote lookup of the EJB and what is in the properties object that you are passing into the InitialContext ctor?

            Thanks

            • 3. Re: Remoting problem
              Sharath Komarla Newbie

              I have tried this on both windows and solaris (solaris 10) and have the same problem on both platforms.

              • 4. Re: Remoting problem
                Sharath Komarla Newbie

                ahh.. got it.

                damn what a silly error.

                you need

                java.naming.provider.url=socket://localhost:3873

                in both the server's jndi.properties AND the client's jndi settings. I was only putting this in the client's version.

                The Embedded JBoss distro should come this way. The wiki page for Embedded and Remoting does state the above, but I misread it. I don't see any harm with the distro coming this way out of the box.

                Thanks for your help.