3 Replies Latest reply on Nov 11, 2004 7:52 AM by darranl

    Rebind() does not work for RMI server over JNDI

    thoste

      When I deploy a simple HelloWorld RMI server object (with the code shown at the bottom
      of this posting) to the deploy directory of JBoss 3.2.6 it is NOT bound successfully.

      Why?

      A Context.list() from a client does not list it and a lookup from a client yields a

      RmiClient exception: myRmiServer not bound
      javax.naming.NameNotFoundException: myRmiServer not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:282)
      ...


      Source:
      package test.rmi:

      import java.rmi.*;
      import java.rmi.server.UnicastRemoteObject;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import java.util.Hashtable;

      public class RmiServerImpl extends UnicastRemoteObject implements RmiServer {
      private String name;

      public RmiServerImpl(String s) throws RemoteException {
      super();
      name = s; }

      public String sayHello() throws RemoteException {
      System.out.println("RmiServer.sayHello()");
      return "Hello World!";
      }

      public static void main(String args[]) {
      try {
      Hashtable hashtable = new Hashtable(3);
      hashtable.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      hashtable.put(Context.PROVIDER_URL, "jnp://localhost:1099");
      hashtable.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      InitialContext ictx = new InitialContext(hashtable);

      RmiServerImpl obj = new RmiServerImpl("myRmiServer");
      //ictx.rebind("jnp://localhost:1099/myRmiServer", obj); //Does not work too
      ictx.rebind("myRmiServer", obj);

      } catch (Exception e) {
      System.out.println("RmiServerImpl err: " + e.getMessage());
      e.printStackTrace(); }
      }
      }