aspose file tools*
The moose likes Distributed Java and the fly likes codebase problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "codebase problem" Watch "codebase problem" New topic
Author

codebase problem

Vijay Venkat
Ranch Hand

Joined: Aug 12, 2001
Posts: 52
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..." );
}
}
//----------------------------------------------------------------------
Vijay Venkat
Ranch Hand

Joined: Aug 12, 2001
Posts: 52
grant{
permission java.security.AllPermission "","";
};
Just add the new line to the policy file and it works !!!
permission java.net.SocketPermission "*:80", "connect";
hence the policy.all file becomes
grant{
permission java.security.AllPermission "","";
permission java.net.SocketPermission "*:80", "connect";
};
rose shik
Greenhorn

Joined: Jan 22, 2010
Posts: 3
Ive just been ... fighting with this stuff to... after some perserverence I
did get it all to work, but encountered a number of errors along the way. I
did keep notes about how to get a setup working on a Linux box- so may not
directly apply to win XP, but if you need more info...

Anyway, in short-
- clear the CLASSPATH
- start the RMI registry
- set the CLASSPATH eg
/home/whatever/src:/public_html_dir/classes/yourjar.jar
- start the rmi server ie cd /public_html_dir/classes then,
java -Djava.rmi.server.codebase=http://whatever/classes/ -Djava.rmi.server.h
ostname=whatever -Djava.security.policy=java.policy package.class
- start the client...

good luck

"Søren "Pengman" Pedersen" <pengman@pengworld.zzn.com> wrote in message
news:borikb$gfb$1@sunsite.dk...
> Dear all
>
> My setup is this:
>
> A RMI server application running with the codebase property as follows:
> -Djava.rmi.server.codebase=http://localhost/Java/Rmiserver/
>
> this location contains the root of the package which containts the stubs

and
> other classes for the server. Those files is accesible with internet
> explorer.
>
> Then when I try to run my client program I get this message:
>
> "error unmarshalling return; nested exception is:
> java.lang.ClassNotFoundException:RMI.server.Chanse rv_Stub"
>
> How can that be??
> The file that it cannot find is availible in
> http://localhost/Java/RMIserver/RMI/...erv_Stub.class and if I
> place it with the client application everything is fine....
>
> I hope somebody can help me with this... Just´say if you need more
> information but I think it must be something stupid I've forgotten
>
> Thanks in advance
> Søren
>
>

===========================
health care jobs which pay more
Leesburg Vein Clinic
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: codebase problem
 
Similar Threads
help, RMI
Starting local server problem -Rmi
RMI Newbie
RMI access denied client/server
How to change default RMI 1099 port