4.0.1 to 4.0.2 ClassCastException on PortableRemoteObject.na
tigerreef May 13, 2005 6:06 AMHello,
Firstly I know there is a lot of discussion on this point, but I can't find anything that describes my problem exactly.
To emphasize up front:
1. My app is not distributed between two ears (I don't have a hot deploy of partial app issue)
2. The EXACT same ear works in 4.0.1 but not in 4.0.2
The problem:
The code (which is in a Servlet):
Context ctx = new InitialContext();
Object o = ctx.lookup("ejb/TSmartAdmin");
Class target = TSmartAdminHome.class;
TSmartAdminHome home = (TSmartAdminHome)PortableRemoteObject.narrow(o, TSmartAdminHome.class);
causes:
java.lang.ClassCastException
com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
com.tigerreef.templatesmart.servlet.NavServlet.lookupTSmartAdmin(NavServlet.java:397)
but ONLY when deplyed to a JBOSS 4.0.2 server (works fine on 4.0.1).
Additional the same code run in a testClient running within Eclipse runs fine.
It seems to me that the problem is to do with Class loaders. So, added the follwoing code after I have the object ref "o":
System.out.println("Servlet>>>>>> o's CL: " + o.getClass().getClassLoader() + " target's CL: " + target.getClassLoader());
and on 4.0.2 I get:
Servlet>>>>>> o's CL: org.jboss.mx.loading.UnifiedClassLoader3@773a1{ url=file:/C:/jboss-4.0.2/server/default/tmp/deploy/tmp27550TSmartApp.ear ,addedOrder=40} target's CL: WebappClassLoader
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
java.net.FactoryURLClassLoader@1f5248c
Two different class loaders, used for the EJB tier and the Web tier (both from the same ear running in the same JVM - my unserstanding is JBoss is supposed to optimise this.)
I tried the same thing on 4.0.1:
and get:
Servlet>>>>>> o's CL: org.jboss.mx.loading.UnifiedClassLoader3@6dd8e1{ url=file:/C:/jboss-4.0.1/server/default/tmp/deploy/tmp7498TSmartApp.ear ,addedOrder=39} target's CL: org.jboss.mx.loading.UnifiedClassLoader3@6dd8e1{ url=file:/C:/jboss-4.0.1/server/default/tmp/deploy/tmp7498TSmartApp.ear ,addedOrder=39}
NOTE UnifiedClassLoader in both cases....
And now I am stumped. I see a lot of people having problems with comms between two different ears and hot deploys of one of them due to dangling references, but I don't think this is in that category. To reiterate - ONE ear - everything deployed fresh (at the same time), the same problem occurs if I start the server form the command line or from within Eclipse AND the EXACT same ear works fine in 4.0.1.
Please help!
PJ