Hi RMI Specialists,
I am experiencing a possible dynamic class loading issue when attempting to separate the client & server codes across 2 separate Windows (XP & 2000) systems. This exercise (from ch13 of Oreilly’s Learning Java) is made up
of the following interfaces and classes:
On the Server side:
[code]package LearningJavaServer;
import java.rmi.*;
import java.util.*;
public interface RemoteServer extends Remote {
Date getDate( ) throws RemoteException;
Object execute( WorkRequest work ) throws RemoteException;
}[/code]
[code]package LearningJavaServer;
import java.rmi.*;
import java.util.*;
public class MyServer extends java.rmi.server.UnicastRemoteObject
implements RemoteServer {
public MyServer( ) throws RemoteException { }
// implement the RemoteServer interface
public Date getDate( ) throws RemoteException {
return new Date( );
}
public Object execute( WorkRequest work ) throws RemoteException {
return work.execute( );
}
public static void main(String args[]) {
try {
RemoteServer server = new MyServer( );
Naming.rebind("NiftyServer", server);
} catch (java.io.IOException e) {
// problem registering server
}
}
}[/code]
[code]package LearningJavaServer;
import java.io.*;
public class Request implements java.io.Serializable {}[/code]
[code]package LearningJavaServer;
public abstract class WorkRequest extends Request {
public abstract Object execute( );
}[/code]
On the Client side:
[code]package LearningJavaClient;
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class MyClient {
public static void main(String [] args)
throws RemoteException {
new MyClient( args[0] );
}
public MyClient(String host) {
try {
RemoteServer server = (RemoteServer)
Naming.lookup("rmi://"+host+"/NiftyServer");
System.out.println( server.getDate( ) );
System.out.println(
server.execute( new MyCalculation(2) ) );
} catch (java.io.IOException e) {
// I/O Error or bad URL
System.out.println( e );
} catch (NotBoundException e) {
// NiftyServer isn't registered
System.out.println( e );
}
}
}[/code]
[code]package LearningJavaClient;
import java.rmi.*;
import java.util.*;
public interface RemoteServer extends Remote {
Date getDate( ) throws RemoteException;
Object execute( WorkRequest work ) throws RemoteException;
}[/code]
[code]package LearningJavaClient;
public class MyCalculation extends WorkRequest {
int n;
public MyCalculation( int n ) {
this.n = n;
}
public Object execute( ) {
return new Integer( n * n );
}
}[/code]
[code]package LearningJavaClient;
import java.io.*;
public class Request implements java.io.Serializable {}[/code]
[code]package LearningJavaClient;
public abstract class WorkRequest extends Request {
public abstract Object execute( );
}[/code]
Steps to invoke all services on the server side:
cd C:\Documents and Settings\htran\JavaRMI\build\classes on both systems;
( i ) start rmiregistry.
( ii ) java -Djava.rmi.server.codebase='http://serverhostname/LearningJavaServer/' -Djava.security.policy="C:\Documents and Settings\htran\.java.policy" -cp . LearningJavaServer.MyServer
Steps to invoke all services on the client side:
( i ) java -Djava.security.policy="C:\Documents and Settings\htran\.java.policy" -cp . LearningJavaClient.MyClient serverhostname
[b]java.rmi.NotBoundException: NiftyServer[/b]
Or
( ii ) java -Djava.rmi.server.codebase='http://clienthostname/LearningJavaClient/' -Djava.security.policy="C:\Documents and Settings\htran\.java.policy" -cp . LearningJavaClient.MyClient serverhostname
[b]java.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
java.net.MalformedURLException: no protocol: 'http://clienthostname/LearningJavaClient/'[/b]
Is it possible that this issue could have been caused by either the Request/WorkRequest classes which are present on both system? Likewise, is the location of invoking RMI registry on the server correct?
Both systems have got their own web servers (http://serverhostname/LearningJavaServer & http://clienthostname/LearningJavaClient).
No firewalls between the two systems and the security files (C:\Document Settings\htran\.java.policy) are made up of the following 2 lines:
[code]grant codeBase "file:/home/jones/src/" {
permission java.security.AllPermission;
};[/code]
Another issue that I am having is that the server process below is that it keeps on dropping off after a minute or two:
C:\Documents and Settings\htran\JavaRMI\build\classes>java -Djava.rmi.se
rver.codebase='http://clienthostname/LearningJavaClient/' -Djava.security.policy="C:\
Documents and Settings\htran\.java.policy" -cp . LearningJavaClient.MyClient serverhostname
This exercise has worked fine when running all the codes on the same host.
I am running Netbeans 5.5, JDK1.5.0_11 on Windows 2000 (Server) & XP (Client).
Any assistance would be appreciated.
Many thanks,
Henry