From acdeba00109360790675bae7a95887efacab5ecc Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Fri, 9 Jun 2023 20:58:17 +1200 Subject: [PATCH] progress --- container-test/README.md | 13 - .../example-webapp/pom.xml | 0 .../MockRewriteMatch.java | 0 .../urlrewriteviacontainer/TestRunObj.java | 0 .../webapp/WEB-INF/urlrewrite-decode-none.xml | 0 .../webapp/WEB-INF/urlrewrite-decode-utf8.xml | 0 .../src/main/webapp/WEB-INF/urlrewrite.xml | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../src/main/webapp/echo.jsp | 0 .../src/main/webapp/gzip-me.jsp | 0 .../src/main/webapp/mod/index.jsp | 0 .../main/webapp/no-decode-test-D%25%2cD.jsp | 0 .../src/main/webapp/products.jsp | 0 .../src/main/webapp/settest.jsp | 0 .../src/main/webapp/test/filterRedirector.jsp | 0 .../src/main/webapp/test/test.jsp | 0 container-test/pom.xml | 151 ------ .../MockRewriteMatch.java | 70 --- .../urlrewriteviacontainer/TestRunObj.java | 248 --------- .../webapp/WEB-INF/urlrewrite-decode-none.xml | 28 - .../webapp/WEB-INF/urlrewrite-decode-utf8.xml | 16 - .../src/main/webapp/WEB-INF/web.xml | 65 --- container-test/src/main/webapp/test/test.jsp | 7 - .../ContainerTestBase.java | 100 ---- .../WebappDecodeNoneIT.java | 61 --- .../WebappDecodeUtf8IT.java | 57 -- .../urlrewriteviacontainer/WebappHttpIT.java | 170 ------ .../WebappModStyleHttpIT.java | 80 --- .../test-with-testcontainters/pom.xml | 4 +- .../ContainerTestBase.java | 0 .../WebappDecodeNoneIT.java | 0 .../WebappDecodeUtf8IT.java | 0 .../urlrewriteviacontainer/WebappHttpIT.java | 0 .../WebappModStyleHttpIT.java | 0 .../src/main/webapp/WEB-INF/urlrewrite.xml | 501 ------------------ .../example-webapp/src/main/webapp/echo.jsp | 1 - .../src/main/webapp/gzip-me.jsp | 1 - .../src/main/webapp/mod/index.jsp | 1 - .../main/webapp/no-decode-test-D%25%2cD.jsp | 1 - .../src/main/webapp/products.jsp | 1 - .../src/main/webapp/settest.jsp | 1 - .../src/main/webapp/test/filterRedirector.jsp | 0 42 files changed, 2 insertions(+), 1575 deletions(-) delete mode 100644 container-test/README.md rename {container-test2 => container-test}/example-webapp/pom.xml (100%) rename {container-test2 => container-test}/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java (100%) rename {container-test2 => container-test}/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java (100%) rename {container-test2 => container-test}/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml (100%) rename {container-test2 => container-test}/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml (100%) rename container-test/{ => example-webapp}/src/main/webapp/WEB-INF/urlrewrite.xml (100%) rename {container-test2 => container-test}/example-webapp/src/main/webapp/WEB-INF/web.xml (100%) rename container-test/{ => example-webapp}/src/main/webapp/echo.jsp (100%) rename container-test/{ => example-webapp}/src/main/webapp/gzip-me.jsp (100%) rename container-test/{ => example-webapp}/src/main/webapp/mod/index.jsp (100%) rename container-test/{ => example-webapp}/src/main/webapp/no-decode-test-D%25%2cD.jsp (100%) rename container-test/{ => example-webapp}/src/main/webapp/products.jsp (100%) rename container-test/{ => example-webapp}/src/main/webapp/settest.jsp (100%) rename container-test/{ => example-webapp}/src/main/webapp/test/filterRedirector.jsp (100%) rename {container-test2 => container-test}/example-webapp/src/main/webapp/test/test.jsp (100%) delete mode 100644 container-test/pom.xml delete mode 100644 container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java delete mode 100644 container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java delete mode 100644 container-test/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml delete mode 100644 container-test/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml delete mode 100644 container-test/src/main/webapp/WEB-INF/web.xml delete mode 100644 container-test/src/main/webapp/test/test.jsp delete mode 100644 container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java delete mode 100644 container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java delete mode 100644 container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java delete mode 100644 container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java delete mode 100644 container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java rename {container-test2 => container-test}/test-with-testcontainters/pom.xml (96%) rename {container-test2 => container-test}/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java (100%) rename {container-test2 => container-test}/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java (100%) rename {container-test2 => container-test}/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java (100%) rename {container-test2 => container-test}/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java (100%) rename {container-test2 => container-test}/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java (100%) delete mode 100644 container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml delete mode 100644 container-test2/example-webapp/src/main/webapp/echo.jsp delete mode 100644 container-test2/example-webapp/src/main/webapp/gzip-me.jsp delete mode 100644 container-test2/example-webapp/src/main/webapp/mod/index.jsp delete mode 100644 container-test2/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp delete mode 100644 container-test2/example-webapp/src/main/webapp/products.jsp delete mode 100644 container-test2/example-webapp/src/main/webapp/settest.jsp delete mode 100644 container-test2/example-webapp/src/main/webapp/test/filterRedirector.jsp diff --git a/container-test/README.md b/container-test/README.md deleted file mode 100644 index 76c09e25..00000000 --- a/container-test/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Container Tests - - mvn clean verify org.codehaus.cargo:cargo-maven3-plugin:run - - mvn clean verify org.codehaus.cargo:cargo-maven3-plugin:run \ - -Dcargo.maven.containerId=tomcat9x \ - -Dcargo.maven.containerUrl=https://repo.maven.apache.org/maven2/org/apache/tomcat/tomcat/9.0.45/tomcat-9.0.45.zip - - - mvn clean verify org.codehaus.cargo:cargo-maven3-plugin:run - -Dcargo.maven.containerId=wildfly20x - -Dcargo.maven.containerUrl=https://download.jboss.org/wildfly/20.0.1.Final/wildfly-20.0.1.Final.zip - -Dcargo.servlet.port=9000 \ No newline at end of file diff --git a/container-test2/example-webapp/pom.xml b/container-test/example-webapp/pom.xml similarity index 100% rename from container-test2/example-webapp/pom.xml rename to container-test/example-webapp/pom.xml diff --git a/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java b/container-test/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java similarity index 100% rename from container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java rename to container-test/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java diff --git a/container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java b/container-test/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java similarity index 100% rename from container-test2/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java rename to container-test/example-webapp/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java diff --git a/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml b/container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml similarity index 100% rename from container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml rename to container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml diff --git a/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml b/container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml similarity index 100% rename from container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml rename to container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml diff --git a/container-test/src/main/webapp/WEB-INF/urlrewrite.xml b/container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml similarity index 100% rename from container-test/src/main/webapp/WEB-INF/urlrewrite.xml rename to container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml diff --git a/container-test2/example-webapp/src/main/webapp/WEB-INF/web.xml b/container-test/example-webapp/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from container-test2/example-webapp/src/main/webapp/WEB-INF/web.xml rename to container-test/example-webapp/src/main/webapp/WEB-INF/web.xml diff --git a/container-test/src/main/webapp/echo.jsp b/container-test/example-webapp/src/main/webapp/echo.jsp similarity index 100% rename from container-test/src/main/webapp/echo.jsp rename to container-test/example-webapp/src/main/webapp/echo.jsp diff --git a/container-test/src/main/webapp/gzip-me.jsp b/container-test/example-webapp/src/main/webapp/gzip-me.jsp similarity index 100% rename from container-test/src/main/webapp/gzip-me.jsp rename to container-test/example-webapp/src/main/webapp/gzip-me.jsp diff --git a/container-test/src/main/webapp/mod/index.jsp b/container-test/example-webapp/src/main/webapp/mod/index.jsp similarity index 100% rename from container-test/src/main/webapp/mod/index.jsp rename to container-test/example-webapp/src/main/webapp/mod/index.jsp diff --git a/container-test/src/main/webapp/no-decode-test-D%25%2cD.jsp b/container-test/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp similarity index 100% rename from container-test/src/main/webapp/no-decode-test-D%25%2cD.jsp rename to container-test/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp diff --git a/container-test/src/main/webapp/products.jsp b/container-test/example-webapp/src/main/webapp/products.jsp similarity index 100% rename from container-test/src/main/webapp/products.jsp rename to container-test/example-webapp/src/main/webapp/products.jsp diff --git a/container-test/src/main/webapp/settest.jsp b/container-test/example-webapp/src/main/webapp/settest.jsp similarity index 100% rename from container-test/src/main/webapp/settest.jsp rename to container-test/example-webapp/src/main/webapp/settest.jsp diff --git a/container-test/src/main/webapp/test/filterRedirector.jsp b/container-test/example-webapp/src/main/webapp/test/filterRedirector.jsp similarity index 100% rename from container-test/src/main/webapp/test/filterRedirector.jsp rename to container-test/example-webapp/src/main/webapp/test/filterRedirector.jsp diff --git a/container-test2/example-webapp/src/main/webapp/test/test.jsp b/container-test/example-webapp/src/main/webapp/test/test.jsp similarity index 100% rename from container-test2/example-webapp/src/main/webapp/test/test.jsp rename to container-test/example-webapp/src/main/webapp/test/test.jsp diff --git a/container-test/pom.xml b/container-test/pom.xml deleted file mode 100644 index da412149..00000000 --- a/container-test/pom.xml +++ /dev/null @@ -1,151 +0,0 @@ - - - 4.0.0 - org.tuckey - urlrewritefilter-container-test - war - 5.0.0 - UrlRewriteFilter Container Tests - http://www.tuckey.org/urlrewrite/ - 2001 - Integration tests for UrlRewriteFilter - - Paul Tuckey - - - - - BSD - http://www.opensource.org/licenses/bsd-license.php - repo - - - - - - Paul Tuckey - - - - - webapp - - - maven-compiler-plugin - 2.5.1 - - - org.apache.maven.plugins - maven-war-plugin - 3.3.1 - - - - WEB-INF - target - - urlrewrite-generated.xml - - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 2.12 - - - - integration-test - verify - - - - - - maven-surefire-plugin - 2.12 - - - org.codehaus.cargo - cargo-maven2-plugin - 1.6.5 - - - ${cargo.maven.containerId} - - ${cargo.maven.containerUrl} - - ${project.build.directory}/${cargo.maven.containerId}/out.log - - - ${project.build.directory}/${cargo.maven.containerId} - - - - - - start-container - pre-integration-test - - start - - - - stop-container - post-integration-test - - stop - - - - - - - - - - org.tuckey - urlrewritefilter - 4.0.4 - - - junit - junit - 4.13.2 - test - - - javax.servlet - servlet-api - 2.4 - provided - - - commons-httpclient - commons-httpclient - 3.1 - test - - - - - - - maven-surefire-report-plugin - 2.12 - - - - - - UTF-8 - UTF-8 - 1.7 - 1.7 - - - \ No newline at end of file diff --git a/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java b/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java deleted file mode 100644 index 6bf52551..00000000 --- a/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/MockRewriteMatch.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewriteviacontainer; - -import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; - -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import java.io.IOException; - - -/** - * Mock RewriteMatch that can be used for testing. Included here and not in test folder as it needs to be deployed with - * the main library. - * - * @author Paul Tuckey - * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ - */ -public class MockRewriteMatch extends RewriteMatch { - - private static long calledTime = 0; - - public boolean execute(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - calledTime = System.currentTimeMillis(); - try { - Thread.sleep(10); - } catch (InterruptedException e) { - // don't worry - } - return true; - } - - public static long getCalledTime() { - return calledTime; - } -} diff --git a/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java b/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java deleted file mode 100644 index 9085af9e..00000000 --- a/container-test/src/main/java/org/tuckey/web/filters/urlrewriteviacontainer/TestRunObj.java +++ /dev/null @@ -1,248 +0,0 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewriteviacontainer; - -import org.tuckey.web.filters.urlrewrite.extend.RewriteMatch; - -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletConfig; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; - -/** - * RunObject that can be used for testing. Included here and not in test folder as it needs to be deployed with the - * main library. - * - * @author Paul Tuckey - * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ - */ -public class TestRunObj { - private static boolean runCalled; - private static boolean destroyCalled; - private static boolean initCalled; - private static boolean nonDefaultRunCalled; - private static ServletConfig servletConfig; - - private static int createdCount = 0; - private static String paramStr = null; - private static long runWithChainParamAfterDoFilter = 0; - - public TestRunObj() { - createdCount++; - } - - public void run(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - runCalled = true; - - PrintWriter sos = httpServletResponse.getWriter(); - if (sos == null) return; - sos.print("this is " + TestRunObj.class.getName()); - sos.close(); - } - - - public MockRewriteMatch runWithReturnedObj(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - return new MockRewriteMatch(); - } - - public void nonDefaultRun(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - nonDefaultRunCalled = true; - } - - public String runThatReturns(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - return "aaabbb"; - } - - public String runWithParam(int i) - throws ServletException, IOException { - paramStr = "" + i; - return paramStr; - } - - public String runWithNoParams() - throws ServletException, IOException { - paramStr = "[no params]"; - return paramStr; - } - - public String runWithChainParam(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain c) - throws ServletException, IOException { - paramStr = "" + c; - c.doFilter(httpServletRequest, httpServletResponse); - try { - Thread.sleep(10); - } catch (InterruptedException e) { - // - } - runWithChainParamAfterDoFilter = System.currentTimeMillis(); - return paramStr; - } - - public static long getRunWithChainParamAfterDoFilter() { - return runWithChainParamAfterDoFilter; - } - - public String runWithPrimitiveParam(int i, char c, double d, float f, short s, byte b, boolean b2, String s2) - throws ServletException, IOException { - paramStr = i + "," + c + "," + d + "," + f + "," + s + "," + b + "," + b2 + "," + s2; - return paramStr; - } - - public String runWithObjParam(Integer i, Character c, Double d, Float f, Short s, Byte b, Boolean b2, String s2) - throws ServletException, IOException { - paramStr = i + "," + c + "," + d + "," + f + "," + s + "," + b + "," + b2 + "," + s2; - return paramStr; - } - - public static String getParamStr() { - return paramStr; - } - - public void runNullPointerException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - exceptionGenerator.doNullPointer(); - } - - public void runRuntiumeException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - exceptionGenerator.doRuntime(); - } - - public void runServletException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - exceptionGenerator.doServlet(); - } - - public void runIOException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws ServletException, IOException { - exceptionGenerator.doIO(); - } - - public void runCustomException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) - throws TestExceptionGenerator.CustomException { - exceptionGenerator.doCustom(); - } - - TestExceptionGenerator exceptionGenerator = new TestExceptionGenerator(); - - private class TestExceptionGenerator { - public void doNullPointer() { - String aaa = null; - // YES we WANT a null pointer here - aaa.toLowerCase(); - } - - public void doRuntime() { - throw new RuntimeException("shit!"); - } - - public void doServlet() throws ServletException { - throw new ServletException("serv"); - } - - public void doIO() throws IOException { - throw new IOException("me i.o. has gone crazy"); - } - - public void doCustom() throws CustomException { - throw new CustomException(); - } - - public class CustomException extends Exception { - - } - } - - public RewriteMatch trialException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, - ClassNotFoundException e) { - return new MockRewriteMatch(); - } - - /** - * Do not delete! used in RunTest. - */ - private void privateRun(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { - // do nothing - } - - public void destroy() { - destroyCalled = true; - } - - public void init(ServletConfig config) throws ServletException { - servletConfig = config; - initCalled = true; - } - - public static boolean isRunCalled() { - return runCalled; - } - - public static int getCreatedCount() { - return createdCount; - } - - public static void resetTestFlags() { - createdCount = 0; - runCalled = false; - destroyCalled = false; - initCalled = false; - nonDefaultRunCalled = false; - servletConfig = null; - } - - public static ServletConfig getTestServletConfig() { - return servletConfig; - } - - public static boolean isDestroyCalled() { - return destroyCalled; - } - - public static boolean isInitCalled() { - return initCalled; - } - - public static boolean isNonDefaultRunCalled() { - return nonDefaultRunCalled; - } -} diff --git a/container-test/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml b/container-test/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml deleted file mode 100644 index 9bdfb77d..00000000 --- a/container-test/src/main/webapp/WEB-INF/urlrewrite-decode-none.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - utf test - /utf/(m%C4%81ori)/ - %{context-path}/utf-redir/done/$1/ - - - - Proxy - ^/no-decode-test/(.*)$ - /no-decode-test-$1.jsp - - - - ^/query-string-no-decode/(.*)$ - http://query-string-no-decode-result.com/?q=$1&another=${unescape:$1} - - - \ No newline at end of file diff --git a/container-test/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml b/container-test/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml deleted file mode 100644 index 3fa2bb82..00000000 --- a/container-test/src/main/webapp/WEB-INF/urlrewrite-decode-utf8.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - utf test - ^/utf/māori/$ - %{context-path}/utf-redir/done/ - - - \ No newline at end of file diff --git a/container-test/src/main/webapp/WEB-INF/web.xml b/container-test/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 5d57210c..00000000 --- a/container-test/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - test - test context - - - UrlRewriteFilter - org.tuckey.web.filters.urlrewrite.UrlRewriteFilter - - logLevel - debug - - - allowConfSwapViaHttp - true - - - - - UrlRewriteFilter-mod - org.tuckey.web.filters.urlrewrite.UrlRewriteFilter - - logLevel - debug - - - statusPath - /mod/rewrite-status - - - modRewriteConfText - - - - - - - UrlRewriteFilter-mod - /mod/* - - - - UrlRewriteFilter - /* - - - - - - - - - - diff --git a/container-test/src/main/webapp/test/test.jsp b/container-test/src/main/webapp/test/test.jsp deleted file mode 100644 index 543a0b47..00000000 --- a/container-test/src/main/webapp/test/test.jsp +++ /dev/null @@ -1,7 +0,0 @@ -<%-- Test JSP used by the TestServletTestCase test class to test --%> -<%-- RequestDispatcher call. --%> - - - Hello ! - - \ No newline at end of file diff --git a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java deleted file mode 100644 index 1ec6c14e..00000000 --- a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewriteviacontainer; - -import junit.framework.TestCase; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.methods.GetMethod; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; - - -public abstract class ContainerTestBase extends TestCase { - - private String baseUrl = "http://127.0.0.1:8080"; - protected HttpClient client = new HttpClient(); - private File systemPropBaseReportsDir = new File("container-test", "reports"); - private String containerId = "test"; - - protected void setUp() throws Exception { - String containerId = System.getProperty("test.container.id"); - if (containerId != null) { - this.containerId = containerId; - } - String systemPropBaseUrl = System.getProperty("test.base.url"); - if (systemPropBaseUrl != null) { - baseUrl = systemPropBaseUrl; - } - String systemPropBaseReports = System.getProperty("test.base.reports"); - if (systemPropBaseReports != null) { - systemPropBaseReportsDir = new File(systemPropBaseReports); - } - System.err.println("systemPropBaseReportsDir: " + systemPropBaseReportsDir); - - GetMethod method = new GetMethod(getBaseUrl() + "/rewrite-status/?conf=/WEB-INF/" + getConf()); - client.executeMethod(method); - super.setUp(); - } - - protected String getBaseUrl() { - return baseUrl + "/" + getApp(); - } - - protected void recordRewriteStatus() throws IOException { - GetMethod method = new GetMethod(baseUrl + "/" + getApp() + "/rewrite-status"); - method.setFollowRedirects(false); - client.executeMethod(method); - File statusFile = new File(containerId + "-" + getApp() + "-" + getConf() + "-rewrite-status.html"); - //noinspection ResultOfMethodCallIgnored - if ( statusFile.canWrite() && statusFile.createNewFile() ) { // some containers don't let us do this - PrintWriter pw = new PrintWriter(statusFile); - pw.print(method.getResponseBodyAsString()); - pw.close(); - System.out.println("status saved to " + statusFile.getAbsolutePath()); - } - } - - abstract protected String getApp(); - - protected String getConf() { - return "urlrewrite.xml"; - } - - public String getContainerId() { - return containerId; - } -} diff --git a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java deleted file mode 100644 index 1e21e10e..00000000 --- a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.tuckey.web.filters.urlrewriteviacontainer; - - -import org.apache.commons.httpclient.methods.GetMethod; - -import jakarta.servlet.ServletException; -import java.io.IOException; -import java.net.URLEncoder; - -/** - * - */ -public class WebappDecodeNoneIT extends ContainerTestBase { - - protected String getApp() { - return "webapp"; - } - - protected String getConf() { - return "urlrewrite-decode-none.xml"; - } - - public void testSetup() throws IOException { - super.recordRewriteStatus(); - } - - - /** - * note, had trouble keeping true utf (multi byte) chars as cvs buggers them up! - */ - public void testTestUtf() throws ServletException, IOException { - if ( "orion2.0.5".equals(getContainerId())) return; // orion not supported - String encodedStr = URLEncoder.encode("m\u0101ori", "UTF8"); - GetMethod method = new GetMethod(getBaseUrl() + "/utf/" + encodedStr + "/"); - method.setRequestHeader("Accept-Encoding", "utf8"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertNotNull("no location header", method.getResponseHeader("Location")); - assertEquals(getBaseUrl() + "/utf-redir/done/" + encodedStr + "/", method.getResponseHeader("Location").getValue()); - } - - public void testNoDecode() throws IOException { - if ( "orion2.0.5".equals(getContainerId())) return; // jsp's with % in path not supported - if ( "tomcat-4.1.31".equals(getContainerId())) return; // jsp's with % in path not supported - - GetMethod method = new GetMethod(getBaseUrl() + "/no-decode-test/D%25%2cD"); - client.executeMethod(method); - assertEquals("this is no-decode-test target jsp", method.getResponseBodyAsString()); - } - - public void testQueryStringNoDecode() throws IOException { - if ( "orion2.0.5".equals(getContainerId())) return; // orion cannot correctly encode & into %26 - - GetMethod method = new GetMethod(getBaseUrl() + "/query-string-no-decode/jack+%26+jones"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals("http://query-string-no-decode-result.com/?q=jack+%26+jones&another=jack & jones", method.getResponseHeader("Location").getValue()); - } - - -} \ No newline at end of file diff --git a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java deleted file mode 100644 index acf56ffd..00000000 --- a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.tuckey.web.filters.urlrewriteviacontainer; - - -import org.apache.commons.httpclient.methods.GetMethod; - -import jakarta.servlet.ServletException; -import java.io.IOException; -import java.net.URLEncoder; - -/** - * todo: need to do a few tests - *

- * with eocode-using not set (ie, browser encoding used, step down to utf8) - * with eocode-using set to utf (force always with a specific decoding) - * with eocode-using not set to null (never decode) - * accept-encoding header? - *

- *

- * don't decode anything - null - * browser then utf then default - default browser,utf - * browser then don't decode - default browser,null - * always utf - utf - *

- *

- * options: browser (may fail), enc (unlikely fail) - */ -public class WebappDecodeUtf8IT extends ContainerTestBase { - - protected String getApp() { - return "webapp"; - } - - protected String getConf() { - return "urlrewrite-decode-utf8.xml"; - } - - public void testSetup() throws IOException { - super.recordRewriteStatus(); - } - - - /** - * - */ - public void testTestUtf() throws ServletException, IOException { - String utfSampleString = "m\u0101ori"; - GetMethod method = new GetMethod(getBaseUrl() + "/utf/" + URLEncoder.encode(utfSampleString, "UTF8") + "/"); - method.setRequestHeader("Accept-Encoding", "utf8"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals(getBaseUrl() + "/utf-redir/done/", method.getResponseHeader("Location").getValue()); - } - - - - -} diff --git a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java deleted file mode 100644 index 668c7092..00000000 --- a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java +++ /dev/null @@ -1,170 +0,0 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewriteviacontainer; - -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.methods.GetMethod; -import org.tuckey.web.filters.urlrewrite.utils.StringUtils; -import org.xml.sax.SAXException; - -import jakarta.servlet.ServletException; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.zip.GZIPInputStream; - - -/** - * @author Paul Tuckey - * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ - */ -public class WebappHttpIT extends ContainerTestBase { - - protected String getApp() { - return "webapp"; - } - - public void testStatusRecord() throws IOException { - super.recordRewriteStatus(); - } - - public void testProduct() throws IOException, SAXException, InterruptedException { - GetMethod method = new GetMethod(getBaseUrl() + "/products/987"); - client.executeMethod(method); - assertEquals("product 987", method.getResponseBodyAsString()); - } - - - public void testSimpleDistEx() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/test/status/"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals(getBaseUrl() + "/rewrite-status", method.getResponseHeader("Location").getValue()); - } - - public void testBasicSets() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/settest/674"); - client.executeMethod(method); - assertNotNull(method.getResponseHeader("cache-control")); - assertEquals("testsession: hello!, " + - "param.settest1: 674, " + - "method: DELETE", method.getResponseBodyAsString()); - } - - public void testMultipleProduct() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/multiple/products/987"); - client.executeMethod(method); - assertEquals("product 987", method.getResponseBodyAsString()); - } - - public void testNullTo() throws ServletException, IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/hideme/anb.jsp;dsaddd?asdasds#sdsfd"); - client.executeMethod(method); - assertEquals("should have status set", 403, method.getStatusCode()); - String CONTENT = "

some content

"; - assertFalse("should not output above content", CONTENT.equals(StringUtils.trim(method.getResponseBodyAsString()))); - } - - public void testYear() throws ServletException, IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/time/year/current"); - client.executeMethod(method); - assertEquals("echo yearisbetween1970and3000", method.getResponseBodyAsString()); - } - - public void testTestAxis() throws ServletException, IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/services/blah?qwerty"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals(getBaseUrl() + "/axis/services/blah", method.getResponseHeader("Location").getValue()); - } - - public void testTestErik() throws ServletException, IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/eriktest/hi.ho"); - method.setFollowRedirects(false); - method.addRequestHeader(new Header("host", "blah.com")); - client.executeMethod(method); - assertEquals("http://www.example.com/context/hi.ho", method.getResponseHeader("Location").getValue()); - } - - public void testTestEncode() throws ServletException, IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/went%20to%20bahamas/"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals(getBaseUrl() + "/jamaica/", method.getResponseHeader("Location").getValue()); - } - - public void testSimpleRun() throws ServletException, IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/run/test/test1"); - client.executeMethod(method); - assertEquals("this is " + TestRunObj.class.getName(), method.getResponseBodyAsString()); - } - - public void testQueryStringEscape() throws IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/query-string-escape/jack+%26+jones"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals("http://query-string-escape-result.com/?q=jack%2B%26%2Bjones&another=jack+&+jones", method.getResponseHeader("Location").getValue()); - } - - public void testGzip() throws IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/gzip-me.jsp"); - method.addRequestHeader("accept-encoding", "gzip"); - client.executeMethod(method); - assertEquals("gzip", method.getResponseHeader("Content-Encoding").getValue()); - assertEquals("hello world hello world hello world", inflateGzipToString(method.getResponseBodyAsStream())); - } - - /** - * inflate a gzipped inputstream and return it as a string. - */ - private String inflateGzipToString(InputStream is) throws IOException { - GZIPInputStream gis = new GZIPInputStream(is); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - while (true) { - int bytesRead = gis.read(buffer); - if (bytesRead == -1) break; - os.write(buffer, 0, bytesRead); - } - return os.toString(); - } - - public void testSampleAnnotation() throws IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/do-something/7"); - client.executeMethod(method); - assertEquals(method.getResponseBodyAsString(), "AnnotatedClassSample id=7"); - } - -} diff --git a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java b/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java deleted file mode 100644 index 4f6401af..00000000 --- a/container-test/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (c) 2005-2007, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewriteviacontainer; - -import org.apache.commons.httpclient.methods.GetMethod; -import org.xml.sax.SAXException; - -import jakarta.servlet.ServletException; -import java.io.IOException; - - -/** - * @author Paul Tuckey - * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ - */ -public class WebappModStyleHttpIT extends ContainerTestBase { - - protected String getApp() { - return "webapp/mod"; - } - - public void testStatusRecord() throws IOException { - super.recordRewriteStatus(); - } - - public void testSimpleTest() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/index.jsp"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals("this is index.jsp", method.getResponseBodyAsString()); - } - - public void testSimpleTestRewrite() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/simple/test"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertEquals("this is index.jsp", method.getResponseBodyAsString()); - } - - public void testStatus1() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/rewrite-status"); - method.setFollowRedirects(false); - client.executeMethod(method); - assertTrue(method.getResponseBodyAsString().contains("Running Status")); - assertFalse(method.getResponseBodyAsString().contains("Error")); - } - -} diff --git a/container-test2/test-with-testcontainters/pom.xml b/container-test/test-with-testcontainters/pom.xml similarity index 96% rename from container-test2/test-with-testcontainters/pom.xml rename to container-test/test-with-testcontainters/pom.xml index e2afa6bf..0b39ec5b 100644 --- a/container-test2/test-with-testcontainters/pom.xml +++ b/container-test/test-with-testcontainters/pom.xml @@ -2,14 +2,14 @@ 4.0.0 org.tuckey - urlrewritefilter-container-test2 + urlrewritefilter-container-test jar 17 17 6.0.0 - UrlRewriteFilter Container Tests2 + UrlRewriteFilter Container Tests http://www.tuckey.org/urlrewrite/ 2001 Integration tests for UrlRewriteFilter diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java b/container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java similarity index 100% rename from container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java rename to container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java b/container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java similarity index 100% rename from container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java rename to container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java b/container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java similarity index 100% rename from container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java rename to container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java b/container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java similarity index 100% rename from container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java rename to container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java b/container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java similarity index 100% rename from container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java rename to container-test/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java diff --git a/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml b/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml deleted file mode 100644 index dfcff1da..00000000 --- a/container-test2/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml +++ /dev/null @@ -1,501 +0,0 @@ - - - - - - - - - The rule means that requests to /test/status/ will be redirected to /rewrite-status - the url will be rewritten. - - /test/status/ - %{context-path}/rewrite-status - - - - /spelling/([a-z]+) - /spelling/index.jsp?spell=$1 - - - - gEt - /get/ - /getty/lotsofgetty/ - - - - /products/([0-9]+) - /products.jsp?product_id=$1 - - - - /multiple/products/([0-9]+) - /multiple/products.jsp?product_id=$1 - - - - /multiple/(.*) - /$1 - - - - ^/settest/([0-9]+)$ - hello! - none-fool - $1 - DELETE - /settest.jsp - - - - - http method test - - PROPFIND - PUT - /.* - /go-away-nasty-methods.html - - - - 1970 - 2020 - /time/year/current - /echo.jsp?echo=yearisbetween1970and3000 - - - - ^/services/(.*) - %{context-path}/axis/services/$1 - - - - ^/weblog/([0-9]+)/([0-9]+)/$ - /weblog/index.jsp?year=$1&month=$2 - - - - Domain Name Check - www.example.com - /eriktest(.*) - http://www.example.com/context$1 - - - - 403 null Check - ^/hideme/.*$ - 403 - null - - - - encode test - /went to bahamas/ - %{context-path}/bahamas/ - - - - Bad referers test - - - Prevent vermin from appearing in your logs by denying nasty referers - - - ^http://www\.badguys\.com/.*$ - /(.*) - 403 - null - - - - - admin - bigboss - ^/admin/(.*)$ - /go-away-please.html - - - - - Simple Run Test - ^/run/test/(.*)$ - - null - - - - - - - - - - - - - Canonical URLs - - On some webservers there are more than one URL for a resource. Usually there are canonical URLs (which - should be actually used and distributed) and those which are just shortcuts, internal ones, etc. Independent - of which URL the user supplied with the request he should finally see the canonical one only. - - We do an external HTTP redirect for all non-canonical URLs to fix them in the location view of the Browser - and for all subsequent requests. In the example ruleset below we replace /~user by the canonical /u/user and - fix a missing trailing slash for /u/user. - - RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R] - RewriteRule ^/([uge])/([^/]+)$ /$1/$2/ [R] - - ^/~([^/]+)/?(.*) - /u/$1/$2 - - - ^/([uge])/([^/]+)$ - /$1/$2/ - - - - - Canonical Hostnames - - The goal of this rule is to force the use of a particular hostname, in preference to other hostnames which - may be used to reach the same site. For example, if you wish to force the use of www.example.com instead of - example.com, you might use a variant of the following recipe. - - RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC] - RewriteCond %{HTTP_HOST} !^$ - RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R] - - !^fully\.qualified\.domain\.name - ^$ - ^/(.*) - http://fully.qualified.domain.name/$1 - - - - - Moved DocumentRoot - - Usually the DocumentRoot of the webserver directly relates to the URL "/". But often this data is not - really of top-level priority, it is perhaps just one entity of a lot of data pools. For instance at our - Intranet sites there are /e/www/ (the homepage for WWW), /e/sww/ (the homepage for the Intranet) etc. Now - because the data of the DocumentRoot stays at /e/www/ we had to make sure that all inlined images and other - stuff inside this data pool work for subsequent requests. - - We just redirect the URL / to /e/www/. While is seems trivial it is actually trivial with mod_rewrite, only. - Because the typical old mechanisms of URL Aliases (as provides by mod_alias and friends) only used prefix - matching. With this you cannot do such a redirection because the DocumentRoot is a prefix of all URLs. - With mod_rewrite it is really trivial: - - RewriteRule ^/$ /e/www/ [R] - - ^/$ - /e/www/ - - - - - Trailing Slash Problem - - Every webmaster can sing a song about the problem of the trailing slash on URLs referencing directories. - If they are missing, the server dumps an error, because if you say /~quux/foo instead of /~quux/foo/ then - the server searches for a file named foo. And because this file is a directory it complains. Actually it - tries to fix it itself in most of the cases, but sometimes this mechanism need to be emulated by you. For - instance after you have done a lot of complicated URL rewritings to CGI scripts etc. - - The solution to this subtle problem is to let the server add the trailing slash automatically. To do this - correctly we have to use an external redirect, so the browser correctly requests subsequent images etc. If - we only did a internal rewrite, this would only work for the directory page, but would go wrong when any - images are included into this page with relative URLs, because the browser would request an in-lined object. - For instance, a request for image.gif in /~quux/foo/index.html would become /~quux/image.gif without the - external redirect! - - ^/~quux/foo$ - /~quux/foo/ - - - - - Move Homedirs to Different Webserver - - Many webmasters have asked for a solution to the following situation: They wanted to redirect just all - homedirs on a webserver to another webserver. They usually need such things when establishing a newer - webserver which will replace the old one over time. - - The solution is trivial with mod_rewrite (and urlrewrite filter). On the old webserver we just redirect all - /~user/anypath URLs to http://newserver/~user/anypath. - - RewriteRule ^/~(.+) http://newserver/~$1 [R,L] - - ^/~(.+) - http://newserver/~$1 - - - - - Structured Homedirs - - Some sites with thousands of users usually use a structured homedir layout, i.e. each homedir is in a - subdirectory which begins for instance with the first character of the username. So, /~foo/anypath is - /home/f/foo/.www/anypath while /~bar/anypath is /home/b/bar/.www/anypath. - - We use the following ruleset to expand the tilde URLs into exactly the above layout. - - RewriteRule ^/~(([a-z])[a-z0-9]+)(.*) /home/$2/$1/.www$3 - - ^/~(([a-z])[a-z0-9]+)(.*) - /home/$2/$1/.www$3 - - - - - Redirect Homedirs For Foreigners - - We want to redirect homedir URLs to another webserver www.somewhere.com when the requesting user does not - stay in the local domain ourdomain.com. This is sometimes used in virtual host contexts. - - Just a rewrite condition: - - RewriteCond %{REMOTE_HOST} !^.+\.ourdomain\.com$ - RewriteRule ^(/~.+) http://www.somewhere.com/$1 [R,L] - - !^.+\.ourdomain\.com$ - ^(/~.+) - http://www.somewhere.com/$1 - - - - - Time-Dependent Rewriting - - When tricks like time-dependent content should happen a lot of webmasters still use CGI scripts which do for - instance redirects to specialized pages. How can it be done via mod_rewrite? - - There are a lot of types in conjunction with operators we can do time-dependent redirects: - - RewriteCond %{TIME_HOUR}%{TIME_MIN} >0700 - RewriteCond %{TIME_HOUR}%{TIME_MIN} <1900 - RewriteRule ^foo\.html$ foo.day.html - RewriteRule ^foo\.html$ foo.night.html - - 7 - 19 - ^foo\.html$ - foo.day.html - - - ^foo\.html$ - foo.night.html - - - - - - - Assume we have recently renamed the page foo.html to bar.html and now want to provide the old URL for - backward compatibility. Actually we want that users of the old URL even not recognize that the pages was - renamed. - - We rewrite the old URL to the new one internally via the following rule: - - RewriteBase /~quux/ - RewriteRule ^foo\.html$ bar.html - - ^/~quux/foo\.html$ - /~quux/bar.html - - - - - From Old to New (extern) - - Assume again that we have recently renamed the page foo.html to bar.html and now want to provide the old URL - for backward compatibility. But this time we want that the users of the old URL get hinted to the new one, - i.e. their browsers Location field should change, too. - - We force a HTTP redirect to the new URL which leads to a change of the browsers and thus the users view: - - RewriteBase /~quux/ - RewriteRule ^foo\.html$ bar.html [R] - - ^/~quux/foo\.html$ - /~quux/bar.html - - - - - Browser Dependent Content - - At least for important top-level pages it is sometimes necessary to provide the optimum of browser dependent - content, i.e. one has to provide a maximum version for the latest Netscape variants, a minimum version for - the Lynx browsers and a average feature version for all others. - - We cannot use content negotiation because the browsers do not provide their type in that form. Instead we - have to act on the HTTP header "User-Agent". The following condig does the following: If the HTTP header - "User-Agent" begins with "Mozilla/3", the page foo.html is rewritten to foo.NS.html and and the rewriting - stops. If the browser is "Lynx" or "Mozilla" of version 1 or 2 the URL becomes foo.20.html. All other - browsers receive page foo.32.html. This is done by the following ruleset: - - RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.* - RewriteRule ^foo\.html$ foo.NS.html [L] - - RewriteCond %{HTTP_USER_AGENT} ^Lynx/.* [OR] - RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12].* - RewriteRule ^foo\.html$ foo.20.html [L] - - RewriteRule ^foo\.html$ foo.32.html [L] - - ^Mozilla/3.* - ^foo\.html$ - foo.NS.html - - - ^Lynx/.* - ^Mozilla/[12].* - ^foo\.html$ - foo.20.html - - - ^foo\.html$ - foo.32.html - - - - - From Static to Dynamic - - How can we transform a static page foo.html into a dynamic variant foo.cgi in a seamless way, i.e. without - notice by the browser/user. - - We just rewrite the URL to the jsp/servlet and force the correct MIME-type so it gets really run as - a CGI-script. This way a request to /~quux/foo.html internally leads to the invocation of /~quux/foo.jsp. - - RewriteBase /~quux/ - RewriteRule ^foo\.html$ foo.cgi [T=application/x-httpd-cgi] - - ^/~quux/foo\.html$ - /~quux/foo.jsp - - - - Blocking of Robots - - How can we block a really annoying robot from retrieving pages of a specific webarea? A /robots.txt file - containing entries of the "Robot Exclusion Protocol" is typically not enough to get rid of such a robot. - - We use a ruleset which forbids the URLs of the webarea /~quux/foo/arc/ (perhaps a very deep directory - indexed area where the robot traversal would create big server load). We have to make sure that we forbid - access only to the particular robot, i.e. just forbidding the host where the robot runs is not enough. - This would block users from this host, too. We accomplish this by also matching the User-Agent HTTP header - information. - - RewriteCond %{HTTP_USER_AGENT} ^NameOfBadRobot.* - RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.[8-9]$ - RewriteRule ^/~quux/foo/arc/.+ - [F] - - ^NameOfBadRobot.* - ^123\.45\.67\.[8-9]$ - ^/~quux/foo/arc/.+ - 403 - null - - - - - Blocked Inline-Images - - Assume we have under http://www.quux-corp.de/~quux/ some pages with inlined GIF graphics. These graphics are - nice, so others directly incorporate them via hyperlinks to their pages. We don't like this practice because - it adds useless traffic to our server. - - While we cannot 100% protect the images from inclusion, we can at least restrict the cases where the browser - sends a HTTP Referer header. - - RewriteCond %{HTTP_REFERER} !^$ - RewriteCond %{HTTP_REFERER} !^http://www.quux-corp.de/~quux/.*$ [NC] - RewriteRule .*\.gif$ - [F] - - ^$ - ^http://www.quux-corp.de/~quux/.*$ - .*\.gif$ - 403 - null - - - Blocked Inline-Images example 2 - - RewriteCond %{HTTP_REFERER} !^$ - RewriteCond %{HTTP_REFERER} !.*/foo-with-gif\.html$ - RewriteRule ^inlined-in-foo\.gif$ - [F] - - ^$ - .*/foo-with-gif\.html$ - ^inlined-in-foo\.gif$ - 403 - - - - - /bahamas/ - /jamaica/ - - - - ^/query-string-escape/(.*)$ - http://query-string-escape-result.com/?q=${escape:$1}&another=$1 - - - - ^/gzip-me.jsp$ - - - - - diff --git a/container-test2/example-webapp/src/main/webapp/echo.jsp b/container-test2/example-webapp/src/main/webapp/echo.jsp deleted file mode 100644 index c78b4773..00000000 --- a/container-test2/example-webapp/src/main/webapp/echo.jsp +++ /dev/null @@ -1 +0,0 @@ -echo <%= request.getParameter("echo") %> \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/gzip-me.jsp b/container-test2/example-webapp/src/main/webapp/gzip-me.jsp deleted file mode 100644 index 2496d27b..00000000 --- a/container-test2/example-webapp/src/main/webapp/gzip-me.jsp +++ /dev/null @@ -1 +0,0 @@ -hello world hello world hello world \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/mod/index.jsp b/container-test2/example-webapp/src/main/webapp/mod/index.jsp deleted file mode 100644 index 7727d0fc..00000000 --- a/container-test2/example-webapp/src/main/webapp/mod/index.jsp +++ /dev/null @@ -1 +0,0 @@ -this is index.jsp \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp b/container-test2/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp deleted file mode 100644 index 277e1123..00000000 --- a/container-test2/example-webapp/src/main/webapp/no-decode-test-D%25%2cD.jsp +++ /dev/null @@ -1 +0,0 @@ -this is no-decode-test target jsp \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/products.jsp b/container-test2/example-webapp/src/main/webapp/products.jsp deleted file mode 100644 index d457064f..00000000 --- a/container-test2/example-webapp/src/main/webapp/products.jsp +++ /dev/null @@ -1 +0,0 @@ -product <%= request.getParameter("product_id") %> \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/settest.jsp b/container-test2/example-webapp/src/main/webapp/settest.jsp deleted file mode 100644 index 507e0fcf..00000000 --- a/container-test2/example-webapp/src/main/webapp/settest.jsp +++ /dev/null @@ -1 +0,0 @@ -testsession: <%= session.getAttribute("testsession") %>, param.settest1: <%= request.getParameter("settest1") %>, method: <%= request.getMethod() %> \ No newline at end of file diff --git a/container-test2/example-webapp/src/main/webapp/test/filterRedirector.jsp b/container-test2/example-webapp/src/main/webapp/test/filterRedirector.jsp deleted file mode 100644 index e69de29b..00000000