You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2010/07/01 23:35:19 UTC

svn commit: r959790 - in /tomcat/trunk: java/org/apache/catalina/connector/ java/org/apache/tomcat/util/http/mapper/ webapps/docs/

Author: markt
Date: Thu Jul  1 21:35:19 2010
New Revision: 959790

URL: http://svn.apache.org/viewvc?rev=959790&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49536
Ensure a 404 response for an unmapped request when no ROOT context is deployed.
Most of the change is getting the mapper to use the Host object rather than the ObjectName or an empty string

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
    tomcat/trunk/java/org/apache/catalina/connector/MapperListener.java
    tomcat/trunk/java/org/apache/catalina/connector/Request.java
    tomcat/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=959790&r1=959789&r2=959790&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Thu Jul  1 21:35:19 2010
@@ -630,6 +630,16 @@ public class CoyoteAdapter implements Ad
             return false;
         }
 
+        // If there is no context at this point, it is likely no ROOT context
+        // has been deployed
+        if (request.getContext() == null) {
+            res.setStatus(404);
+            res.setMessage("Not found");
+            // No context, so use host
+            request.getHost().logAccess(request, response, 0, true);
+            return false;
+        }
+        
         // Now we have the context, we can parse the session ID from the URL
         // (if any). Need to do this before we redirect in case we need to
         // include the session id in the redirect

Modified: tomcat/trunk/java/org/apache/catalina/connector/MapperListener.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/MapperListener.java?rev=959790&r1=959789&r2=959790&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/MapperListener.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/MapperListener.java Thu Jul  1 21:35:19 2010
@@ -273,7 +273,7 @@ public class MapperListener implements C
     private void registerHost(Host host) {
         
         String[] aliases = host.findAliases();
-        mapper.addHost(host.getName(), aliases, host.getObjectName());
+        mapper.addHost(host.getName(), aliases, host);
         
         host.addContainerListener(this);
         
@@ -330,13 +330,13 @@ public class MapperListener implements C
         if ("/".equals(contextName)) {
             contextName = "";
         }
-        String hostName = context.getParent().getName();
+        Container host = context.getParent();
         
         javax.naming.Context resources = context.getResources();
         String[] welcomeFiles = context.findWelcomeFiles();
 
-        mapper.addContext(hostName, contextName, context, welcomeFiles,
-                resources);
+        mapper.addContext(host.getName(), host, contextName, context,
+                welcomeFiles, resources);
 
         context.addContainerListener(this);
        

Modified: tomcat/trunk/java/org/apache/catalina/connector/Request.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Request.java?rev=959790&r1=959789&r2=959790&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Request.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Request.java Thu Jul  1 21:35:19 2010
@@ -617,10 +617,7 @@ public class Request
      * Return the Host within which this Request is being processed.
      */
     public Host getHost() {
-        if (getContext() == null)
-            return null;
-        return (Host) getContext().getParent();
-        //return ((Host) mappingData.host);
+        return ((Host) mappingData.host);
     }
 
 

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=959790&r1=959789&r2=959790&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 Thu Jul  1 21:35:19 2010
@@ -210,33 +210,34 @@ public final class Mapper {
      * Add a new Context to an existing Host.
      *
      * @param hostName Virtual host name this context belongs to
+     * @param host Host object
      * @param path Context path
      * @param context Context object
      * @param welcomeResources Welcome files defined for this context
      * @param resources Static resources of the context
      */
     public void addContext
-        (String hostName, String path, Object context,
+        (String hostName, Object host, String path, Object context,
          String[] welcomeResources, javax.naming.Context resources) {
 
         Host[] hosts = this.hosts;
         int pos = find(hosts, hostName);
         if( pos <0 ) {
-            addHost(hostName, new String[0], "");
+            addHost(hostName, new String[0], host);
             hosts = this.hosts;
             pos = find(hosts, hostName);
         }
         if (pos < 0) {
             log.error("No host found: " + hostName);
         }
-        Host host = hosts[pos];
-        if (host.name.equals(hostName)) {
+        Host mappedHost = hosts[pos];
+        if (mappedHost.name.equals(hostName)) {
             int slashCount = slashCount(path);
-            synchronized (host) {
-                Context[] contexts = host.contextList.contexts;
+            synchronized (mappedHost) {
+                Context[] contexts = mappedHost.contextList.contexts;
                 // Update nesting
-                if (slashCount > host.contextList.nesting) {
-                    host.contextList.nesting = slashCount;
+                if (slashCount > mappedHost.contextList.nesting) {
+                    mappedHost.contextList.nesting = slashCount;
                 }
                 Context[] newContexts = new Context[contexts.length + 1];
                 Context newContext = new Context();
@@ -245,7 +246,7 @@ public final class Mapper {
                 newContext.welcomeResources = welcomeResources;
                 newContext.resources = resources;
                 if (insertMap(contexts, newContexts, newContext)) {
-                    host.contextList.contexts = newContexts;
+                    mappedHost.contextList.contexts = newContexts;
                 }
             }
         }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=959790&r1=959789&r2=959790&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Jul  1 21:35:19 2010
@@ -83,6 +83,11 @@
         <bug>49525</bug>: Ensure cookies for the ROOT context have a path of /
         rather than an empty string. (markt)
       </fix>
+      <fix>
+        <bug>49536</bug>: If no ROOT context is deployed, ensure a 404 rather
+        than a 200 is returned for requests that don't map to any other context.
+        (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



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