0

I'm working on Java RMI application.

For client using java 7 runs everything correctly.

But for client using java 1.4.2.

The server runs on Windows XP with java 7.

Service Interface:

package rmiserver;
import java.rmi.*;

public interface ServiceInterface extends Remote {

    public static final int port=1099; 
    public String getString(Integer n) throws RemoteException;

}

Service Implementation:

package rmiserver;
import java.rmi.*;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;



public class ServiceImplementation extends UnicastRemoteObject implements ServiceInterface{


    public ServiceImplementation() throws RemoteException {
        try {
        } catch (Exception e) {
            System.out.println("Error:" + e.toString());
        }
    }

    public String getString(Integer n) throws RemoteException {        
        return n.toString();        
    }

    public static void main(String[] args) { // Por ej. en el main del servidor RMI
        int port = ServiceInterface.port;
        System.setSecurityManager(new RMISecurityManager());
        try {
            java.rmi.registry.LocateRegistry.createRegistry(port);
        } catch (Exception e) {
            System.out.println(e.toString() + "Rmiregistry OK.");
        }
        try {
            ServiceImplementation service = new ServiceImplementation();
            String machine = "//192.168.1.3" + ":" + port;
            String name_service = "/serviceString";
            String serviceRemoto = machine + name_service;
            Naming.rebind(serviceRemoto, service);
            System.out.println("....OK.....");
        } catch (Exception e) {
            System.out.println("Error: " + e.toString());
        }
    }


}

Client:

package rmiclient;

import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import rmiserver.ServiceInterface;

public class RMIClient {


    public static void main(String[] args) {
        try {
            ServiceInterface service;
            String name_service = "/serviceString";
            System.setSecurityManager(new RMISecurityManager());
            int port = ServiceInterface.port;
            String machine = "192.168.1.3";
            service = (ServiceInterface) Naming.lookup("rmi://" + machine + ":" +port + name_service);
            System.out.println("OUTPUT: "+service.getString(new Integer(23)));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

On the client and on the server I have the following java.policy:

grant {
permission java.security.AllPermission;
};

On the server side I have the "Service" folder, under this I have:

  1. RmiServer.jar
  2. java.policy
  3. RmiServer.bat (I run the service with this)

RmiServer.bat:

java -classpath RmiServer.jar -Djava.rmi.server.codebase=file:RmiServer.jar -Djava.security.policy=java.policy -jar RmiServer.jar

On the client side I have the "Client" folder, under this I have:

  1. RMIClient.jar
  2. java.policy
  3. stub_folder/rmiserver/ (It is a folder containing the ServiceImplementation_Stub.class)
  4. lib/ (It is a folder containing the RmiServer.jar)
  5. RMIClient.bat (I run the client with this)

RMIClient.bat:

java -classpath lib -Djava.rmi.server.codebase=file:lib -Djava.security.policy=java.policy -jar RMIClient.jar 

I generated the stub as follows:

rmic -classpath RmiServer.jar -d stub_folder rmiserver.ServiceImplementation

I have the following error to run the client in java 1.4.2 :

java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
        java.lang.ClassNotFoundException: java.rmi.server.RemoteObjectInvocation
Handler
        at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
        at java.rmi.Naming.lookup(Unknown Source)
        at rmiclient.RMIClient.main(RMIClient.java:17)
Caused by: java.lang.ClassNotFoundException: java.rmi.server.RemoteObjectInvocat
ionHandler
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
        at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
        at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
        at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
        at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
        at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
        at java.io.ObjectInputStream.readClassDesc(Unknown Source)
        at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
        at java.io.ObjectInputStream.readObject0(Unknown Source)
        at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
        at java.io.ObjectInputStream.readSerialData(Unknown Source)
        at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
        at java.io.ObjectInputStream.readObject0(Unknown Source)
        at java.io.ObjectInputStream.readObject(Unknown Source)
        ... 3 more

Thanks for any help.

1 Answer 1

2

You are running a 1.5+ server without a stub, which causes a dynamic stub to be used, in the form of a dynamic proxy and an RemoteObjectInvocationHandler, and a 1.4 client, which doesn't have the RemoteObjectInvocationHandler class in the JRE.

You need to run 'rmic' and deploy the stub correctly at the server and clients. You haven't deployed the stub class correctly at server and client. It isn't even being found at the server. It should be in the JAR file at both ends, not in some weirdo directory unknown to the CLASSPATH.

Or update the clients to use a current JDK. 1.4 is many years past end of life.

Sign up to request clarification or add additional context in comments.

5 Comments

The Java client can not update 1.4.2 because the application will be used by a legacy system that only supports that version of java. Sorry to ask something so stupid, but what's the best way to add the stub in the jar?.
Same way you put any other .class file into the jar.
Create the stub and skeleton with rmic -v1.1 and add classes in compliance with directory structure in RmiServer.jar In both the run indicated "-Djava.rmi.server.codebase=file:F:/RmiServer.jar" But still gives the same error. Sorry, but I'm missing something?.
Now it works!. Your explanation helped me. I had missed classhpath change.
@MariaJosé You don't need a skeleton, or -v1.1 either. Skeletons have been obsolete since 1998. file: codebase URLs don't work in general, you should normally use FTP or HTTP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.