tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jacek Lawniczek" <>
Subject RMI class loading in a servlet (ClassCastException)
Date Mon, 06 Aug 2001 16:46:08 GMT
Hello everyone,
I have a problem using RMI in a servlet. My configuration is desribed below:
Machine 1:
   - RMI server
   - HTTP server for dynamic class loading.
Machine 2:
   - Tomcat 3.2, my servlet that is an RMI client.

When the servlet is trying to connet to the RMI server, it cannot see all
the classes which are located in WEB-INF/classes directory. This is strange
but it does not cause an error and the client then downloads the neccessary
class files from HTTP server on Machine 1. I can see in the HTTP server log
that the RMI interface, related class and the STUB class are downloaded to
Machine 2.
Unfortunatelly an exception is thrown after I use Naming.lookup to find the
server's instance. I cast the returned Object to my server's interface
(ParkServer) and I get ClassCastException. When I check the Object's class
it shows PackServerImpl_Stub and "PackServerImpl_Stub implements
ParkServer". The code looks like this:

Object o = Naming.lookup("//machine2/park/ParkServer");
// ok
System.out.println("Class=" + o.getClass().getName());
// prints "Class=ParkServerImpl_Stub"
// and this class implements ParkServer interface
ParkServer p = (ParkServer) o;  // exception is raised!!!!

This is very strange to me and I don't know what to do. Please help.

Everything works fine when I put the STUB file in the WEB-INF directory but
it is not the best solution. The the client doesn't download any files from
HTTP server on Machine 1. It takes evertything from WEB-INF/classes.

When I connect to the RMI server from a standalone client everything is OK.
I can also see in the HTTP server's log that only the STUB class is loaded
to the client. This is the right way.

Best regards,

Janosik ma swego godnego nastepce...

View raw message