tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1346510 - in /tomcat/trunk: java/org/apache/catalina/core/StandardContext.java java/org/apache/tomcat/util/http/mapper/Mapper.java test/org/apache/tomcat/util/http/mapper/TestMapperContextRoot.java
Date Tue, 05 Jun 2012 18:17:58 GMT
Author: markt
Date: Tue Jun  5 18:17:58 2012
New Revision: 1346510

URL: http://svn.apache.org/viewvc?rev=1346510&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53356
Add support for an explicit mapping of a servlet to the context root

Added:
    tomcat/trunk/test/org/apache/tomcat/util/http/mapper/TestMapperContextRoot.java
Modified:
    tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
    tomcat/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1346510&r1=1346509&r2=1346510&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Tue Jun  5 18:17:58 2012
@@ -5957,6 +5957,9 @@ public class StandardContext extends Con
         if (urlPattern.indexOf('\n') >= 0 || urlPattern.indexOf('\r') >= 0) {
             return (false);
         }
+        if (urlPattern.equals("")) {
+            return true;
+        }
         if (urlPattern.startsWith("*.")) {
             if (urlPattern.indexOf('/') < 0) {
                 checkUnusualURLPattern(urlPattern);

Modified: tomcat/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java?rev=1346510&r1=1346509&r2=1346510&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java Tue Jun  5 18:17:58 2012
@@ -393,7 +393,13 @@ public final class Mapper {
                 context.defaultWrapper = newWrapper;
             } else {
                 // Exact wrapper
-                newWrapper.name = path;
+                if (path.length() == 0) {
+                    // Special case for the Context Root mapping which is
+                    // treated as an exact match
+                    newWrapper.name = "/";
+                } else {
+                    newWrapper.name = path;
+                }
                 Wrapper[] oldWrappers = context.exactWrappers;
                 Wrapper[] newWrappers =
                     new Wrapper[oldWrappers.length + 1];
@@ -1026,8 +1032,16 @@ public final class Mapper {
         int pos = find(wrappers, path);
         if ((pos != -1) && (path.equals(wrappers[pos].name))) {
             mappingData.requestPath.setString(wrappers[pos].name);
-            mappingData.wrapperPath.setString(wrappers[pos].name);
             mappingData.wrapper = wrappers[pos].object;
+            if (path.equals("/")) {
+                // Special handling for Context Root mapped servlet
+                mappingData.pathInfo.setString("/");
+                mappingData.wrapperPath.recycle();
+                // This seems wrong but it is what the spec says...
+                mappingData.contextPath.recycle();
+            } else {
+                mappingData.wrapperPath.setString(wrappers[pos].name);
+            }
         }
     }
 

Added: tomcat/trunk/test/org/apache/tomcat/util/http/mapper/TestMapperContextRoot.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/http/mapper/TestMapperContextRoot.java?rev=1346510&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/http/mapper/TestMapperContextRoot.java (added)
+++ tomcat/trunk/test/org/apache/tomcat/util/http/mapper/TestMapperContextRoot.java Tue Jun
 5 18:17:58 2012
@@ -0,0 +1,79 @@
+/*
+ * 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.mapper;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.tomcat.util.buf.ByteChunk;
+
+public class TestMapperContextRoot extends TomcatBaseTest{
+
+    @Test
+    public void testBug53339() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        tomcat.enableNaming();
+
+        // Must have a real docBase - just use temp
+        Context ctx =
+            tomcat.addContext("", System.getProperty("java.io.tmpdir"));
+
+        Tomcat.addServlet(ctx, "Bug53356", new Bug53356Servlet());
+        ctx.addServletMapping("", "Bug53356");
+
+        tomcat.start();
+
+        ByteChunk body = getUrl("http://localhost:" + getPort());
+
+        Assert.assertEquals("OK", body.toString());
+    }
+
+    private static class Bug53356Servlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+            // Confirm behaviour as per Servler 12.2
+            boolean pass = "/".equals(req.getPathInfo());
+            if (pass) {
+                pass = (req.getServletPath() == null);
+            }
+            if (pass) {
+                pass = (req.getContextPath() == null);
+            }
+
+            resp.setContentType("text/plain");
+            if (pass) {
+                resp.getWriter().write("OK");
+            } else {
+                resp.getWriter().write("FAIL");
+            }
+        }
+    }
+}



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


Mime
View raw message