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 2018/02/28 16:12:12 UTC

svn commit: r1825580 - in /tomcat/trunk: java/org/apache/catalina/manager/ java/org/apache/catalina/util/ test/org/apache/catalina/util/ webapps/docs/

Author: markt
Date: Wed Feb 28 16:12:11 2018
New Revision: 1825580

URL: http://svn.apache.org/viewvc?rev=1825580&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=47467
When deploying a web application via the manager application and a path is not explicitly specified, derive it from the provided deployment descriptor or, if that is not present, the WAR or DIR.

Added:
    tomcat/trunk/test/org/apache/catalina/util/TestContextNameExtractFromPath.java   (with props)
Modified:
    tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java
    tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java
    tomcat/trunk/java/org/apache/catalina/util/ContextName.java
    tomcat/trunk/webapps/docs/changelog.xml
    tomcat/trunk/webapps/docs/manager-howto.xml

Modified: tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java?rev=1825580&r1=1825579&r2=1825580&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java Wed Feb 28 16:12:11 2018
@@ -185,14 +185,19 @@ public final class HTMLManagerServlet ex
         if (path != null) {
             cn = new ContextName(path, request.getParameter("version"));
         }
+
         String deployPath = request.getParameter("deployPath");
+        String deployWar = request.getParameter("deployWar");
+        String deployConfig = request.getParameter("deployConfig");
         ContextName deployCn = null;
-        if (deployPath != null) {
-            deployCn = new ContextName(deployPath,
-                    request.getParameter("deployVersion"));
+        if (deployPath != null && deployPath.length() > 0) {
+            deployCn = new ContextName(deployPath, request.getParameter("deployVersion"));
+        } else if (deployConfig != null && deployConfig.length() > 0) {
+            deployCn = ContextName.extractFromPath(deployConfig);
+        } else if (deployWar != null && deployWar.length() > 0) {
+            deployCn = ContextName.extractFromPath(deployWar);
         }
-        String deployConfig = request.getParameter("deployConfig");
-        String deployWar = request.getParameter("deployWar");
+
         String tlsHostName = request.getParameter("tlsHostName");
 
         // Prepare our output writer to generate the response message

Modified: tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java?rev=1825580&r1=1825579&r2=1825580&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java Wed Feb 28 16:12:11 2018
@@ -311,14 +311,20 @@ public class ManagerServlet extends Http
         String command = request.getPathInfo();
         if (command == null)
             command = request.getServletPath();
-        String config = request.getParameter("config");
+
         String path = request.getParameter("path");
+        String war = request.getParameter("war");
+        String config = request.getParameter("config");
         ContextName cn = null;
         if (path != null) {
             cn = new ContextName(path, request.getParameter("version"));
+        } else if (config != null) {
+            cn = ContextName.extractFromPath(config);
+        } else if (war != null) {
+            cn = ContextName.extractFromPath(war);
         }
+
         String type = request.getParameter("type");
-        String war = request.getParameter("war");
         String tag = request.getParameter("tag");
         boolean update = false;
         if ((request.getParameter("update") != null)

Modified: tomcat/trunk/java/org/apache/catalina/util/ContextName.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/ContextName.java?rev=1825580&r1=1825579&r2=1825580&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/ContextName.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/ContextName.java Wed Feb 28 16:12:11 2018
@@ -173,4 +173,29 @@ public final class ContextName {
     public String toString() {
         return getDisplayName();
     }
+
+
+    /**
+     * Extract the final component of the given path which is assumed to be a
+     * base name and generate a {@link ContextName} from that base name.
+     *
+     * @param path The path that ends in a base name
+     *
+     * @return the {@link ContextName} generated from the given base name
+     */
+    public static ContextName extractFromPath(String path) {
+        // Convert '\' to '/'
+        path = path.replaceAll("\\\\", "/");
+        // Remove trailing '/'. Use while just in case a value ends in ///
+        while (path.endsWith("/")) {
+            path = path.substring(0, path.length() - 1);
+        }
+
+        int lastSegment = path.lastIndexOf('/');
+        if (lastSegment > 0) {
+            path = path.substring(lastSegment + 1);
+        }
+
+        return new ContextName(path, true);
+    }
 }

Added: tomcat/trunk/test/org/apache/catalina/util/TestContextNameExtractFromPath.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/util/TestContextNameExtractFromPath.java?rev=1825580&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/util/TestContextNameExtractFromPath.java (added)
+++ tomcat/trunk/test/org/apache/catalina/util/TestContextNameExtractFromPath.java Wed Feb 28 16:12:11 2018
@@ -0,0 +1,70 @@
+/*
+ * 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.catalina.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+
+@RunWith(Parameterized.class)
+public class TestContextNameExtractFromPath {
+
+    @Parameterized.Parameters(name = "{index}: path[{0}]")
+    public static Collection<Object[]> parameters() {
+        List<Object[]> parameterSets = new ArrayList<>();
+
+        parameterSets.add(new Object[] {"/foo/bar", "/bar", ""});
+        parameterSets.add(new Object[] {"C:\\foo\\bar", "/bar", ""});
+        parameterSets.add(new Object[] {"/foo/bar.war", "/bar", ""});
+        parameterSets.add(new Object[] {"C:\\foo\\bar.war", "/bar", ""});
+        parameterSets.add(new Object[] {"/foo/bar.xml", "/bar", ""});
+        parameterSets.add(new Object[] {"C:\\foo\\bar.xml", "/bar", ""});
+        parameterSets.add(new Object[] {"/foo/bar////", "/bar", ""});
+        parameterSets.add(new Object[] {"C:\\foo\\bar\\\\", "/bar", ""});
+        parameterSets.add(new Object[] {"/foo/bar##4", "/bar", "4"});
+        parameterSets.add(new Object[] {"C:\\foo\\bar##4", "/bar", "4"});
+        parameterSets.add(new Object[] {"/foo/bar#foo##4", "/bar/foo", "4"});
+        parameterSets.add(new Object[] {"C:\\foo\\bar#foo##4", "/bar/foo", "4"});
+        parameterSets.add(new Object[] {"/foo/ROOT", "", ""});
+        parameterSets.add(new Object[] {"C:\\foo\\ROOT", "", ""});
+
+        return parameterSets;
+    }
+
+    @Parameter(0)
+    public String path;
+
+    @Parameter(1)
+    public String expectedPath;
+
+    @Parameter(2)
+    public String expectedVersion;
+
+
+    @Test
+    public void testConextNameExtractFromPath() throws Exception {
+        ContextName cn = ContextName.extractFromPath(path);
+        Assert.assertEquals(expectedPath,  cn.getPath());
+        Assert.assertEquals(expectedVersion, cn.getVersion());
+    }
+}

Propchange: tomcat/trunk/test/org/apache/catalina/util/TestContextNameExtractFromPath.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1825580&r1=1825579&r2=1825580&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed Feb 28 16:12:11 2018
@@ -144,6 +144,12 @@
   <subsection name="Web applications">
     <changelog>
       <add>
+        <bug>47467</bug>: When deploying a web application via the manager
+        application and a path is not explicitly specified, derive it from the
+        provided deployment descriptor or, if that is not present, the WAR or
+        DIR. (markt)
+      </add>
+      <add>
         <bug>48672</bug>: Add documentation for the Host Manager web
         application. Patch provided by Marek Czernek. (markt)
       </add>

Modified: tomcat/trunk/webapps/docs/manager-howto.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/manager-howto.xml?rev=1825580&r1=1825579&r2=1825580&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/manager-howto.xml (original)
+++ tomcat/trunk/webapps/docs/manager-howto.xml Wed Feb 28 16:12:11 2018
@@ -257,14 +257,24 @@ the host and port appropriately for your
 <ul>
 <li><strong>path</strong> - The context path (including the leading slash)
     of the web application you are dealing with.  To select the ROOT web
-    application, specify "/".  <strong>NOTE</strong>:
-    It is not possible to perform administrative commands on the
-    Manager application itself.</li>
+    application, specify "/".
+    <br/>
+    <strong>NOTE</strong>: It is not possible to perform administrative commands
+    on the Manager application itself.
+    <br/>
+    <strong>NOTE</strong>: If the path parameter is not explicitly specified
+    then the path and the version will be derived using the standard
+    <a href="config/context.html#Naming">Context naming</a> rules from the
+    config parameter or, if the config parameter is not present, the war
+    parameter.</li>
 <li><strong>version</strong> - The version of this web application as used by
     the <a href="config/context.html">parallel deployment</a> feature. If you
     use parallel deployment wherever a path is required you must specify a
     version in addition to the path and it is the combination of path and
-    version that must be unique rather than just the path.</li>
+    version that must be unique rather than just the path.
+    <br/>
+    <strong>NOTE</strong>: If the path is not explicitly specified, the version
+    parameter is ignored.</li>
 <li><strong>war</strong> - URL of a web application archive (WAR) file, or
     pathname of a directory which contains the web application, or a
     Context configuration ".xml" file.  You can use URLs in any of the



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