hi all, I meet a strange problem when i writing a test for a simple filter, the filter's function is to save the user name in the session. The test works well when I deploy it in tomcat and test it from browser. But when I try to integrate it with jetty and run the test using junit4 in the eclipse, it give me the strange error information. I have worked this strange error for several days, and hope get some help from you. Thanks very much.
btw, I also write a simple servlet test, and it also works well with the jetty integration, they are in the same project. the following is the exception, classes and configuration. 0. the exception detail org.apache.cactus.util.ChainedRuntimeException: Failed to get the test results at [http://localhost:8081/CactusTest/FilterRedirector] at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody0(DefaultHttpClient.java:93) at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody1$advice(DefaultHttpClient.java:307) at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest(DefaultHttpClient.java:1) at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runWebTest(HttpProtocolHandler.java:164) at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody0(HttpProtocolHandler.java:83) at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody1$advice(HttpProtocolHandler.java:307) at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest(HttpProtocolHandler.java:1) at org.apache.cactus.internal.client.ClientTestCaseCaller.runTest(ClientTestCaseCaller.java:145) at org.apache.cactus.internal.AbstractCactusTestCase.runBareClient(AbstractCactusTestCase.java:218) at org.apache.cactus.internal.AbstractCactusTestCase.runBare(AbstractCactusTestCase.java:134) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:124) at junit.framework.TestSuite.runTest(TestSuite.java:232) at junit.framework.TestSuite.run(TestSuite.java:227) at junit.framework.TestSuite.runTest(TestSuite.java:232) at junit.framework.TestSuite.run(TestSuite.java:227) at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24) at org.apache.cactus.extension.jetty.Jetty5xTestSetup$1.protect(Jetty5xTestSetup.java:168) at junit.framework.TestResult.runProtected(TestResult.java:128) at org.apache.cactus.extension.jetty.Jetty5xTestSetup.run(Jetty5xTestSetup.java:176) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) org.apache.cactus.internal.client.ParsingException: Not a valid response [404 %2FCactusTest%2FFilterRedirector+Not+Found] at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.callGetResult(DefaultHttpClient.java:212) at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody0(DefaultHttpClient.java:88) at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody1$advice(DefaultHttpClient.java:307) at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest(DefaultHttpClient.java:1) at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runWebTest(HttpProtocolHandler.java:164) at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody0(HttpProtocolHandler.java:83) at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody1$advice(HttpProtocolHandler.java:307) at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest(HttpProtocolHandler.java:1) at org.apache.cactus.internal.client.ClientTestCaseCaller.runTest(ClientTestCaseCaller.java:145) at org.apache.cactus.internal.AbstractCactusTestCase.runBareClient(AbstractCactusTestCase.java:218) at org.apache.cactus.internal.AbstractCactusTestCase.runBare(AbstractCactusTestCase.java:134) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:124) at junit.framework.TestSuite.runTest(TestSuite.java:232) at junit.framework.TestSuite.run(TestSuite.java:227) at junit.framework.TestSuite.runTest(TestSuite.java:232) at junit.framework.TestSuite.run(TestSuite.java:227) at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24) at org.apache.cactus.extension.jetty.Jetty5xTestSetup$1.protect(Jetty5xTestSetup.java:168) at junit.framework.TestResult.runProtected(TestResult.java:128) at org.apache.cactus.extension.jetty.Jetty5xTestSetup.run(Jetty5xTestSetup.java:176) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) ----------------------------------------------------------------------------------------------------------------------------------- 1. SimpleFilter : the filter class package demo.cactus.java; public class SimpleFilter implements Filter { private FilterConfig config; public void destroy() { // TODO Auto-generated method stub } public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { String userName; if(req.getParameter("USERNAME") == null || "".equals(req.getParameter("USERNAME"))) { userName = "SOMEONE"; } else { userName = req.getParameter("USERNAME"); } ((HttpServletRequest) req).getSession().setAttribute("USERNAME", userName); chain.doFilter(req, resp); } public void init(FilterConfig config) throws ServletException { this.config = config; } } ----------------------------------------------------------------------------------------------------------------------------------- 2. TestSimpleFilter : the test class public class TestSimpleFilter extends FilterTestCase { public void beginDoFilter(WebRequest request) { request.addParameter("USERNAME", "guest"); } public void testDoFilter() throws Exception { SimpleFilter filter = new SimpleFilter(); FilterChain mockFilterChain = new FilterChain() { public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { PrintWriter writer = response.getWriter(); Object loginUserName = ((HttpServletRequest)request).getSession().getAttribute("USERNAME"); String userName = (loginUserName == null) ? "null" : loginUserName.toString(); writer.write("<p>userName= "+ userName +"</p>"); writer.close(); } }; filter.doFilter(request, response, mockFilterChain); } public void endDoFilter(WebResponse response) throws Exception { assertTrue("RIGHT RESPONSE", response.getText().indexOf("guest") > 0); } } ----------------------------------------------------------------------------------------------------------------------------------- 3. JettyTestSuite : the integeration class with jetty package demo.cactus.test; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.cactus.extension.jetty.Jetty5xTestSetup; public class JettyTestSuite extends TestCase { public static Test suite() { System.setProperty("cactus.contextURL", " http://localhost:8081/CactusTest"); TestSuite suite = new TestSuite(); suite.addTestSuite(TestSimpleFilter.class); return new Jetty5xTestSetup(suite); } } ----------------------------------------------------------------------------------------------------------------------------------- 4. web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- Cactus Config --> <servlet> <servlet-name>ServletRedirector</servlet-name> <servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-class> </servlet> <servlet-mapping> <servlet-name>ServletRedirector</servlet-name> <url-pattern>/ServletRedirector</url-pattern> </servlet-mapping> <filter> <filter-name>FilterRedirector</filter-name> <filter-class>org.apache.cactus.server.FilterTestRedirector</filter-class> </filter> <filter-mapping> <filter-name>FilterRedirector</filter-name> <url-pattern>/FilterRedirector</url-pattern> </filter-mapping> <servlet> <servlet-name>ServletTestRunner</servlet-name> <servlet-class>org.apache.cactus.server.runner.ServletTestRunner</servlet-class> </servlet> <servlet-mapping> <servlet-name>ServletTestRunner</servlet-name> <url-pattern>/ServletTestRunner</url-pattern> </servlet-mapping> </web-app> ----------------------------------------------------------------------------------------------------------------------------------- 5. libs the cactus version is 1.8.1. aspectjrt-1.5.3.jar cactus.core.framework.uberjar.javaEE.14-1.8.1.jar cactus.integration.ant-1.8.1.jar cactus.integration.shared.api-1.8.1.jar commons-codec-1.4.jar commons-httpclient-3.1.jar commons-logging-1.0.4.jar httpunit.jar js-1.6R5.jar jtidy-4aug2000r7-dev.jar junit-4.4.jar nekohtml-0.9.5.jar org.mortbay.jetty-5.1.9.jar xercesImpl-2.6.1.jar ----------------------------------------------------------------------------------------------------------------------------------- -- Best regards, Haiting Zhang chiefsai...@gmail.com