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 2014/03/13 15:48:14 UTC

svn commit: r1577182 - in /tomcat/trunk: java/org/apache/catalina/manager/LocalStrings.properties java/org/apache/catalina/manager/ManagerServlet.java java/org/apache/catalina/startup/HostConfig.java webapps/docs/changelog.xml

Author: markt
Date: Thu Mar 13 14:48:14 2014
New Revision: 1577182

URL: http://svn.apache.org/r1577182
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56248
Allow the deployer to update an existing WAR file without
undeploying the existing application if the update flag is set.
This allows any existing custom context.xml for the application
to be retained. To update an application and remove any existing
context.xml simply undeploy the old version of the application
before deploying the new version.

Modified:
    tomcat/trunk/java/org/apache/catalina/manager/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java
    tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/manager/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/LocalStrings.properties?rev=1577182&r1=1577181&r2=1577182&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/manager/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/manager/LocalStrings.properties Thu Mar 13 14:48:14 2014
@@ -80,6 +80,7 @@ managerServlet.exception=FAIL - Encounte
 managerServlet.findleaksFail=FAIL - Find leaks failed: Host not instance of StandardHost
 managerServlet.findleaksList=OK - Found potential memory leaks in the following applications:
 managerServlet.findleaksNone=OK - No memory leaks found
+managerServlet.invalidCommand=FAIL - Invalid parameters supplied for command [{0}]
 managerServlet.invalidPath=FAIL - Invalid context path {0} was specified
 managerServlet.listed=OK - Listed applications for virtual host {0}
 managerServlet.listitem={0}:{1}:{2}:{3}

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=1577182&r1=1577181&r2=1577182&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java Thu Mar 13 14:48:14 2014
@@ -54,6 +54,7 @@ import org.apache.catalina.Wrapper;
 import org.apache.catalina.connector.Connector;
 import org.apache.catalina.core.StandardHost;
 import org.apache.catalina.core.StandardServer;
+import org.apache.catalina.startup.ExpandWar;
 import org.apache.catalina.util.ContextName;
 import org.apache.catalina.util.RequestUtil;
 import org.apache.catalina.util.ServerInfo;
@@ -179,8 +180,7 @@ public class ManagerServlet extends Http
 
     /**
      * File object representing the directory into which the deploy() command
-     * will store the WAR and context configuration files that have been
-     * uploaded.
+     * will deploy uploaded WAR files (normally the appBase).
      */
     protected File deployed = null;
 
@@ -340,8 +340,11 @@ public class ManagerServlet extends Http
         } else if (command.equals("/deploy")) {
             if (war != null || config != null) {
                 deploy(writer, config, cn, war, update, smClient);
-            } else {
+            } else if (tag != null) {
                 deploy(writer, cn, tag, smClient);
+            } else {
+                writer.println(smClient.getString(
+                        "managerServlet.invalidCommand", command));
             }
         } else if (command.equals("/list")) {
             list(writer, smClient);
@@ -654,21 +657,16 @@ public class ManagerServlet extends Http
         String baseName = cn.getBaseName();
         String displayPath = cn.getDisplayName();
 
-        // Check if app already exists, or undeploy it if updating
+        // If app exists deployment can only proceed if update is true
+        // Note existing WAR will be deleted and then replaced
         Context context = (Context) host.findChild(name);
-        if (update) {
-            if (context != null) {
-                undeploy(writer, cn, smClient);
-            }
-            context = (Context) host.findChild(name);
-        }
-        if (context != null) {
+        if (context != null && !update) {
             writer.println(smClient.getString("managerServlet.alreadyContext",
                     displayPath));
             return;
         }
 
-        // Calculate the base path
+        // Determine directory where WAR will be uploaded to
         File deployedPath = deployed;
         if (tag != null) {
             deployedPath = new File(versioned, tag);
@@ -679,26 +677,30 @@ public class ManagerServlet extends Http
             }
         }
 
-        // Upload the web application archive to a local WAR file
+        // Determine full path for uploaded WAR
         File localWar = new File(deployedPath, baseName + ".war");
         if (debug >= 2) {
             log("Uploading WAR file to " + localWar);
         }
 
-        // Copy WAR to appBase
         try {
             if (!isServiced(name)) {
                 addServiced(name);
                 try {
+                    if (update && tag == null && localWar.isFile()) {
+                        if (!localWar.delete()) {
+                            writer.println(smClient.getString("managerServlet.deleteFail",
+                                    localWar));
+                            return;
+                        }
+                    }
                     // Upload WAR
                     uploadWar(writer, request, localWar, smClient);
-                    // Copy WAR and XML to the host app base if needed
                     if (tag != null) {
+                        // Copy WAR to the host's appBase
                         deployedPath = deployed;
                         File localWarCopy = new File(deployedPath, baseName + ".war");
                         copy(localWar, localWarCopy);
-                        localWar = localWarCopy;
-                        copy(localWar, new File(host.getAppBaseFile(), baseName + ".war"));
                     }
                     // Perform new deployment
                     check(name);
@@ -722,7 +724,6 @@ public class ManagerServlet extends Http
             writer.println(smClient.getString(
                     "managerServlet.deployFailed", displayPath));
         }
-
     }
 
 
@@ -738,6 +739,8 @@ public class ManagerServlet extends Http
     protected void deploy(PrintWriter writer, ContextName cn, String tag,
             StringManager smClient) {
 
+        // NOTE: It is assumed that update is always true in this method.
+
         // Validate the requested context path
         if (!validateContextName(cn, writer, smClient)) {
             return;
@@ -747,26 +750,19 @@ public class ManagerServlet extends Http
         String name = cn.getName();
         String displayPath = cn.getDisplayName();
 
-        // Calculate the base path
-        File deployedPath = versioned;
-        if (tag != null) {
-            deployedPath = new File(deployedPath, tag);
-        }
-
         // Find the local WAR file
-        File localWar = new File(deployedPath, baseName + ".war");
-
-        // Check if app already exists, or undeploy it if updating
-        Context context = (Context) host.findChild(name);
-        if (context != null) {
-            undeploy(writer, cn, smClient);
-        }
+        File localWar = new File(versioned, baseName + ".war");
 
         // Copy WAR to appBase
         try {
             if (!isServiced(name)) {
                 addServiced(name);
                 try {
+                    if (!localWar.delete()) {
+                        writer.println(smClient.getString("managerServlet.deleteFail",
+                                localWar));
+                        return;
+                    }
                     copy(localWar, new File(host.getAppBaseFile(), baseName + ".war"));
                     // Perform new deployment
                     check(name);
@@ -842,15 +838,10 @@ public class ManagerServlet extends Http
         String baseName = cn.getBaseName();
         String displayPath = cn.getDisplayName();
 
-        // Check if app already exists, or undeploy it if updating
+        // If app exists deployment can only proceed if update is true
+        // Note existing files will be deleted and then replaced
         Context context = (Context) host.findChild(name);
-        if (update) {
-            if (context != null) {
-                undeploy(writer, cn, smClient);
-            }
-            context = (Context) host.findChild(name);
-        }
-        if (context != null) {
+        if (context != null && !update) {
             writer.println(smClient.getString("managerServlet.alreadyContext",
                     displayPath));
             return;
@@ -873,17 +864,27 @@ public class ManagerServlet extends Http
                                     "managerServlet.mkdirFail",configBase));
                             return;
                         }
-                        copy(new File(config),
-                                new File(configBase, baseName + ".xml"));
+                        File localConfig = new File(configBase, baseName + ".xml");
+                        if (localConfig.isFile() && !localConfig.delete()) {
+                            writer.println(smClient.getString(
+                                    "managerServlet.deleteFail", localConfig));
+                            return;
+                        }
+                        copy(new File(config), localConfig);
                     }
                     if (war != null) {
+                        File localWar;
                         if (war.endsWith(".war")) {
-                            copy(new File(war),
-                                    new File(host.getAppBaseFile(), baseName + ".war"));
+                            localWar = new File(host.getAppBaseFile(), baseName + ".war");
                         } else {
-                            copy(new File(war),
-                                    new File(host.getAppBaseFile(), baseName));
+                            localWar = new File(host.getAppBaseFile(), baseName);
+                        }
+                        if (localWar.exists() && !ExpandWar.delete(localWar)) {
+                            writer.println(smClient.getString(
+                                    "managerServlet.deleteFail", localWar));
+                            return;
                         }
+                        copy(new File(war), localWar);
                     }
                     // Perform new deployment
                     check(name);

Modified: tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java?rev=1577182&r1=1577181&r2=1577182&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java Thu Mar 13 14:48:14 2014
@@ -445,7 +445,7 @@ public class HostConfig
         ContextName cn = new ContextName(name, false);
         String baseName = cn.getBaseName();
 
-        if (deploymentExists(baseName)) {
+        if (deploymentExists(cn.getName())) {
             return;
         }
 

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1577182&r1=1577181&r2=1577182&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Mar 13 14:48:14 2014
@@ -113,6 +113,14 @@
         authenticating an unknown user. (markt)
       </fix>
       <fix>
+        <bug>56248</bug>: Allow the deployer to update an existing WAR file
+        without undeploying the existing application if the update flag is set.
+        This allows any existing custom context.xml for the application to be
+        retained. To update an application and remove any existing context.xml
+        simply undeploy the old version of the application before deploying the
+        new version. (markt)
+      </fix>
+      <fix>
         <bug>56253</bug>: When listing resources that are provided by a JAR, fix
         possible <code>StringIndexOutOfBoundsException</code>s. Add some unit
         tests for this and similar scenarios and fix the additional issues those



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


Re: svn commit: r1577182 - in /tomcat/trunk: java/org/apache/catalina/manager/LocalStrings.properties java/org/apache/catalina/manager/ManagerServlet.java java/org/apache/catalina/startup/HostConfig.java webapps/docs/changelog.xml

Posted by Mark Thomas <ma...@apache.org>.
On 13/03/2014 14:48, markt@apache.org wrote:
> Author: markt
> Date: Thu Mar 13 14:48:14 2014
> New Revision: 1577182
> 
> URL: http://svn.apache.org/r1577182
> Log:
> Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56248
> Allow the deployer to update an existing WAR file without
> undeploying the existing application if the update flag is set.
> This allows any existing custom context.xml for the application
> to be retained. To update an application and remove any existing
> context.xml simply undeploy the old version of the application
> before deploying the new version.

Reviewing the back-port to 7.0.x, the logic isn't quite right when tag
!= null. I'm working on an update.

Mark

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