I'm using Cactus with Struts 1.1 (although in this instance, not with
StrutsTestCase). I have a beginXXX method that sets up a request, and a
testXXX method that invokes the service method on my ActionServlet. In most
of my tests, this works great. I have one request, however, that does not
work. I get an error:
javax.servlet.ServletException: The request object passed to forward() must
be the request object you got from your Cactus test case (i.e. a Cactus
request wrapper object). Instead we got
[org.apache.catalina.core.ApplicationHttpRequest]
The relevant snippet from my struts-config.xml:
<action
path="/pageOne"
type="com.opentext.myactions.KPageAction"
name="pages">
<forward
name="pageTwoFwd"
path="/pageTwo"
redirect="false"/>
</action>
<action
path="/pageTwo"
name="pages"
forward="/WEB-INF/jsp/pageTwo.jsp">
</action>
My test sets up a request for /pageOne. KPageAction executes, and debug
statements confirm that the request is an instance of
org.apache.cactus.server.HttpServletRequestWrapper. KPageAction returns
actionMapping.findForward( "pageTwoFwd" ). This appears to work okay (based
on TRACE output from struts). The next things I see in my debug output are:
<RequestProcessor> Processing a 'GET' for path '/pageTwo'
<MyRequestProcessor> processPreprocess request: class
org.apache.catalina.core.ApplicationHttpRequest
(MyRequestProcessor is my overridden RequestProcessor class, where I
override processPreprocess. At this point, it looks like the request is back
to being the original request, not the wrapped request.)
I then see:
<RequestProcessor> Delegating via forward to '/WEB-INF/jsp/pageTwo.jsp'
<MyRequestProcessor> request: class
org.apache.catalina.core.ApplicationHttpRequest
<MyRequestProcessor> response: class
org.apache.coyote.tomcat5.CoyoteResponseFacade
<ServletContextWrapper> <getRequestDispatcher([/WEB-INF/jsp/pageTwo.jsp])
<ApplicationDispatcher> servletPath=/WEB-INF/jsp/pageTwo.jsp, pathInfo=null,
queryString=null, name=null
<ServletContextWrapper> >getRequestDispatcher =
[EMAIL PROTECTED]
<MyRequestProcessor> rd: class
org.apache.cactus.server.RequestDispatcherWrapper
<ServletContextWrapper> <getRequestDispatcher([/WEB-INF/jsp/pageTwo.jsp])
<ApplicationDispatcher> servletPath=/WEB-INF/jsp/pageTwo.jsp, pathInfo=null,
queryString=null, name=null
<ServletContextWrapper> >getRequestDispatcher =
[EMAIL PROTECTED]
<RequestDispatcherWrapper>
<forward([EMAIL PROTECTED],
[EMAIL PROTECTED])
ApplicationDispatcher[/cactus-hermes]: Servlet.service() for servlet hermes
threw exception
javax.servlet.ServletException: The request object passed to forward() must
be the request object you got from your Cactus test case (i.e. a Cactus
request wrapper object). Instead we got
[org.apache.catalina.core.ApplicationHttpRequest]
So it looks like the first forward from /pageOne to /pageTwo works, but then
the forward to the actual JSP fails. In this simple example, I can work
around the problem by removing a level of indirection in the
struts-config.xml, defining my pageTwoFwd to forward directly to the JSP
instead of going through the /pageTwo action mapping. However, it seems like
it should work either way. Is this a cactus bug? Struts bug? Or am I doing
something wrong?
Thanks,
Daniel Rabe