views:

311

answers:

3

Hi Friends, 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  A: 

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.

jarnbjo
A: 

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.

Dan
A: 

Thanks for your reply. Actual that was a mistake from my side. The client code is like this:

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.getOrder(orderObject);
  }
  catch(Exception e){
         e.printStackTrace(); 
  }
  }
 }

I have solved the problem.

I have set the classpath environment variable to the root directory of Order class.

Now I am able to call the remote method from local host.

But I am getting other exception, when trying to execute the remote method from different computer.

One computer is running as the server (eg: server ip is 192.168.1.108). My client code is exactly like this:

public class TestClientProgram {
public static void main(String[] args)  {
try{
java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry.getRegistry("192.168.1.108", 1234); //
ServerInterface service = (ServerInterface) registry.lookup("ServerImplementation");
Order orderObject=new Order(12,"DISH");
service.getOrder(orderObject);
}
catch(NotBoundException e){
System.out.println("NotBoundException");
e.printStackTrace();
}
catch(RemoteException e){
System.out.println("RemoteException");
 e.printStackTrace();
}
}  
}

The exception I am getting is:

java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is: 
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)

I don't know, why this error occurs. I am able to ping the two computers and checked the port in the server and it is all working. The two computers are running in Ubuntu. But my confusion is why the above exception points to the ip 127.0.1.1 even though I am connecting to the ip 192.168.1.108 (ip of server).

Any Ideas ?

Thanks In Advance

Renjith M