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 16:30:35 UTC

svn commit: r1577199 - in /tomcat/tc7.0.x/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 15:30:35 2014
New Revision: 1577199

URL: http://svn.apache.org/r1577199
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/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/LocalStrings.properties
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/ManagerServlet.java
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1577182,1577195

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/LocalStrings.properties?rev=1577199&r1=1577198&r2=1577199&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/LocalStrings.properties (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/LocalStrings.properties Thu Mar 13 15:30:35 2014
@@ -79,6 +79,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.invalidWar=FAIL - Invalid application URL {0} was specified
 managerServlet.listed=OK - Listed applications for virtual host {0}

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/ManagerServlet.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/ManagerServlet.java?rev=1577199&r1=1577198&r2=1577199&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/ManagerServlet.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/ManagerServlet.java Thu Mar 13 15:30:35 2014
@@ -52,6 +52,7 @@ import org.apache.catalina.Session;
 import org.apache.catalina.Wrapper;
 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;
@@ -189,8 +190,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;
 
@@ -366,8 +366,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);
@@ -639,51 +642,50 @@ 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
-        File deployedPath = deployed;
-        if (tag != null) {
-            deployedPath = new File(versioned, tag);
-            if (!deployedPath.mkdirs() && !deployedPath.isDirectory()) {
+        File deployedWar = new File(deployed, baseName + ".war");
+
+        // Determine full path for uploaded WAR
+        File uploadedWar;
+        if (tag == null) {
+            uploadedWar = deployedWar;
+        } else {
+            File uploadPath = new File(versioned, tag);
+            if (!uploadPath.mkdirs() && !uploadPath.isDirectory()) {
                 writer.println(smClient.getString("managerServlet.mkdirFail",
-                        deployedPath));
+                        uploadPath));
                 return;
             }
+            uploadedWar = new File(uploadPath, baseName + ".war");
         }
-
-        // Upload the web application archive to a local WAR file
-        File localWar = new File(deployedPath, baseName + ".war");
         if (debug >= 2) {
-            log("Uploading WAR file to " + localWar);
+            log("Uploading WAR file to " + uploadedWar);
         }
 
-        // Copy WAR to appBase
         try {
             if (!isServiced(name)) {
                 addServiced(name);
                 try {
+                    if (update && tag == null && deployedWar.isFile()) {
+                        if (!deployedWar.delete()) {
+                            writer.println(smClient.getString("managerServlet.deleteFail",
+                                    deployedWar));
+                            return;
+                        }
+                    }
                     // Upload WAR
-                    uploadWar(writer, request, localWar, smClient);
-                    // Copy WAR and XML to the host app base if needed
+                    uploadWar(writer, request, uploadedWar, smClient);
                     if (tag != null) {
-                        deployedPath = deployed;
-                        File localWarCopy = new File(deployedPath, baseName + ".war");
-                        copy(localWar, localWarCopy);
-                        localWar = localWarCopy;
-                        copy(localWar, new File(getAppBase(), baseName + ".war"));
+                        // Copy WAR to the host's appBase
+                        copy(uploadedWar, deployedWar);
                     }
                     // Perform new deployment
                     check(name);
@@ -707,7 +709,6 @@ public class ManagerServlet extends Http
             writer.println(smClient.getString(
                     "managerServlet.deployFailed", displayPath));
         }
-        
     }
 
 
@@ -722,6 +723,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;
@@ -731,27 +734,22 @@ 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");
+        File localWar = new File(versioned, 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 deployedWar = new File(host.getAppBase(), baseName + ".war");
 
         // Copy WAR to appBase
         try {
             if (!isServiced(name)) {
                 addServiced(name);
                 try {
-                    copy(localWar, new File(getAppBase(), baseName + ".war"));
+                    if (!deployedWar.delete()) {
+                        writer.println(smClient.getString("managerServlet.deleteFail",
+                                deployedWar));
+                        return;
+                    }
+                    copy(localWar, deployedWar);
                     // Perform new deployment
                     check(name);
                 } finally {
@@ -825,15 +823,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;
@@ -856,17 +849,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(getAppBase(), baseName + ".war"));
+                            localWar = new File(getAppBase(), baseName + ".war");
                         } else {
-                            copy(new File(war), 
-                                    new File(getAppBase(), baseName));
+                            localWar = new File(getAppBase(), 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/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java?rev=1577199&r1=1577198&r2=1577199&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java Thu Mar 13 15:30:35 2014
@@ -537,7 +537,7 @@ public class HostConfig
         ContextName cn = new ContextName(name, false);
         String baseName = cn.getBaseName();
 
-        if (deploymentExists(baseName)) {
+        if (deploymentExists(cn.getName())) {
             return;
         }
 

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1577199&r1=1577198&r2=1577199&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu Mar 13 15:30:35 2014
@@ -82,6 +82,14 @@
         <bug>56246</bug>: Fix NullPointerException in MemoryRealm when
         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>
     </changelog>
   </subsection>
   <subsection name="Coyote">



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


Re: svn commit: r1577199 - in /tomcat/tc7.0.x/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 Konstantin Kolinko <kn...@gmail.com>.
2014-03-16 0:14 GMT+04:00 Konstantin Kolinko <kn...@gmail.com>:
> 2014-03-13 19:30 GMT+04:00  <ma...@apache.org>:
>> Author: markt
>> Date: Thu Mar 13 15:30:35 2014
>> New Revision: 1577199
>>
>> URL: http://svn.apache.org/r1577199
>> 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/tc7.0.x/trunk/   (props changed)
>>     tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/LocalStrings.properties
>>     tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/ManagerServlet.java
>>     tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java
>>     tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
>>
>> Propchange: tomcat/tc7.0.x/trunk/
>> ------------------------------------------------------------------------------
>>   Merged /tomcat/trunk:r1577182,1577195
>>
>
> There is a bug in this commit in the second deploy() method,
>
>     protected void deploy(PrintWriter writer, ContextName cn, String tag,
>             StringManager smClient) {
> .. lines 740
>
>         // Find the local WAR file
>         File localWar = new File(versioned, baseName + ".war");
>
> The filename of a tagged war file should be  versioned + tag +
> baseName.war.  The "tag" part was lost.

2. ..line 744

        File deployedWar = new File(host.getAppBase(), baseName + ".war");

The value of "host.getAppBase()" is not guaranteed to be an absolute path.

In TC7 here there is field  ManagerServlet.deployed that provides
absolute value of that path.
There is also method ManagerServlet.getAppBase() that provides
canonical path for it.

The TC8 code is correct here. It calls a different method on a Host.
 new File(host.getAppBaseFile(), baseName + ".war");


The first and third deploy() methods are OK, no issues noted there.

Best regards,
Konstantin Kolinko

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


Re: svn commit: r1577199 - in /tomcat/tc7.0.x/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 Konstantin Kolinko <kn...@gmail.com>.
2014-03-13 19:30 GMT+04:00  <ma...@apache.org>:
> Author: markt
> Date: Thu Mar 13 15:30:35 2014
> New Revision: 1577199
>
> URL: http://svn.apache.org/r1577199
> 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/tc7.0.x/trunk/   (props changed)
>     tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/LocalStrings.properties
>     tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/ManagerServlet.java
>     tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java
>     tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
>
> Propchange: tomcat/tc7.0.x/trunk/
> ------------------------------------------------------------------------------
>   Merged /tomcat/trunk:r1577182,1577195
>

There is a bug in this commit in the second deploy() method,

    protected void deploy(PrintWriter writer, ContextName cn, String tag,
            StringManager smClient) {
.. lines 740

        // Find the local WAR file
        File localWar = new File(versioned, baseName + ".war");

The filename of a tagged war file should be  versioned + tag +
baseName.war.  The "tag" part was lost.

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