I have a small RMI Application in the following form
I want the Stub to be down loaded to the client dynamically.
I want my application to run in the following manner.
Client in one machine
Server in another machine
Http Serever in another machine
HttpServer serves the Classes requried for the client [Implies i set the java.rmi.server.codebase=http://ipaddress:8080/]
All classes requried are stored in public_html/ directory in the machine where the webserver is run . The package sturcture is also maintained.
The structure of the rmi program is as mentioned below
Rmi structure
rmidir/SimpleStocks>StockMarket.java [RemoteInterface]
rmidir/SimpleStocks>StockMarketImpl.java [Implementig class]
rmidir>StockMarketServer.java [Server class instantiating the Implementing class]
rmidir>StockMarketClient.java [Client which invokes remote calls]
rmidir>policy.all
The code of the programs are given in the end of this document.
The class files are distributed in the machine in the manner described below
Machine 1 for running the client part
--------------------------------------------
client> StockMarketClient.java [The client program]
client> policy.all
client>StockSeverClient.class
client/SimpleStocks>StockMarket.java [The RemoteInterface ]
client/SimpleStocks>StockMarket.class
Machine 2 - Running the RMI Registry and the RMI Server class
--------------------------------------------------------------------
server> StockMarketServer.java [The server class which instantiates the StockMarketImpl]
server> policy.all
Machine 3 - The webserver is run here [Using javawebserver2.0 for
testing]
related files are set here
public.html\SimpleStocks>StockMarket.class [The remote object]
public.html\SimpleStocks>StockMarketImpl.class
public.html\SimpleStocks>StocmMarketImpl_stub.class
I have compiled all the code at one place and distributed the class in the three machines accordingly.
In Machine 3 : i start the webserver and i check if it works from another machine - i find it is working.
Now in machine 2 in one of the command promt i start
server>rmiregistry
in another prompt
server>
java -Djava.security.policy=policy.all -Djava.rmi.server.codebase=http://192.168.33.79:8080/ StockMarketServer
Problem !!! The server does not get loaded - it always screams that the Remote object is not found /
when i copy the remoteinterface calss ie StockMarket.classs in the directory
server/SimpleStocks> then again execute the command
java -Djava.security.policy=policy.all -Djava.rmi.server.codebase=http://192.168.33.79:8080/ StockMarketServer
now it screams that the StockMarketImpl.class not found
then screams Stub not found. I dont understand then what is the work of the codebase
-Djava.rmi.server.codebase=http://192.168.33.79:8080/ - then what does this line mean.
Want RMI look for all this from the webserver ???
Any solution as to how to solve the problem. But one thing is for sure
I want client in one machine
Sever invocation in another machine
Webserver in another machine
Is this possible ???
Where am i exactly going wrong ??
Leads or Solutions please !!
Thanks in advance !
code of the programs - a sample program downloaded from site
//----------------------------------------------------------------------
package SimpleStocks;
import java.util.*;
import java.rmi.*;
public interface StockMarket extends java.rmi.Remote {
float get_price(
String symbol ) throws RemoteException;
}
//----------------------------------------------------------------------
package SimpleStocks;
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
public class StockMarketImpl extends UnicastRemoteObject implements StockMarket {
public StockMarketImpl( String name ) throws RemoteException {
try {
Naming.rebind(name, this );
} catch( Exception e ) {
System.out.println( e );
}
}
public float get_price( String symbol ) {
float price = 5.0f;
return price;
}
}
//----------------------------------------------------------------------
grant{
permission java.security.AllPermission "","";
};
//----------------------------------------------------------------------
import java.rmi.*;
import java.rmi.registry.*;
import SimpleStocks.*;
public class StockMarketClient {
public static void main(String[] args) {
try {
if(System.getSecurityManager() == null)
{
System.setSecurityManager( new RMISecurityManager() );
}
StockMarket market = (StockMarket)Naming.lookup("rmi://192.168.33.29/NASDAQ");
System.out.println("The price of MY COMPANY is "+ market.get_price("MY_COMPANY"));
}catch( Exception e ) {
System.out.println( e );
}
}
}
//----------------------------------------------------------------------
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import SimpleStocks.*;
public class StockMarketServer {
public static void main(String[] args) throws Exception {
if(System.getSecurityManager() == null)
{
System.setSecurityManager(new RMISecurityManager());
}
StockMarketImpl myObject = new StockMarketImpl( "NASDAQ" );
System.out.println( "RMI StockMarketServer ready..." );
}
}
//----------------------------------------------------------------------