troubleshooting Question

Using RMI registry for the first time, problems with registering chat server.

Avatar of kenkenyon
kenkenyon asked on
Java
2 Comments1 Solution796 ViewsLast Modified:
This is the first time I have used RMI. I am working through some examples I found which act as a chat server and a chat client. The chat client works fine when I use

java  -Djava.security.policy=RMISecurity.policy chat

but if i try java  -Djava.security.policy=RMISecurity.policy RMIChatServerImpl

I get this error:

Failed to register object java.rmi.ServerException: RemoteException occurred in
server thread; nested exception is:
        java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
tion is:
        java.lang.ClassNotFoundException: RMIChatServerImpl_Stub
java.rmi.ServerException: RemoteException occurred in server thread; nested exce
ption is:
        java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
tion is:
        java.lang.ClassNotFoundException: RMIChatServerImpl_Stub
        at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:396
)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
        at sun.rmi.transport.Transport$1.run(Transport.java:159)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:5
35)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTranspor
t.java:790)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
.java:649)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:908)
        at java.lang.Thread.run(Thread.java:619)
        at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
RemoteCall.java:255)
        at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
233)
        at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
        at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
        at java.rmi.Naming.rebind(Naming.java:160)
        at RMIChatServerImpl.main(RMIChatServerImpl.java:172)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested ex
ception is:
        java.lang.ClassNotFoundException: RMIChatServerImpl_Stub
        at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
        at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:386
)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
        at sun.rmi.transport.Transport$1.run(Transport.java:159)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:5
35)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTranspor
t.java:790)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
.java:649)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:908)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: RMIChatServerImpl_Stub
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:434)
        at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)
        at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
        at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
        at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.jav
a:197)
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:157
5)
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
732)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
        ... 12 more

I have included the code for RMIChatServerImpl, which I believe is where the problem is. As I said this is the first time I have used RMI so I would appreciate any help.

Thank you

import java.util.*;
import java.io.*;
import java.net.*;
import java.rmi.*;
import java.rmi.server.*;
 
public class RMIChatServerImpl extends UnicastRemoteObject
    implements RMIChatServer {
 
 /**
  *  The client vector. This holds one entry
  *  for each client that has registered with
  *  the server.
  */
 private Vector myClientVector;
 
 /**
  *  Constructs the chat server
  */
 public RMIChatServerImpl() throws RemoteException {
 
  // simply instantiate the Vector
  myClientVector = new Vector();
 
 }
 
 /**
  *  Allows the registration of a chat client
  */
 public void connect(RMIChatClient theClient) throws RemoteException {
 
 
  // store the reference
  myClientVector.addElement(theClient);
 
  System.out.println("Bound Client: " + theClient);
 
 }
 
 /**
  *  Allows the sending of a message
  */
 public void sendMessageToServer( String theMessage)
   throws RemoteException {
 
  RMIChatClient tempClient;
 
  // build the message to send
  String outputMessage = "Message received : " + theMessage;
  System.out.println("Sending: " + outputMessage);
 
  // get an iterator for the vector
  Iterator it = myClientVector.iterator();
 
  // iterate over the entries
  while (it.hasNext()){
 
   // send the message
   tempClient = (RMIChatClient)it.next();
   try {
    tempClient.dispatchMessage( outputMessage);
   }
   catch (RemoteException re) {
    // failed to send to client, log it and carry on
    // most likely reason is that client has
    // gone away but we do not know about it
    System.out.println("Failed to send to: " + tempClient + " reason: " + re);
   }
  }
 
 }
 
 public static void main (String[] args){
 
  try{
   /* To Do: #4.
     ********************************************
     * Create an instance of the Remote Object
     ********************************************
     * You will need to:
     *  - Create an instance of the
     *    RMIChatServerImpl class.
     *  - Instantiate and install an
     *    RMISecuritymanager
     *
    *********************************************
    */
 
    RMIChatServer myObject = new RMIChatServerImpl();
 
    // create an RMI security manager and register it with
    // the system
    System.setSecurityManager(new RMISecurityManager());
 
 
    Naming.rebind("RMIChatServer42", myObject);
 
    System.out.println("Remote object bound to registry");
  }
  catch( Exception e){
 
   System.out.println("Failed to register object " + e);
   e.printStackTrace();
   System.exit(1);
 
  }
 
 }
 
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros