From f265db4037e314ce05699f035136a1337540fdba Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Thu, 11 Feb 2010 21:41:54 +0000 Subject: [PATCH] fix stop button; catch and log exceptions better --- .../net/i2p/router/web/ConfigClientsHandler.java | 15 ++++++++++----- .../net/i2p/router/web/ConfigClientsHelper.java | 2 +- .../src/net/i2p/router/web/PluginStarter.java | 13 ++++++++++--- .../net/i2p/router/web/PluginUpdateHandler.java | 8 ++++++-- .../src/net/i2p/router/web/WebAppStarter.java | 2 ++ 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java index a496cd3999..1fd1191265 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java @@ -72,8 +72,9 @@ public class ConfigClientsHandler extends FormHandler { PluginStarter.stopPlugin(_context, app); PluginStarter.deletePlugin(_context, app); addFormNotice(_("Deleted plugin {0}", app)); - } catch (IOException e) { + } catch (Throwable e) { addFormError(_("Error deleting plugin {0}", app) + ": " + e); + _log.error("Error deleting plugin " + app, e); } } return; @@ -84,8 +85,11 @@ public class ConfigClientsHandler extends FormHandler { String app = _action.substring(5); try { PluginStarter.stopPlugin(_context, app); - } catch (IOException e) {} - addFormNotice(_("Stopped plugin {0}", app)); + addFormNotice(_("Stopped plugin {0}", app)); + } catch (Throwable e) { + addFormError(_("Error stopping plugin {0}", app) + ": " + e); + _log.error("Error stopping plugin " + app, e); + } return; } @@ -247,8 +251,9 @@ public class ConfigClientsHandler extends FormHandler { path = new File(path, app + ".war"); WebAppStarter.startWebApp(_context, s, app, path.getAbsolutePath()); addFormNotice(_("WebApp") + " <a href=\"/" + app + "/\">" + _(app) + "</a> " + _("started") + '.'); - } catch (Exception ioe) { - addFormError(_("Failed to start") + ' ' + _(app) + " " + ioe + '.'); + } catch (Throwable e) { + addFormError(_("Failed to start") + ' ' + _(app) + " " + e + '.'); + _log.error("Failed to start webapp " + app, e); } return; } diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java index d0daac4b2e..a096df5f08 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java @@ -181,7 +181,7 @@ public class ConfigClientsHelper extends HelperBase { if (showEditButton && (!edit) && !ro) buf.append("<button type=\"submit\" name=\"edit\" value=\"Edit ").append(index).append("\" >" + _("Edit") + "<span class=hide> ").append(index).append("</span></button>"); if (showStopButton && (!edit)) - buf.append("<button type=\"submit\" name=\"edit\" value=\"Stop ").append(index).append("\" >" + _("Stop") + "<span class=hide> ").append(index).append("</span></button>"); + buf.append("<button type=\"submit\" name=\"action\" value=\"Stop ").append(index).append("\" >" + _("Stop") + "<span class=hide> ").append(index).append("</span></button>"); if (showUpdateButton && (!edit) && !ro) { buf.append("<button type=\"submit\" name=\"action\" value=\"Check ").append(index).append("\" >" + _("Check for updates") + "<span class=hide> ").append(index).append("</span></button>"); buf.append("<button type=\"submit\" name=\"action\" value=\"Update ").append(index).append("\" >" + _("Update") + "<span class=hide> ").append(index).append("</span></button>"); 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 c6dd398cbb..76920fc68b 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java @@ -50,6 +50,7 @@ public class PluginStarter implements Runnable { startPlugins(_context); } + /** this shouldn't throw anything */ static void startPlugins(RouterContext ctx) { Log log = ctx.logManager().getLog(PluginStarter.class); Properties props = pluginProperties(); @@ -61,7 +62,7 @@ public class PluginStarter implements Runnable { try { if (!startPlugin(ctx, app)) log.error("Failed to start plugin: " + app); - } catch (Exception e) { + } catch (Throwable e) { log.error("Failed to start plugin: " + app, e); } } @@ -69,7 +70,10 @@ public class PluginStarter implements Runnable { } } - /** @return true on success */ + /** + * @return true on success + * @throws just about anything, caller would be wise to catch Throwable + */ static boolean startPlugin(RouterContext ctx, String appName) throws Exception { Log log = ctx.logManager().getLog(PluginStarter.class); File pluginDir = new File(ctx.getAppDir(), PluginUpdateHandler.PLUGIN_DIR + '/' + appName); @@ -159,7 +163,10 @@ public class PluginStarter implements Runnable { return true; } - /** @return true on success */ + /** + * @return true on success + * @throws just about anything, caller would be wise to catch Throwable + */ static boolean stopPlugin(RouterContext ctx, String appName) throws IOException { Log log = ctx.logManager().getLog(PluginStarter.class); File pluginDir = new File(ctx.getAppDir(), PluginUpdateHandler.PLUGIN_DIR + '/' + appName); diff --git a/apps/routerconsole/java/src/net/i2p/router/web/PluginUpdateHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/PluginUpdateHandler.java index 903000fbd7..46ff441cb3 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/PluginUpdateHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/PluginUpdateHandler.java @@ -308,7 +308,10 @@ public class PluginUpdateHandler extends UpdateHandler { if (!PluginStarter.stopPlugin(_context, appName)) { // failed, ignore } - } catch (IOException e) {} // ignore + } catch (Throwable e) { + // no updateStatus() for this one + _log.error("Error stopping plugin " + appName, e); + } } else { if (Boolean.valueOf(props.getProperty("update-only")).booleanValue()) { @@ -347,8 +350,9 @@ public class PluginUpdateHandler extends UpdateHandler { updateStatus("<b>" + _("Plugin {0} installed and started", appName) + "</b>"); else updateStatus("<b>" + _("Plugin {0} installed but failed to start, check logs", appName) + "</b>"); - } catch (Exception e) { + } catch (Throwable e) { updateStatus("<b>" + _("Plugin {0} installed but failed to start", appName) + ": " + e + "</b>"); + _log.error("Error starting plugin " + appName, e); } } } 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 3e24a38c41..1117fd93ab 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/WebAppStarter.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/WebAppStarter.java @@ -30,6 +30,7 @@ public class WebAppStarter { /** * adds and starts + * @throws just about anything, caller would be wise to catch Throwable */ static void startWebApp(I2PAppContext ctx, Server server, String appName, String warPath) throws Exception { File tmpdir = new File(ctx.getTempDir(), "jetty-work-" + appName + ctx.random().nextInt()); @@ -61,6 +62,7 @@ public class WebAppStarter { /** * stop it + * @throws just about anything, caller would be wise to catch Throwable */ static void stopWebApp(Server server, String appName) { // this will return a new context if one does not exist -- GitLab