From 2df7247e83c5e5cf3154d0ca785d858989ee7b3a Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Mon, 8 Feb 2010 22:19:59 +0000
Subject: [PATCH] fix start webapp, add stop webapp

---
 .../src/net/i2p/router/web/PluginStarter.java | 28 +++++++++++++++++--
 .../src/net/i2p/router/web/WebAppStarter.java | 14 ++++++++++
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java
index 0bf04dc134..0b71b52de0 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java
@@ -84,13 +84,19 @@ public class PluginStarter implements Runnable {
         if (server != null) {
             File consoleDir = new File(pluginDir, "console");
             Properties props = RouterConsoleRunner.webAppProperties(consoleDir.getAbsolutePath());
-            File webappDir = new File(pluginDir, "webapps");
+            File webappDir = new File(consoleDir, "webapps");
             String fileNames[] = webappDir.list(RouterConsoleRunner.WarFilenameFilter.instance());
             if (fileNames != null) {
                 for (int i = 0; i < fileNames.length; i++) {
                     try {
                         String warName = fileNames[i].substring(0, fileNames[i].lastIndexOf(".war"));
-                        // check for duplicates in $I2P ?
+                        // check for duplicates in $I2P
+                        // easy way for now...
+                        if (warName.equals("i2psnark") || warName.equals("susidns") || warName.equals("i2ptunnel") ||
+                            warName.equals("susimail") || warName.equals("addressbook")) {
+                            log.error("Skipping duplicate webapp " + warName + " in plugin " + appName);
+                            continue;
+                        }
                         String enabled = props.getProperty(PREFIX + warName + ENABLED);
                         if (! "false".equals(enabled)) {
                             String path = new File(webappDir, fileNames[i]).getCanonicalPath();
@@ -161,6 +167,24 @@ public class PluginStarter implements Runnable {
         }
 
         // stop console webapps in console/webapps
+        Server server = getConsoleServer();
+        if (server != null) {
+            File consoleDir = new File(pluginDir, "console");
+            Properties props = RouterConsoleRunner.webAppProperties(consoleDir.getAbsolutePath());
+            File webappDir = new File(consoleDir, "webapps");
+            String fileNames[] = webappDir.list(RouterConsoleRunner.WarFilenameFilter.instance());
+            if (fileNames != null) {
+                for (int i = 0; i < fileNames.length; i++) {
+                    String warName = fileNames[i].substring(0, fileNames[i].lastIndexOf(".war"));
+                    if (warName.equals("i2psnark") || warName.equals("susidns") || warName.equals("i2ptunnel") ||
+                        warName.equals("susimail") || warName.equals("addressbook")) {
+                        continue;
+                    }
+                    WebAppStarter.stopWebApp(server, warName);
+                }
+            }
+        }
+
 
         // remove summary bar link
         Properties props = pluginProperties(ctx, appName);
diff --git a/apps/routerconsole/java/src/net/i2p/router/web/WebAppStarter.java b/apps/routerconsole/java/src/net/i2p/router/web/WebAppStarter.java
index dafc1c10a5..3e24a38c41 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/WebAppStarter.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/WebAppStarter.java
@@ -7,6 +7,7 @@ import java.util.StringTokenizer;
 
 import net.i2p.I2PAppContext;
 
+import org.mortbay.http.HttpContext;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.servlet.WebApplicationContext;
 
@@ -57,4 +58,17 @@ public class WebAppStarter {
         wac.setConfigurationClassNames(newClassNames);
         return wac;
     }
+
+    /**
+     *  stop it
+     */
+    static void stopWebApp(Server server, String appName) {
+        // this will return a new context if one does not exist
+        HttpContext wac = server.getContext('/' + appName);
+        try {
+            // false -> not graceful
+            wac.stop(false);
+        } catch (InterruptedException ie) {}
+    }
+
 }
-- 
GitLab