Port fix for bug 34399 - disable the undeploy option if the webapp has not been ...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 21 Sep 2006 02:21:19 +0000 (02:21 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 21 Sep 2006 02:21:19 +0000 (02:21 +0000)
This occurs, for example, if the webapp is defined in server.xml

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

java/org/apache/catalina/manager/HTMLManagerServlet.java
java/org/apache/catalina/manager/LocalStrings.properties
java/org/apache/catalina/manager/ManagerServlet.java
java/org/apache/catalina/startup/HostConfig.java
java/org/apache/catalina/startup/mbeans-descriptors.xml

index ad84bb2..e53396f 100644 (file)
@@ -333,6 +333,7 @@ public final class HTMLManagerServlet extends ManagerServlet {
 
         Iterator iterator = sortedContextPathsMap.entrySet().iterator();
         boolean isHighlighted = true;
+        boolean isDeployed = true;
         String highlightColor = null;
 
         while (iterator.hasNext()) {
@@ -353,6 +354,13 @@ public final class HTMLManagerServlet extends ManagerServlet {
             }
 
             if (context != null ) {
+                try {
+                    isDeployed = isDeployed(contextPath);
+                } catch (Exception e) {
+                    // Assume false on failure for safety
+                    isDeployed = false;
+                }
+                
                 args = new Object[6];
                 args[0] = displayPath;
                 args[1] = context.getDisplayName();
@@ -398,12 +406,18 @@ public final class HTMLManagerServlet extends ManagerServlet {
                 if (context.getPath().equals(this.context.getPath())) {
                     writer.print(MessageFormat.format(
                         MANAGER_APP_ROW_BUTTON_SECTION, args));
-                } else if (context.getAvailable()) {
+                } else if (context.getAvailable() && isDeployed) {
+                    writer.print(MessageFormat.format(
+                        STARTED_DEPLOYED_APPS_ROW_BUTTON_SECTION, args));
+                } else if (context.getAvailable() && !isDeployed) {
                     writer.print(MessageFormat.format(
-                        STARTED_APPS_ROW_BUTTON_SECTION, args));
+                        STARTED_NONDEPLOYED_APPS_ROW_BUTTON_SECTION, args));
+                } else if (!context.getAvailable() && isDeployed) {
+                    writer.print(MessageFormat.format(
+                        STOPPED_DEPLOYED_APPS_ROW_BUTTON_SECTION, args));
                 } else {
                     writer.print(MessageFormat.format(
-                        STOPPED_APPS_ROW_BUTTON_SECTION, args));
+                        STOPPED_NONDEPLOYED_APPS_ROW_BUTTON_SECTION, args));
                 }
 
             }
@@ -584,7 +598,7 @@ public final class HTMLManagerServlet extends ManagerServlet {
         " </td>\n" +
         "</tr>\n";
 
-    private static final String STARTED_APPS_ROW_BUTTON_SECTION =
+    private static final String STARTED_DEPLOYED_APPS_ROW_BUTTON_SECTION =
         " <td class=\"row-left\" bgcolor=\"{8}\">\n" +
         "  <small>\n" +
         "  &nbsp;{1}&nbsp;\n" +
@@ -595,7 +609,7 @@ public final class HTMLManagerServlet extends ManagerServlet {
         " </td>\n" +
         "</tr>\n";
 
-    private static final String STOPPED_APPS_ROW_BUTTON_SECTION =
+    private static final String STOPPED_DEPLOYED_APPS_ROW_BUTTON_SECTION =
         " <td class=\"row-left\" bgcolor=\"{8}\">\n" +
         "  <small>\n" +
         "  &nbsp;<a href=\"{0}\" onclick=\"return(confirm('''Are you sure?'''))\">{1}</a>&nbsp;\n" +
@@ -606,6 +620,28 @@ public final class HTMLManagerServlet extends ManagerServlet {
         " </td>\n" +
         "</tr>\n";
 
+    private static final String STARTED_NONDEPLOYED_APPS_ROW_BUTTON_SECTION =
+        " <td class=\"row-left\" bgcolor=\"{8}\">\n" +
+        "  <small>\n" +
+        "  &nbsp;{1}&nbsp;\n" +
+        "  &nbsp;<a href=\"{2}\" onclick=\"return(confirm('''Are you sure?'''))\">{3}</a>&nbsp;\n" +
+        "  &nbsp;<a href=\"{4}\" onclick=\"return(confirm('''Are you sure?'''))\">{5}</a>&nbsp;\n" +
+        "  &nbsp;{7}&nbsp;\n" +
+        "  </small>\n" +
+        " </td>\n" +
+        "</tr>\n";
+
+    private static final String STOPPED_NONDEPLOYED_APPS_ROW_BUTTON_SECTION =
+        " <td class=\"row-left\" bgcolor=\"{8}\">\n" +
+        "  <small>\n" +
+        "  &nbsp;<a href=\"{0}\" onclick=\"return(confirm('''Are you sure?'''))\">{1}</a>&nbsp;\n" +
+        "  &nbsp;{3}&nbsp;\n" +
+        "  &nbsp;{5}&nbsp;\n" +
+        "  &nbsp;{7}&nbsp;\n" +
+        "  </small>\n" +
+        " </td>\n" +
+        "</tr>\n";
+
     private static final String DEPLOY_SECTION =
         "</table>\n" +
         "<br>\n" +
index feeabb1..31363a4 100644 (file)
@@ -58,6 +58,7 @@ managerServlet.noRename=FAIL - Cannot deploy uploaded WAR for path {0}
 managerServlet.noRole=FAIL - User does not possess role {0}
 managerServlet.noSelf=FAIL - The manager can not reload, undeploy, stop, or undeploy itself
 managerServlet.noWrapper=Container has not called setWrapper() for this servlet
+managerServlet.notDeployed=FAIL - Context {0} is defined in server.xml and may not be undeployed
 managerServlet.reloaded=OK - Reloaded application at context path {0}
 managerServlet.undeployd=OK - Undeployed application at context path {0}
 managerServlet.resourcesAll=OK - Listed global resources of all types
index d71ed0c..d7dffce 100644 (file)
@@ -1277,6 +1277,12 @@ public class ManagerServlet
                 }
             }
 
+            if (!isDeployed(path)) {
+                writer.println(sm.getString("managerServlet.notDeployed",
+                        RequestUtil.filter(displayPath)));
+                return;
+            }
+
             if (!isServiced(path)) {
                 addServiced(path);
                 try {
@@ -1369,6 +1375,19 @@ public class ManagerServlet
 
 
     /**
+     * Invoke the isDeployed method on the deployer.
+     */
+    protected boolean isDeployed(String name) 
+        throws Exception {
+        String[] params = { name };
+        String[] signature = { "java.lang.String" };
+        Boolean result = 
+            (Boolean) mBeanServer.invoke(oname, "isDeployed", params, signature);
+        return result.booleanValue();
+    }
+    
+
+    /**
      * Invoke the check method on the deployer.
      */
     protected void check(String name) 
@@ -1380,7 +1399,7 @@ public class ManagerServlet
     
 
     /**
-     * Invoke the check method on the deployer.
+     * Invoke the isServiced method on the deployer.
      */
     protected boolean isServiced(String name) 
         throws Exception {
@@ -1393,7 +1412,7 @@ public class ManagerServlet
     
 
     /**
-     * Invoke the check method on the deployer.
+     * Invoke the addServiced method on the deployer.
      */
     protected void addServiced(String name) 
         throws Exception {
@@ -1404,7 +1423,7 @@ public class ManagerServlet
     
 
     /**
-     * Invoke the check method on the deployer.
+     * Invoke the removeServiced method on the deployer.
      */
     protected void removeServiced(String name) 
         throws Exception {
index fd23158..189f158 100644 (file)
@@ -354,6 +354,23 @@ public class HostConfig
     }
     
     
+    /**
+     * Has the specified application been deployed? Note applications defined
+     * in server.xml will not have been deployed.
+     * @return <code>true</code> if the application has been deployed and
+     * <code>false</code> if the applciation has not been deployed or does not
+     * exist
+     */
+    public boolean isDeployed(String name) {
+        DeployedApplication app = (DeployedApplication) deployed.get(name);
+        if (app == null) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+    
+    
     // ------------------------------------------------------ Protected Methods
 
     
@@ -671,8 +688,6 @@ public class HostConfig
         if (files == null)
             return;
         
-        boolean checkAdditionalDeployments = false;
-        
         for (int i = 0; i < files.length; i++) {
             
             if (files[i].equalsIgnoreCase("META-INF"))
index 1d283c4..be0bccb 100644 (file)
                  type="java.lang.String"/>
     </operation>
 
+    <operation name="isDeployed"
+               description="Was this web application deployed by this component"
+               impact="ACTION"
+               returnType="boolean">
+      <parameter name="name"
+                 description="Application name"
+                 type="java.lang.String"/>
+    </operation>
+
     <operation name="manageApp"
                description="Add a web application managed externally"
                impact="ACTION"