Console: Register all webapps with port mapper (ticket #1749)

This commit is contained in:
zzz
2018-03-14 12:23:37 +00:00
parent 74ea45901a
commit 9b3082be06
5 changed files with 42 additions and 5 deletions

View File

@ -541,7 +541,7 @@ public class PluginStarter implements Runnable {
Iterator <String> wars = pluginWars.get(appName).iterator();
while (wars.hasNext()) {
String warName = wars.next();
WebAppStarter.stopWebApp(warName);
WebAppStarter.stopWebApp(ctx, warName);
}
pluginWars.get(appName).clear();
}

View File

@ -1115,7 +1115,7 @@ public class RouterConsoleRunner implements RouterApp {
continue;
if (WebAppStarter.isWebAppRunning(app)) {
try {
WebAppStarter.stopWebApp(app);
WebAppStarter.stopWebApp(_context, app);
} catch (Throwable t) { t.printStackTrace(); }
}
}

View File

@ -8,6 +8,7 @@ import java.util.concurrent.ConcurrentHashMap;
import net.i2p.router.RouterContext;
import net.i2p.util.FileUtil;
import net.i2p.util.PortMapper;
import net.i2p.util.SecureDirectory;
import org.eclipse.jetty.server.Handler;
@ -50,6 +51,7 @@ public class WebAppStarter {
/**
* Adds and starts.
* Prior to 0.9.28, was not guaranteed to throw on failure.
* Not for routerconsole.war, it's started in RouterConsoleRunner.
*
* @throws Exception just about anything, caller would be wise to catch Throwable
* @since public since 0.9.33, was package private
@ -64,6 +66,10 @@ public class WebAppStarter {
// and the caller will know it failed
wac.setThrowUnavailableOnStartupException(true);
wac.start();
// Doesn't have to be right, just for presence indication
int port = ctx.portMapper().getPort(PortMapper.SVC_CONSOLE, PortMapper.DEFAULT_CONSOLE_PORT);
String host = ctx.portMapper().getActualHost(PortMapper.SVC_CONSOLE, "127.0.0.1");
ctx.portMapper().register(appName, host, port);
}
/**
@ -77,7 +83,7 @@ public class WebAppStarter {
// Jetty will happily load one context on top of another without stopping
// the first one, so we remove any previous one here
try {
stopWebApp(appName);
stopWebApp(ctx, appName);
} catch (Throwable t) {}
// To avoid ZipErrors from JarURLConnetion caching,
@ -141,10 +147,11 @@ public class WebAppStarter {
* Throws just about anything, caller would be wise to catch Throwable
* @since public since 0.9.33, was package private
*/
public static void stopWebApp(String appName) {
public static void stopWebApp(RouterContext ctx, String appName) {
ContextHandler wac = getWebApp(appName);
if (wac == null)
return;
ctx.portMapper().unregister(appName);
try {
// not graceful is default in Jetty 6?
wac.stop();

View File

@ -185,7 +185,7 @@ public class ConfigClientsHandler extends FormHandler {
_log.error("Error stopping plugin " + app, e);
}
} else {
WebAppStarter.stopWebApp(app);
WebAppStarter.stopWebApp(_context, app);
addFormNotice(_t("Stopped webapp {0}", app));
}
}

View File

@ -45,6 +45,36 @@ public class PortMapper {
public static final String SVC_HTTP_I2PCONTROL = "http_i2pcontrol";
/** @since 0.9.34 */
public static final String SVC_HTTPS_I2PCONTROL = "https_i2pcontrol";
/**
* To indicate presence, alternative to WebAppStarter.isWebappRunning().
* For actual base URL, use getConsoleURL()
* @since 0.9.34
*/
public static final String SVC_I2PSNARK = "i2psnark";
/**
* To indicate presence, alternative to WebAppStarter.isWebappRunning().
* For actual base URL, use getConsoleURL()
* @since 0.9.34
*/
public static final String SVC_I2PTUNNEL = "i2ptunnel";
/**
* To indicate presence, alternative to WebAppStarter.isWebappRunning().
* For actual base URL, use getConsoleURL()
* @since 0.9.34
*/
public static final String SVC_IMAGEGEN = "imagegen";
/**
* To indicate presence, alternative to WebAppStarter.isWebappRunning().
* For actual base URL, use getConsoleURL()
* @since 0.9.34
*/
public static final String SVC_SUSIDNS = "susidns";
/**
* To indicate presence, alternative to WebAppStarter.isWebappRunning().
* For actual base URL, use getConsoleURL()
* @since 0.9.34
*/
public static final String SVC_SUSIMAIL = "susimail";
/** @since 0.9.34 */
public static final int DEFAULT_CONSOLE_PORT = 7657;