Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object

I am new to RMI technology.

When I am running the rmi client program, I am getting the exception : java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object. I am using jdk1.5

The argument of the remote method is the Serialized object.

These are the server code...

This is the Remote Interface

package interfacepackage;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface ServerInterface extends Remote{

     public void getOrder(Order order) throws RemoteException;
}

This is the server implementation class

public class ServerImplementation implements ServerInterface {
    public ServerImplementation() throws RemoteException {
    }

    public void getOrderFromCash(Order order) throws RemoteException {
        System.out.println("WORKED");
    }
public static void main(String[] args) 

        try {
            java.rmi.registry.LocateRegistry.createRegistry(1234);
            ServerImplementation service = new ServerImplementation();
            ServerInterface myRemoteObject = (ServerInterface) UnicastRemoteObject
                    .exportObject(service, 0);
            java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry
                    .getRegistry("localhost", 1234);
            registry.rebind("ServerImplementation", myRemoteObject);


        } catch (Exception ex) {
            ex.printStackTrace();

        }
    }
}

This is the class Order

public class Order implements Serializable{
private static final long serialVersionUID = 1L;
private int id;
private String name;
public Order(int id,String name){
    this.id=id;
    this.name=name;
}
}

I have the same Interface and Order class in Client also.

This is the client code

public class TestClientProgram {

    public static void main(String[] args)  {
        try{
         java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry.getRegistry("localhost",1234);
         ServerInterface service=(ServerInterface) registry.lookup("ServerImplementation");
         Order orderObject=new Order(1,"dish");
         service.getOrderFromCash(orderObject);
        }
        catch(Exception e){
            e.printStackTrace();    
        }
        }
    }

Could any one help me to how can I fix the problem ?

Thanks In Advance Renjith M

like image 848
user236919 Avatar asked Dec 22 '09 14:12

user236919


2 Answers

The exception indicates that the server is not able to find the method, which is invoked by the client (the error message is slightly misleading). One possible reason may be that the server and client are running with different classpaths and that the code has been modified enough for the RMI interfaces to be incompatible.

like image 148
jarnbjo Avatar answered Sep 23 '22 11:09

jarnbjo


Something's wrong here. Your ServerInterface has a getOrder method but the implementation has getOrderFromCash. I would check to make sure all the code is compiled and executed with the same versions of that interface.

like image 40
Dan Avatar answered Sep 21 '22 11:09

Dan