Very recently I started running a web application(previously on websphere 5) on Jboss 5 general release with JDK 6 on a Ubuntu box.
Really didn't had much to change except adding one jboss-web.xml, to set the context root. But it's a legacy application which has plethora of jar files in its webinf/lib file. What bugged me for about 2 hrs was this, on a Servlet filter the cast from ServletRequest to HttpServletRequest failed. I tried introspecting the request object in the filter code with the following code
logger.debug(getClass().getName());
logger.debug((req instanceof javax.servlet.http.HttpServletRequest));
for(int i =0; i < req.getClass().getInterfaces().length;i++){
logger.debug((req.getClass().getInterfaces()[i]).getName());
}
javax.servlet.http.HttpSession session=(javax.servlet.http.HttpServletRequest)req).getSession(true);
And the log statement in the for loop was displaying "javax.servlet.http.HttpServletRequest " and debug statement in line 2 was "false". And the last line was giving a ClassCastException.
Intially surprised then upon digging deeper realized it's a stupidity on my end and different classloading at Jboss.
I had a servlet-api.jar in my webinf/lib. I think JBoss loaded HttpServletRequest, it loaded from it's own classloader. While in the application a child classloader loads another instance of this "Class" object from the webinf lib. In the application code the last line compared 2 different class objects loaded by different class loaders, the request object was from Jboss classloader and the other one was from application classloader and gave the error.
Some insight that I had forever but took 2 hours to fix :).
The fix was to remove the servlet-api.jar from webinf lib.
Friday, January 09, 2009
Subscribe to:
Posts (Atom)