0 Replies Latest reply on Jun 30, 2007 1:28 AM by Dinny Chung

    Fail to lookup EJB3 as JBoss return internal IP

    Dinny Chung Newbie

      Hi,

      I wrote a HelloWorld EJB 3 and HelloClient to test remote access JBoss server, but failed as IP changed by firewall.

      The server is linux and using JBoss 4.0.4.GA with jdk1.5.0_09.

      I tried to start JBoss with "run.sh -c default -b <external IP>" , jboss cannot start with error :

      2007-06-30 21:16:12,840 ERROR [org.jboss.remoting.transport.socket.SocketServerInvoker] Error starting ServerSocket. Bind port: 3873, bind address: /202.155.230.102
      2007-06-30 21:16:12,841 ERROR [org.jboss.remoting.transport.Connector] Error starting connector.
      java.net.BindException: Cannot assign requested address
      at java.net.PlainSocketImpl.socketBind(Native Method)
      at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
      at java.net.ServerSocket.bind(ServerSocket.java:319)
      at java.net.ServerSocket.<init>(ServerSocket.java:185)
      at javax.net.DefaultServerSocketFactory.createServerSocket(ServerSocketFactory.java:169)
      at org.jboss.remoting.transport.socket.SocketServerInvoker.createServerSocket(SocketServerInvoker.java:186)
      at org.jboss.remoting.transport.socket.SocketServerInvoker.start(SocketServerInvoker.java:136)
      at org.jboss.remoting.transport.Connector.start(Connector.java:316)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
      at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:995)
      at $Proxy0.start(Unknown Source)
      at org.jboss.system.ServiceController.start(ServiceController.java:417)
      at org.jboss.system.ServiceController.start(ServiceController.java:435)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
      at $Proxy4.start(Unknown Source)
      at org.jboss.deployment.SARDeployer.start(SARDeployer.java:302)
      at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1007)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:808)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:771)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)


      then tried to start JBoss with "run.sh -c default -b <internal IP>" , then got below error

      javax.naming.CommunicationException [Root exception is java.rmi.ConnectException: Connection refused to host: <internal IP>; nested exception is:
      java.net.ConnectException: Connection timed out: connect]


      EJB Source Code
      // HelloWorldBean.java
      package hi;
      
      import javax.ejb.Stateless;
      
      @Stateless(name="HelloWorld")
      public class HelloWorldBean implements HelloWorldRemote {
      
       public String sayHi (){
       System.out.println("sayHi");
       return "Hello world!";
       }
      
      }
      // HelloWorldRemote.java
      package hi;
      
      import javax.ejb.Remote;
      
      @Remote
      public interface HelloWorldRemote {
       public String sayHi ();
      }
      



      Client Source code
      // main.java
      package helloclient;
      import hi.HelloWorldRemote;
      import java.sql.SQLException;
      
      public class Main {
       private static HelloWorldRemote helloRemote;
       public Main() {
       }
       public static void main(String[] args) throws SQLException {
       if( args.length > 0 )
       MyContext.setUrl(args[0]);
       try {
       helloRemote = (HelloWorldRemote) MyContext.lookup("HelloWorld/remote");
       System.out.println(helloRemote.sayHi());
       } catch( Exception e ) {
       System.out.println(e);
       }
       System.exit(0);
      
       }
      
      }
      
      // MyContext.java
      package helloclient;
      
      import java.util.Properties;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      public class MyContext
      {
       private static String url = "localhost:1099";
       private static Context context;
       private static MyContext uniqueInstance;
      
       private MyContext() throws NamingException {
       Properties props = new Properties();
       props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
       props.setProperty("java.naming.provider.url", new String("jnp://" + getUrl()));
       props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
       context = new InitialContext(props);
       }
      
       public static Object lookup( String ejbName ) throws NamingException {
       if( uniqueInstance == null )
       uniqueInstance = new MyContext();
       System.out.println("getUrl " +getUrl());
       System.out.println("ejbName " + ejbName);
       System.out.println(context.toString());
      
       return context.lookup( ejbName);
       }
      
       public static MyContext getInstance() throws NamingException {
       if( uniqueInstance == null )
       uniqueInstance = new MyContext();
       return uniqueInstance;
       }
      
       public static String getUrl() {
       return url;
       }
      
       public static void setUrl(String aUrl) {
       url = aUrl;
       }
      
      }
      
      
      



      Please help