Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

RMI stub loading problems within Tomcat environment

843793Sep 18 2001 — edited Aug 29 2002
Hi Java folks,

I encountered something weird in my client-server-application.
First I tried a simple client which has an RMI connection to an RMI server. Client and server reside on different machines. This works fine - the client calls Naming.lookup (<RMI-server-url + service name>) and casts that thing on the common interface used by client and server. Afterwards all methods of the remote objects are available. Fine.

Now I put my (RMI)-client into a servlet. The code for the RMI-connection is similar. The servlet is deployed in Tomcat 3.2.2. Naming.lookup() again returns "some" object. If I use it's toString()-method I can see that the class type is the expected RMI-stub from the server. Now something really odd happens: If I try to cast that stub to my interface I get a ClassCastException!

I have written a main-method to test the servlet outside tomcat. This just calls init() like the servlet enginge would do, and init tries to establish the RMI connection as described above. So if I use that main-method and call init() directly, I can easily cast the stub to my interface. If I use the servlet engine which in turn calls init(), I suddenly cannot cast it to my interface anymore! What the hell happens there?

I can avoid that problem if I put the stub-class-file in a directory in the tomcat servlet directory so that it's inside the classpath. Then the cast will work. This solves my problem, but it's not quite clever. I think the standard way would be that an RMI client (in this case a servlet) just knows about the interface and loads the stub dynamically from the (RMI-)server. The server stub could vary this way and it would still work as the interface stays the same.

Anybody any idea about that?

Regards,

Stefan
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 26 2002
Added on Sep 18 2001
4 comments
344 views