tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1239048 - in /tomcat/trunk: java/org/apache/catalina/core/ java/org/apache/catalina/servlets/ java/org/apache/catalina/ssi/ java/org/apache/catalina/util/ java/org/apache/naming/resources/ java/org/apache/tomcat/util/http/ res/checkstyle/ ...
Date Wed, 01 Feb 2012 10:47:18 GMT
Author: markt
Date: Wed Feb  1 10:47:17 2012
New Revision: 1239048

URL: http://svn.apache.org/viewvc?rev=1239048&view=rev
Log:
Refactor to remove the circular dependency between o.a.catalina and
o.a.naming

Added:
    tomcat/trunk/java/org/apache/tomcat/util/http/RequestUtil.java
    tomcat/trunk/test/org/apache/tomcat/util/http/TestRequestUtil.java
Modified:
    tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
    tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java
    tomcat/trunk/java/org/apache/catalina/ssi/SSIServletExternalResolver.java
    tomcat/trunk/java/org/apache/catalina/ssi/SSIServletRequestUtil.java
    tomcat/trunk/java/org/apache/catalina/util/RequestUtil.java
    tomcat/trunk/java/org/apache/naming/resources/FileDirContext.java
    tomcat/trunk/res/checkstyle/org-import-control.xml
    tomcat/trunk/test/org/apache/catalina/util/TestRequestUtil.java

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=1239048&r1=1239047&r2=1239048&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java Wed Feb  1 10:47:17
2012
@@ -67,7 +67,6 @@ import org.apache.catalina.Service;
 import org.apache.catalina.Wrapper;
 import org.apache.catalina.connector.Connector;
 import org.apache.catalina.deploy.FilterDef;
-import org.apache.catalina.util.RequestUtil;
 import org.apache.catalina.util.ResourceSet;
 import org.apache.catalina.util.ServerInfo;
 import org.apache.naming.resources.DirContextURLStreamHandler;
@@ -75,6 +74,7 @@ import org.apache.naming.resources.Resou
 import org.apache.tomcat.util.ExceptionUtils;
 import org.apache.tomcat.util.buf.CharChunk;
 import org.apache.tomcat.util.buf.MessageBytes;
+import org.apache.tomcat.util.http.RequestUtil;
 import org.apache.tomcat.util.http.mapper.MappingData;
 import org.apache.tomcat.util.res.StringManager;
 

Modified: tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java?rev=1239048&r1=1239047&r2=1239048&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java Wed Feb  1 10:47:17
2012
@@ -51,13 +51,13 @@ import javax.xml.parsers.ParserConfigura
 
 import org.apache.catalina.util.DOMWriter;
 import org.apache.catalina.util.MD5Encoder;
-import org.apache.catalina.util.RequestUtil;
 import org.apache.catalina.util.XMLWriter;
 import org.apache.naming.resources.CacheEntry;
 import org.apache.naming.resources.Resource;
 import org.apache.naming.resources.ResourceAttributes;
 import org.apache.tomcat.util.buf.B2CConverter;
 import org.apache.tomcat.util.http.FastHttpDateFormat;
+import org.apache.tomcat.util.http.RequestUtil;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -1581,7 +1581,8 @@ public class WebdavServlet
         }
 
         // Remove url encoding from destination
-        destinationPath = RequestUtil.URLDecode(destinationPath, "UTF8");
+        destinationPath = org.apache.catalina.util.RequestUtil.URLDecode(
+                destinationPath, "UTF8");
 
         int protocolIndex = destinationPath.indexOf("://");
         if (protocolIndex >= 0) {

Modified: tomcat/trunk/java/org/apache/catalina/ssi/SSIServletExternalResolver.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ssi/SSIServletExternalResolver.java?rev=1239048&r1=1239047&r2=1239048&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ssi/SSIServletExternalResolver.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ssi/SSIServletExternalResolver.java Wed Feb  1 10:47:17
2012
@@ -34,9 +34,9 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.catalina.connector.Request;
-import org.apache.catalina.util.RequestUtil;
 import org.apache.coyote.Constants;
 import org.apache.tomcat.util.buf.B2CConverter;
+import org.apache.tomcat.util.http.RequestUtil;
 
 /**
  * An implementation of SSIExternalResolver that is used with servlets.

Modified: tomcat/trunk/java/org/apache/catalina/ssi/SSIServletRequestUtil.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ssi/SSIServletRequestUtil.java?rev=1239048&r1=1239047&r2=1239048&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ssi/SSIServletRequestUtil.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ssi/SSIServletRequestUtil.java Wed Feb  1 10:47:17
2012
@@ -16,11 +16,11 @@
  */
 package org.apache.catalina.ssi;
 
-
 import javax.servlet.RequestDispatcher;
 import javax.servlet.http.HttpServletRequest;
 
-import org.apache.catalina.util.RequestUtil;
+import org.apache.tomcat.util.http.RequestUtil;
+
 public class SSIServletRequestUtil {
     /**
      * Return the relative path associated with this servlet. Taken from

Modified: tomcat/trunk/java/org/apache/catalina/util/RequestUtil.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/RequestUtil.java?rev=1239048&r1=1239047&r2=1239048&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/RequestUtil.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/RequestUtil.java Wed Feb  1 10:47:17 2012
@@ -14,8 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.catalina.util;
 
 import java.io.UnsupportedEncodingException;
@@ -35,7 +33,6 @@ import org.apache.tomcat.util.res.String
  * @author Tim Tye
  * @version $Id$
  */
-
 public final class RequestUtil {
 
 
@@ -93,11 +90,18 @@ public final class RequestUtil {
      * try to perform security checks for malicious input.
      *
      * @param path Relative path to be normalized
+     *
+     * @deprecated Deprecated to resolve a circular package dependency and will
+     *             be removed in Tomcat 8.0.x. Use {@link
+     *             org.apache.tomcat.util.http.RequestUtil#normalize(String)} as
+     *             a replacement.
      */
+    @Deprecated
     public static String normalize(String path) {
-        return normalize(path, true);
+        return org.apache.tomcat.util.http.RequestUtil.normalize(path);
     }
 
+
     /**
      * Normalize a relative URI path that may have relative values ("/./",
      * "/../", and so on ) it it.  <strong>WARNING</strong> - This method is
@@ -106,58 +110,16 @@ public final class RequestUtil {
      *
      * @param path Relative path to be normalized
      * @param replaceBackSlash Should '\\' be replaced with '/'
+     *
+     * @deprecated Deprecated to resolve a circular package dependency and will
+     *             be removed in Tomcat 8.0.x. Use {@link
+     *             org.apache.tomcat.util.http.RequestUtil#normalize(String,
+     *             boolean)} as a replacement.
      */
+    @Deprecated
     public static String normalize(String path, boolean replaceBackSlash) {
-
-        if (path == null)
-            return null;
-
-        // Create a place for the normalized path
-        String normalized = path;
-
-        if (replaceBackSlash && normalized.indexOf('\\') >= 0)
-            normalized = normalized.replace('\\', '/');
-
-        if (normalized.equals("/."))
-            return "/";
-
-        // Add a leading "/" if necessary
-        if (!normalized.startsWith("/"))
-            normalized = "/" + normalized;
-
-        // Resolve occurrences of "//" in the normalized path
-        while (true) {
-            int index = normalized.indexOf("//");
-            if (index < 0)
-                break;
-            normalized = normalized.substring(0, index) +
-                normalized.substring(index + 1);
-        }
-
-        // Resolve occurrences of "/./" in the normalized path
-        while (true) {
-            int index = normalized.indexOf("/./");
-            if (index < 0)
-                break;
-            normalized = normalized.substring(0, index) +
-                normalized.substring(index + 2);
-        }
-
-        // Resolve occurrences of "/../" in the normalized path
-        while (true) {
-            int index = normalized.indexOf("/../");
-            if (index < 0)
-                break;
-            if (index == 0)
-                return (null);  // Trying to go outside our context
-            int index2 = normalized.lastIndexOf('/', index - 1);
-            normalized = normalized.substring(0, index2) +
-                normalized.substring(index + 3);
-        }
-
-        // Return the normalized path that we have completed
-        return (normalized);
-
+        return org.apache.tomcat.util.http.RequestUtil.normalize(path,
+                replaceBackSlash);
     }
 
 

Modified: tomcat/trunk/java/org/apache/naming/resources/FileDirContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/resources/FileDirContext.java?rev=1239048&r1=1239047&r2=1239048&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/naming/resources/FileDirContext.java (original)
+++ tomcat/trunk/java/org/apache/naming/resources/FileDirContext.java Wed Feb  1 10:47:17
2012
@@ -41,9 +41,9 @@ import javax.naming.directory.Modificati
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 
-import org.apache.catalina.util.RequestUtil;
 import org.apache.naming.NamingContextEnumeration;
 import org.apache.naming.NamingEntry;
+import org.apache.tomcat.util.http.RequestUtil;
 
 /**
  * Filesystem Directory Context implementation helper class.

Added: tomcat/trunk/java/org/apache/tomcat/util/http/RequestUtil.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/RequestUtil.java?rev=1239048&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/RequestUtil.java (added)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/RequestUtil.java Wed Feb  1 10:47:17 2012
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.util.http;
+
+public class RequestUtil {
+
+    private RequestUtil() {
+        // Hide default constructor as this is a utility class
+    }
+
+
+    /**
+     * Normalize a relative URI path that may have relative values ("/./",
+     * "/../", and so on ) it it.  <strong>WARNING</strong> - This method is
+     * useful only for normalizing application-generated paths.  It does not
+     * try to perform security checks for malicious input.
+     *
+     * @param path Relative path to be normalized
+     */
+    public static String normalize(String path) {
+        return normalize(path, true);
+    }
+
+
+    /**
+     * Normalize a relative URI path that may have relative values ("/./",
+     * "/../", and so on ) it it.  <strong>WARNING</strong> - This method is
+     * useful only for normalizing application-generated paths.  It does not
+     * try to perform security checks for malicious input.
+     *
+     * @param path Relative path to be normalized
+     * @param replaceBackSlash Should '\\' be replaced with '/'
+     */
+    public static String normalize(String path, boolean replaceBackSlash) {
+
+        if (path == null)
+            return null;
+
+        // Create a place for the normalized path
+        String normalized = path;
+
+        if (replaceBackSlash && normalized.indexOf('\\') >= 0)
+            normalized = normalized.replace('\\', '/');
+
+        if (normalized.equals("/."))
+            return "/";
+
+        // Add a leading "/" if necessary
+        if (!normalized.startsWith("/"))
+            normalized = "/" + normalized;
+
+        // Resolve occurrences of "//" in the normalized path
+        while (true) {
+            int index = normalized.indexOf("//");
+            if (index < 0)
+                break;
+            normalized = normalized.substring(0, index) +
+                normalized.substring(index + 1);
+        }
+
+        // Resolve occurrences of "/./" in the normalized path
+        while (true) {
+            int index = normalized.indexOf("/./");
+            if (index < 0)
+                break;
+            normalized = normalized.substring(0, index) +
+                normalized.substring(index + 2);
+        }
+
+        // Resolve occurrences of "/../" in the normalized path
+        while (true) {
+            int index = normalized.indexOf("/../");
+            if (index < 0)
+                break;
+            if (index == 0)
+                return (null);  // Trying to go outside our context
+            int index2 = normalized.lastIndexOf('/', index - 1);
+            normalized = normalized.substring(0, index2) +
+                normalized.substring(index + 3);
+        }
+
+        // Return the normalized path that we have completed
+        return (normalized);
+    }
+}

Modified: tomcat/trunk/res/checkstyle/org-import-control.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/res/checkstyle/org-import-control.xml?rev=1239048&r1=1239047&r2=1239048&view=diff
==============================================================================
--- tomcat/trunk/res/checkstyle/org-import-control.xml (original)
+++ tomcat/trunk/res/checkstyle/org-import-control.xml Wed Feb  1 10:47:17 2012
@@ -105,8 +105,8 @@
     <allow pkg="javax.mail"/>
     <allow pkg="javax.wsdl"/>
     <allow pkg="org.apache.naming"/>
-    <allow class="org.apache.catalina.util.RequestUtil"/>
     <allow class="org.apache.tomcat.util.http.FastHttpDateFormat"/>
+    <allow class="org.apache.tomcat.util.http.RequestUtil"/>
     <subpackage name="factory.webservices">
     </subpackage>
   </subpackage>

Modified: tomcat/trunk/test/org/apache/catalina/util/TestRequestUtil.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/util/TestRequestUtil.java?rev=1239048&r1=1239047&r2=1239048&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/util/TestRequestUtil.java (original)
+++ tomcat/trunk/test/org/apache/catalina/util/TestRequestUtil.java Wed Feb  1 10:47:17 2012
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.catalina.util;
 
 import static org.junit.Assert.assertEquals;
@@ -25,14 +24,6 @@ import org.junit.Test;
 public class TestRequestUtil {
 
     @Test
-    public void testNormalizeString() {
-        assertEquals("/something",RequestUtil.normalize("//something"));
-        assertEquals("/some/thing",RequestUtil.normalize("some//thing"));
-        assertEquals("/something/",RequestUtil.normalize("something//"));
-        assertEquals("/",RequestUtil.normalize("//"));
-    }
-
-    @Test
     public void testURLDecodeStringInvalid() {
         // %n rather than %nn should throw an IAE according to the Javadoc
         Exception exception = null;

Added: tomcat/trunk/test/org/apache/tomcat/util/http/TestRequestUtil.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/http/TestRequestUtil.java?rev=1239048&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/http/TestRequestUtil.java (added)
+++ tomcat/trunk/test/org/apache/tomcat/util/http/TestRequestUtil.java Wed Feb  1 10:47:17
2012
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.util.http;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class TestRequestUtil {
+
+    @Test
+    public void testNormalizeString() {
+        assertEquals("/something",RequestUtil.normalize("//something"));
+        assertEquals("/some/thing",RequestUtil.normalize("some//thing"));
+        assertEquals("/something/",RequestUtil.normalize("something//"));
+        assertEquals("/",RequestUtil.normalize("//"));
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message