Fix bugs https://issues.apache.org/bugzilla/show_bug.cgi?id=43013 and https://issues...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 5 May 2008 18:18:00 +0000 (18:18 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 5 May 2008 18:18:00 +0000 (18:18 +0000)
Add support to manger and deployer for wars and dirs that use # to denote multi-level contexts.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@653549 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/manager/HTMLManagerServlet.java
java/org/apache/catalina/manager/ManagerServlet.java
java/org/apache/catalina/startup/ContextConfig.java
java/org/apache/catalina/startup/HostConfig.java

index a1dd6db..7051eaa 100644 (file)
@@ -226,7 +226,7 @@ public final class HTMLManagerServlet extends ManagerServlet {
                 if (basename.equals("ROOT")) {
                     path = "";
                 } else {
-                    path = "/" + basename;
+                    path = "/" + basename.replace('#', '/');
                 }
 
                 if ((host.findChild(path) != null) && !isDeployed(path)) {
index 9458b48..fd5ae35 100644 (file)
@@ -1363,6 +1363,9 @@ public class ManagerServlet
                     // Ignore
                 }
                 try {
+                    if (path.lastIndexOf('/') > 0) {
+                        path = "/" + path.substring(1).replace('/','#');
+                    }
                     File war = new File(getAppBase(), getDocBase(path) + ".war");
                     File dir = new File(getAppBase(), getDocBase(path));
                     File xml = new File(configBase, getConfigFile(path) + ".xml");
@@ -1374,9 +1377,9 @@ public class ManagerServlet
                         xml.delete();
                     }
                     // Perform new deployment
-                    check(path);
+                    check(path.replace('#', '/'));
                 } finally {
-                    removeServiced(path);
+                    removeServiced(path.replace('#','/'));
                 }
             }
             writer.println(sm.getString("managerServlet.undeployed",
@@ -1408,14 +1411,14 @@ public class ManagerServlet
 
 
     /**
-     * Given a context path, get the config file name.
+     * Given a context path, get the doc base.
      */
     protected String getDocBase(String path) {
         String basename = null;
         if (path.equals("")) {
             basename = "ROOT";
         } else {
-            basename = path.substring(1);
+            basename = path.substring(1).replace('/', '#');
         }
         return (basename);
     }
index 2cac87b..0899667 100644 (file)
@@ -873,9 +873,13 @@ public class ContextConfig
         String contextPath = context.getPath();
         if (contextPath.equals("")) {
             contextPath = "ROOT";
+        } else {
+            if (contextPath.lastIndexOf('/') > 0) {
+                contextPath = "/" + contextPath.substring(1).replace('/','#');
+            }
         }
         if (docBase.toLowerCase().endsWith(".war") && !file.isDirectory() && unpackWARs) {
-            URL war = new URL("jar:" + (new File(docBase)).toURL() + "!/");
+            URL war = new URL("jar:" + (new File(docBase)).toURI().toURL() + "!/");
             docBase = ExpandWar.expand(host, war, contextPath);
             file = new File(docBase);
             docBase = file.getCanonicalPath();
@@ -888,7 +892,8 @@ public class ContextConfig
                 File warFile = new File(docBase + ".war");
                 if (warFile.exists()) {
                     if (unpackWARs) {
-                        URL war = new URL("jar:" + warFile.toURL() + "!/");
+                        URL war =
+                            new URL("jar:" + warFile.toURI().toURL() + "!/");
                         docBase = ExpandWar.expand(host, war, contextPath);
                         file = new File(docBase);
                         docBase = file.getCanonicalPath();
index d3bd38b..a526de4 100644 (file)
@@ -464,14 +464,14 @@ public class HostConfig
 
     
     /**
-     * Given a context path, get the config file name.
+     * Given a context path, get the docBase.
      */
     protected String getDocBase(String path) {
         String basename = null;
         if (path.equals("")) {
             basename = "ROOT";
         } else {
-            basename = path.substring(1);
+            basename = path.substring(1).replace('/', '#');
         }
         return (basename);
     }
@@ -504,7 +504,7 @@ public class HostConfig
         File appBase = appBase();
         File configBase = configBase();
         String baseName = getConfigFile(name);
-        String docBase = getConfigFile(name);
+        String docBase = getDocBase(name);
         
         // Deploy XML descriptors from configBase
         File xml = new File(configBase, baseName + ".xml");
@@ -705,7 +705,7 @@ public class HostConfig
             if (files[i].toLowerCase().endsWith(".war") && dir.isFile()) {
                 
                 // Calculate the context path and make sure it is unique
-                String contextPath = "/" + files[i];
+                String contextPath = "/" + files[i].replace('#','/');
                 int period = contextPath.lastIndexOf(".");
                 if (period >= 0)
                     contextPath = contextPath.substring(0, period);
@@ -843,6 +843,7 @@ public class HostConfig
                         name = path;
                     }
                 }
+                name = name.replace('/', '#');
                 File docBase = new File(name);
                 if (!docBase.isAbsolute()) {
                     docBase = new File(appBase(), name);
@@ -879,7 +880,7 @@ public class HostConfig
             if (dir.isDirectory()) {
 
                 // Calculate the context path and make sure it is unique
-                String contextPath = "/" + files[i];
+                String contextPath = "/" + files[i].replace('#','/');
                 if (files[i].equals("ROOT"))
                     contextPath = "";