PDA

View Full Version : Unable to use MockHttpServletRequest in dispatcher?


moltobenny
06-08-2010, 08:49 PM
Resin 4.0.6, Spring 3.0.2:

This:

MockHttpServletRequest mockrequest = new MockHttpServletRequest();
MockHttpServletRequest mockresponse = new MockHttpServletResponse();
...
RequestDispatcher dispatcher = webApplicationContext.getServletContext().getReque stDispatcher(path);

dispatcher.forward(mockrequest, mockresponse);

...throw the following exception:

java.lang.ClassCastException: org.springframework.mock.web.MockHttpServletReques t cannot be cast to com.caucho.server.http.CauchoRequest
at com.caucho.server.http.CauchoRequestWrapper.getCau choRequest(CauchoRequestWrapper.java:781)

I've tried everything I can think of. Help?

emil
06-08-2010, 10:39 PM
Hi,

I don't think we allow that at the moment, but I've filed a bug report here:

http://bugs.caucho.com/view.php?id=4073

Can you give a full stack trace for the bug report?

Thanks,
Emil

moltobenny
06-08-2010, 11:38 PM
Sure, here's the full stacktrace:

java.lang.ClassCastException: org.springframework.mock.web.MockHttpServletReques t cannot be cast to com.caucho.server.http.CauchoRequest
at com.caucho.server.http.CauchoRequestWrapper.getCau choRequest(CauchoRequestWrapper.java:781)
at com.caucho.server.http.CauchoRequestWrapper.getSes sionId(CauchoRequestWrapper.java:462)
at com.caucho.server.http.CauchoRequestWrapper.getSes sionId(CauchoRequestWrapper.java:464)
at com.caucho.server.http.AbstractCauchoRequest.finis hRequest(AbstractCauchoRequest.java:590)
at com.caucho.server.webapp.ForwardRequest.finishRequ est(ForwardRequest.java:112)
at com.caucho.server.webapp.RequestDispatcherImpl.for ward(RequestDispatcherImpl.java:293)
at com.caucho.server.webapp.RequestDispatcherImpl.for ward(RequestDispatcherImpl.java:121)


This worked in Resin 3, so we just now ran into the issue, attempting to upgrade to 4.

Thanks!

moltobenny
06-09-2010, 12:34 AM
It may be out of scope for this thread/forum, but given that this no longer works, can anyone suggest a workaround? We were using the request dispatcher to allow us to format customer/partner correspondence with JSPs.

tienus
06-09-2010, 04:54 PM
It would be wonderful if the fix for this could be bumped up to a higher priority. We have code working with Resin 3 versions that is now broken in Resin 4.

Thanks.

emil
06-09-2010, 09:20 PM
Ok, I've bumped the priority given that it's affecting a number of people. I don't have a workaround at the moment, but we can look at getting in a fix ASAP.

Thanks,
Emil

tienus
06-09-2010, 10:24 PM
Great news. Our development team will be grateful.

tienus
02-23-2011, 06:19 PM
With the following code:

MockHttpServletResponse mockresponse = new MockHttpServletResponse();
mockresponse.setContentType("text/html");
mockresponse.setBufferSize(16384);
RequestDispatcher dispatcher =
servletContext.getRequestDispatcher(fileName);
dispatcher.forward(mockrequest, mockresponse);

I'm seeing the following error:

java.lang.NullPointerException
at com.caucho.jsp.PageContextImpl.initialize(PageCont extImpl.java:252)
at com.caucho.jsp.PageManager.allocatePageContext(Pag eManager.java:208)
at _jsp._WEB_22dINF._jsp._email._dealerInvoiceEmailUp dateForOutstandingInvoicesGreaterThanTwentyFiveDay s__jspx._jspService(_dealerInvoiceEmailUpdateForOu tstandingInvoicesGreaterThanTwentyFiveDays__jspx.j ava:23)
at com.caucho.jsp.JavaPage.service(JavaPage.java:64)
at com.caucho.jsp.Page.pageservice(Page.java:542)
at com.caucho.server.dispatch.PageFilterChain.doFilte r(PageFilterChain.java:194)
at com.caucho.server.dispatch.ServletInvocation.servi ce(ServletInvocation.java:287)
at com.caucho.server.webapp.RequestDispatcherImpl.for ward(RequestDispatcherImpl.java:270)
at com.caucho.server.webapp.RequestDispatcherImpl.for ward(RequestDispatcherImpl.java:100)

We are using Using Resin 4.0.13.

Any help would be appreciated.

Thanks

ferg
02-25-2011, 06:25 PM
I've filed this as http://bugs.caucho.com/view.php?id=4409

It may already be addressed in 4.0.15.