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

4

8

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

Contamination answered 22/12, 2009 at 14:52 Comment(1)
Have you started rmiregistry ?Woorali
T
6

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.

Thorax answered 22/12, 2009 at 15:5 Comment(1)
What's misleading about the message? It says 'method not supported by remote object', which is exactly what you're describing here.Ilowell
B
4

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.

Bueschel answered 22/12, 2009 at 15:39 Comment(0)
P
0

In ServerInterface you should replace getOrder with getOrderFromCash.

Padding answered 5/9, 2019 at 20:47 Comment(0)
B
-1

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 :)

Bobbibobbie answered 24/3, 2015 at 12:18 Comment(1)
There is no such thing as Server interface and Client interface in RMI. There is one remote interface. It must be the same, by which I mean bitwise identical, at the server and the client.Ilowell

© 2022 - 2024 — McMap. All rights reserved.