Two Laptop Bag*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RemoteData Stub Error... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RemoteData Stub Error..." Watch "RemoteData Stub Error..." New topic
Author

RemoteData Stub Error...

Dayanand Kangala
Greenhorn

Joined: Sep 09, 2002
Posts: 26
Hi,
I am building the basic functionality for client-server communication using RMI.
When I try to lookup the RemoteData object (present in "suncertify.server" package) from a client (present in "client" package), I get
the following error:
RemoteConnection exception: suncertify.server.RemoteData_Stub
java.lang.ClassCastException: suncertify.server.RemoteData_Stub
at client.RemoteConnection.getConnection(RemoteConnection.java:11)
at client.clientTest.main(clientTest.java:258)
Remote Implementation available.
Exception in thread "main" java.lang.NullPointerException
at client.clientTest.<init>(clientTest.java:63)
at client.clientTest.main(clientTest.java:259)
But, when I copy the client class to the "suncertify.server" and access the RemoteData object, the application is running. Where am I making a mistake?!
I also tried copying the RemoteData_Stub to the "client" folder, but still the above error was thrown.
(RemoteData is the class which extends extends UnicastRemoteObject and implements DBMain (which extends Remote). RemoteData's main method binds the RemoteData object with the rmi-registry. The client lookups this object using rmi://ipaddress/obj)
Dayanand.
Dayanand Kangala
Greenhorn

Joined: Sep 09, 2002
Posts: 26
Please note: in the above error message, "Remote Implementation available." is not part of the error message ! (I had a System.out.println )
[ September 26, 2002: Message edited by: Dayanand Kangala ]
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

I also tried copying the RemoteData_Stub to the "client" folder, but still the above error was thrown.

Are you making use of codebase parameter and policy file? Try to run your app without them.
Eugene.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Dayanand,
It looks to me like your trying to cast to the object instead of the interface. You can only cast to a Remote interface on the client thru RMI. That's why it works on the server when not using RMI.
Hope this helps,
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Dayanand Kangala
Greenhorn

Joined: Sep 09, 2002
Posts: 26
Originally posted by Eugene Kononov:

Are you making use of codebase parameter and policy file? Try to run your app without them.
Eugene.

Hi Eugene,
I ran the client without specifying the codebase and policy file.
The following is my directory structure:
workspace
-> Project
---> client
---> suncertify
-------> data
-------> server
I have given "Full Permission" to the directory "workspace", using policytool.
Dayanand.
Dayanand Kangala
Greenhorn

Joined: Sep 09, 2002
Posts: 26
Originally posted by Michael Morris:
Hi Dayanand,
It looks to me like your trying to cast to the object instead of the interface. You can only cast to a Remote interface on the client thru RMI. That's why it works on the server when not using RMI.
Hope this helps,
Michael Morris

Hi Michael,
The following are what I use in the "client":
ConnectionFactory (an interface)
LocalConnection implements ConnectionFactory
RemoteConnection implements ConnectionFactory
When the client is started with "alone" (or) no parameters, the LocalData object is returned by LocalConnection. When the client is started with "server" as parameter, I connect to RMI Registry to get the RemoteData object.
For both, I do the following in client:
DBMain obj = (DBMain) LocalData.getConnection();
(or)
DBMain obj = (DBMain) RemoteData.getConnection();
DBMain is an interface. LocalData and
RemoteData implements this interface. I am not sure if this is done properly.
The following is what I have done:
I have DBMain interface in the "client" package as well as in the "suncertify.server" package. The only difference between these files is that the DBMain interface in the "suncertify.server" package "extends Remote" and all methods "throws RemoteException". The RemoteData (in suncertify.server package) implements the DBMain interface (in the suncertify.server package). When I get the RemoteData object I cast it to DBMain interface (as shown above - in the client package).
Should I copy the DBMain interface used in the "suncertify.server" package in "client" package?
Dayanand.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Dayanand,
ConnectionFactory has to extend Remote also. Here's what you need to do to get your connection:

Your ConnectionFactory should be bound to the RMI registry with some appropriate name using Naming.rebind() on the server.
Hope this helps,
Michael Morris
Dayanand Kangala
Greenhorn

Joined: Sep 09, 2002
Posts: 26
Originally posted by Michael Morris:
Hi Dayanand,
ConnectionFactory has to extend Remote also. Here's what you need to do to get your connection:

Your ConnectionFactory should be bound to the RMI registry with some appropriate name using Naming.rebind() on the server.
Hope this helps,
Michael Morris

Thanks Michael,
I extended the ConnectionFactory as Remote, tried various other things (for a lonng time - 2 days) and finally the client-server communication is happening
Dayanand
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RemoteData Stub Error...
 
Similar Threads
ClassCast Exception with RMI
coupling between client and server Packages.
NX:RMI exception
unable to run client
Local mode - Remote mode