File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI network mode testing problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI network mode testing problem" Watch "RMI network mode testing problem" New topic
Author

RMI network mode testing problem

Kuan Fan
Ranch Hand

Joined: Jan 25, 2002
Posts: 48
hi all,
I have a question about my FBN assignment. I finished coding but when i test network mode i there are something wrong.( i use rmi )
1. I start HTTP SERVER
2. start rmiregistry
3. start server
D:\server>java -Djava.rmi.server.codebase=http://kuanfan-server/ suncertify.db.FactoryServer D:\SCJD\suncertify\db\db.db
4. start client
java -Djava.security.policy=client.policy suncertify.client.MenuMain rmi://kuanfan-server/serviceFactory
the step 1--3 are successful
the step 4 fails
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: suncertify.db.ServiceFactory_Stub
java.lang.ClassNotFoundException: suncertify.db.ServiceFactory_Stub
at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:981)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:232)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:89)
at suncertify.client.MenuMain.getConnection(MenuMain.java:122)
at suncertify.client.MenuMain.main(MenuMain.java:171)
there are strange exception about java.io.ObjectInputStream
i don't know if anyone else has same question as me.
I'm very confused!
Any comments are welcomed! appreciate your help!
thanks!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Did you include your stubs with your client? they need to be there.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Kuan Fan
Ranch Hand

Joined: Jan 25, 2002
Posts: 48
hi Mart,
So nice to get your reply!
I think the stubs should be download to clients machine from server machine.
Just now I solved this problem by add "System.setSecurityManager(new RMISecurityManager());" to Client programe. Actually i don't know why can solve the problem by adding this sentence. But there is another problem follows up:
1. I Apply the Factory Pattern to RMI
2. now i can get ServiceFactory_Stub
but when I invoke getDataAccess() in ServiceFactory_Stub to get a RemoteData, the exceptions are:
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: suncertify.db.RemoteData_Stub
java.lang.ClassNotFoundException: suncertify.db.RemoteData_Stub
at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:981)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:232)
at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:304)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:138)
at suncertify.db.ServiceFactory_Stub.getDataAccess(Unknown Source)
at suncertify.client.MenuMain.main(MenuMain.java:173)
I don't know why like this because the client can get the ServiceFactory_Stub.
look forward you reply. thank you very much!
stephen
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

at suncertify.db.ServiceFactory_Stub.getDataAccess(Unknown Source)

Unknown Source! Hmm sounds like it isn't getting the stub, the only way the server can download it to the client is via dynamic loading, which I believe requires a Web Server.
I still say try to include the stub with the client. But I am wrong a lot of times
Mark
Gregory Garrison
Ranch Hand

Joined: Oct 05, 2001
Posts: 107
stephen - Just my two cents but if you are just trying to pass this exam you don't need a web server. For the exam you will need to supply the rmi stubs in the directory of the client.
Kuan Fan
Ranch Hand

Joined: Jan 25, 2002
Posts: 48
hi Mark and Gregory
thanks very much!
quote: Mark
--------------------------------------------------------------------------------
Unknown Source! Hmm sounds like it isn't getting the stub, the only way the server
can download it to the client is via dynamic loading, which I believe requires a
Web Server.
--------------------------------------------------------------------------------
here is my source code
//interface DataAccess defines all the public methods in Data
//RemoteData extends UnicastRemoteObject and implements DataAccess

//implements the ServiceManager, source codes is here
public class ServiceFactory extends java.rmi.server.UnicastRemoteObject implements ServiceManager, Unreferenced
public DataAccess getDataAccess() throws RemoteException {
try {
RemoteData p =new RemoteData( dbString );
return p;
} catch( Exception e ) { e.printStackTrace(); return null; }
}

//ServiceManager define a method getDataAccess to get a reference which implements DataAccess
public interface ServiceManager extends java.rmi.Remote
public DataAccess getDataAccess( ) throws RemoteException



//this class generates an instance of ServiceFactory and registers it to rmiregistry
public class FactoryServer

i start web server; start rmiregistry( no classpath ); start server( -Djava.rmi.server.codebase=http://kuanfan-server/ ) to
register the ServiceFactory
now i can get the stub of ServiceFactory, but when i invoke the getDataAccess method the exceptions are like these;
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: suncertify.db.RemoteData_Stub
java.lang.ClassNotFoundException: suncertify.db.RemoteData_Stub
at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:981)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:232)
at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:304)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:138)
at suncertify.db.ServiceFactory_Stub.getDataAccess(Unknown Source)
at suncertify.client.MenuMain.main(MenuMain.java:173)
I check lots of materials but i can't find the answer.
by the way, when submit the assignment to sun, may i tell them include the stubs in client when they test the RMI network mode?
But if sun permits us to do this, I don't know whether this is a real RMI network mode. Because when the RMI client look for the stubs,
if it find the stubs are in the local system already, the client don't need to download them from server machine.
any comments and suggestion are welcomed! thanks in advance!
stephen
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Well I see your ServiceManager extending remote, but what about your DataAccess interface or the class that implements this interface. It needs to be a remote object too.
Mark
Kuan Fan
Ranch Hand

Joined: Jan 25, 2002
Posts: 48
Yes, Mark
DataAccess definition is here i forgot wrote it last time )
public interface DataAccess extends Remote
thanks very much! any other suggestions?
stephen
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Hi
Yust a question - ALL stubs and ALL remote interfaces are copied to the client?
if no then copy: ServiceFactory_Stub, RemoteData_Stub, DataAccess (interface) and ServiceManager (interface) to the client
hope this helps
/Ren�


Regards, Rene Larsen
Dropbox Invite
Kuan Fan
Ranch Hand

Joined: Jan 25, 2002
Posts: 48
thanks Rene!
I copy them. It works.
But how about the real RMI mode? I have no idea about whether the stubs should dynamicly download to client? what do you think?
stephen
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Hi Stephen
I have not used dynamic download, because there is no need for it to pass this assignment - and the assignment do not require it.
I just copied the stubs and remote interfaces to the client that is it...
I did not have to set codebase or have to define how to setup the web server. Not useing dynamic download then there is no need for a Security Manager.
/Ren�
Kuan Fan
Ranch Hand

Joined: Jan 25, 2002
Posts: 48
thanks Rene!
You're right. I document it as you said.
thanks for all of the people who helped me!
Dasong
Ranch Hand

Joined: Apr 05, 2002
Posts: 36
Hi Rene
You said you copy remote interface and remote object Stub to client. How did you put them in the client jar file? Or do we have to put server jar file at client side as well?
Thanks preceding
Dasong
[ April 06, 2002: Message edited by: Dasong ]
Dasong
Ranch Hand

Joined: Apr 05, 2002
Posts: 36
Hello people! I am very happy right now. Are you? :roll: Do you feel like any of the faces I put on right now?
[ April 06, 2002: Message edited by: Dasong ]
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Hi Dasong
You said you copy remote interface and remote object Stub to client. How did you put them in the client jar file? Or do we have to put server jar file at client side as well?

If the packages for the client are:
suncertify.client
suncertify.db
and for the server:
suncertify.server
suncertify.db
then you just have to copy the suncertify.server package with only the remote interface and remote object Stub inside, to the client.
/Ren�
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: RMI network mode testing problem