View Full Version : resin 4 HttpSession Attribute Object throw ClassCastException in same webapp

10-07-2010, 04:41 PM

I am upgrading from resin 3.2.1 to resin 4.0.10, and noticed some unexpected behaviour change about session attribute in request forwarding.

I was trying to do this:

1. There are webapp_a and webapp_b
2. Request is forwarded from webapp_a to webapp_b
3. In webapp_b,
the request is first processed by TestServlet, then the code does the following to add a sessionAttribute and forward to an hello.jsp page located under webapp_b
SomeObj obj = new SomeObj(); // SomeObj does not implement java.io.Serializable
HttpSession session = request.getSession();
session.setAttribute("test.attribute.name", obj);
this.getServletContext().getRequestDispatcher("/hello.jsp").forward(request, response);
in hello.jsp, we retrive the object from the session attribute and do some further processing.
SomeObj sObj = (SomeObj)session.getAttribute("test.attribute.name");

resin 3.2.1 works fine, whereas resin 4.0.10 throws ClassCastException when the the request is forwarded although the class type is correct and the object is original.
I think this is related to ClassLoader.

To find out, I printed out the ClassLoader used in hello.jsp and found:
resin 3.2.1 used (DynamicClassLoader[SimpleLoader[C:/resin-3.2.1/webapps/webapp_b/WEB-INF/work]])
resin 4.0.10 used (DynamicClassLoader[SimpleLoader[C:/resin-4.0.10/webapps/webapp_a/WEB-INF/work]])

Please note the ClassLoader difference in resin 3.2.1 and resin 4.0.10, resin 4.0.10 ClassLoader has webapp_a although it is in webapp_b.
Once I made SomeObj implements java.io.Serializable, resin 4.0.10 would work, however, this should not be needed as the session attribute object is retrieved within the same webapp.

BTW, this is a single server environment on windows. What else can I do to make resin 4.0.10 behaves the same way as resin 3.2.1 regarding this issue?

10-07-2010, 08:53 PM

Could you clarify step 2? How is the request being forwarded from webapp_a to webapp_b?


10-07-2010, 09:23 PM
in step 2, I did:

//forwarding request
RequestDispatcher rd = servletContext.getContext("/webapp_b").getRequestDispatcher("/servlet/TestServlet");
rd.forward(request, response);


10-07-2010, 09:52 PM
Hi Jessica,

That definitely sounds like a bug. I've filed it here:


Thanks for letting us know,

10-08-2010, 03:16 PM
Thanks a lot!