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

青春壹個敷衍的年華 提交于 2019-11-28 03:45:33

问题


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


回答1:


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.




回答2:


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.




回答3:


In ServerInterface you should replace getOrder with getOrderFromCash.




回答4:


Well it's a late answer but it may help the new users.

I am using RMI (Client and Server) I got the same error and everything was correct, but what I missed is to define the function in the server's interface, while it was defined in the Client interface !!

I hope this answer will help u :)



来源:https://stackoverflow.com/questions/1946841/getting-java-rmi-unmarshalexception-unrecognized-method-hash-method-not-suppor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!