• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI network mode testing problem

 
Kuan Fan
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you include your stubs with your client? they need to be there.
Mark
 
Kuan Fan
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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�
 
Kuan Fan
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Rene!
You're right. I document it as you said.
thanks for all of the people who helped me!
 
Dasong
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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�
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic