I have a few problems with Cactus, which I have been unable to find any
information about. I got several Cactus test cases which works fine, but
the below cases does not work for me.
I am using JBoss with Tomcat 3.2.3.
1) Problem with dispatching from Servlet to JSP.
In my Servlet I redirect/dispatch to a JSP template. This works fine,
when running the Servlet without Cactus. But when running my Cactus test
case I get below error every time. This is the code that fails.
ServletContext servletContext = getServletContext();
javax.servlet.RequestDispatcher requestDispatcher =
servletContext.getNamedDispatcher( template );
requestDispatcher.forward( req, res ); <------- This goes wrong.
I have initialized the servlet context first in the Cactus test case:
servlet.init(config);
This is the error I get:
java.lang.NullPointerException
at
org.apache.cactus.server.RequestDispatcherWrapper.forward(RequestDispatcherWrapper.java:98)
at com.inceptor.rt.Servlet.dispatchError(Servlet.java:164)
at com.inceptor.rt.Servlet.unexpectedErrorHandling(Servlet.java:132)
at com.inceptor.rt.Servlet.processRequest(Servlet.java:94)
at com.inceptor.rt.Servlet.doGet(Servlet.java:48)
at
com.inceptor.cactus.TestServletChannelMatch.testChannelMatchLongestMatchWins(TestServletChannelMatch.java:82)
at java.lang.reflect.Method.invoke(Native Method)
at
org.apache.cactus.AbstractTestCase.runServerTest(AbstractTestCase.java:491)
at
org.apache.cactus.AbstractTestCase.runBareServerTest(AbstractTestCase.java:456)
at
org.apache.cactus.server.AbstractTestCaller.doTest(AbstractTestCaller.java:137)
at
org.apache.cactus.server.AbstractTestController.handleRequest(AbstractTestController.java:122)
at
org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java:134)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:484)
2) Response 404 least to file not found exception:
For some request my Servlet correct behaviour is to respond with a 404
Page Not Found.
This works fine when running the servlet without Cactus, however, when
running my Cactus test case I get the below error:
So the servlet code is:
res.sendError(HttpServletResponse.SC_NOT_FOUND);
res.flushBuffer();
The exception I get is:
java.io.FileNotFoundException:
http://localhost:8080/cactus/ServletRedirector/
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:562)
at
org.apache.cactus.client.AutoReadHttpURLConnection.getInputStream(AutoReadHttpURLConnection.java:127)
at
org.apache.cactus.client.AbstractHttpClient.doTest(AbstractHttpClient.java:136)
at
org.apache.cactus.AbstractTestCase.runGenericTest(AbstractTestCase.java:422)
at org.apache.cactus.ServletTestCase.runTest(ServletTestCase.java:130)
at org.apache.cactus.AbstractTestCase.runBare(AbstractTestCase.java:371)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:131)
at junit.framework.TestSuite.runTest(TestSuite.java:173)
at junit.framework.TestSuite.run(TestSuite.java:168)
at junit.framework.TestSuite.runTest(TestSuite.java:173)
at junit.framework.TestSuite.run(TestSuite.java:168)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:231)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:582)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:403)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:380)
at org.apache.tools.ant.Task.perform(Task.java:217)
at org.apache.tools.ant.Target.execute(Target.java:164)
at org.apache.tools.ant.Target.performTasks(Target.java:182)
at org.apache.tools.ant.Project.executeTarget(Project.java:601)
at org.apache.tools.ant.Project.executeTargets(Project.java:560)
at org.apache.tools.ant.Main.runBuild(Main.java:454)
at org.apache.tools.ant.Main.start(Main.java:153)
at org.apache.tools.ant.Main.main(Main.java:176)
3) Synchronization problem.
In some cases my Servlet sends a redirect flushes the buffer... and then
continues to do some processing for logging.
response.sendRedirect(redirectURL);
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
response.flushBuffer();
... more stuff for logging.
This works fine, as long as the test is run in isolation. However, if I
do 2 of these test after each other I get into trouble because the setUp
method of the second test is run before the tearDown method of the first
test. I have avoided this by inserting a statement in the endXXX method
that makes the first test sleep for 10 seconds - such that the start of
the next test is delayed.
However, it seems to me that fact that I am flushing the http-response
tricks Cactus into thinking that the test has completed, when in fact
the Servlet is still processing.
Any help on any of these 3 issues would greatly be appreciated.
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>