Plugins: Fix webapp classpath setting when the webapp name does not match the plugin name

This commit is contained in:
zzz
2022-01-05 16:50:33 -05:00
parent aaa1da4c66
commit 150248d8d7
3 changed files with 27 additions and 4 deletions

View File

@@ -475,7 +475,7 @@ public class PluginStarter implements Runnable {
if (log.shouldLog(Log.INFO))
log.info("Starting webapp: " + warName);
String path = files[i].getCanonicalPath();
WebAppStarter.startWebApp(ctx, server, warName, path);
WebAppStarter.startWebApp(ctx, server, warName, path, appName);
pluginWars.get(appName).add(warName);
}
} catch (IOException ioe) {

View File

@@ -88,9 +88,12 @@ public class WebAppConfiguration implements Configuration {
I2PAppContext i2pContext = I2PAppContext.getGlobalContext();
File libDir = i2pContext.getLibDir();
// FIXME this only works if war is the same name as the plugin
File pluginDir = new File(i2pContext.getConfigDir(),
PluginStarter.PLUGIN_DIR + ctxPath);
// Get the plugin name that WebAppStarter stuck in here for us
String pluginName = wac.getInitParameter(WebAppStarter.PARAM_PLUGIN_NAME);
if (pluginName == null)
pluginName = ctxPath;
File pluginDir = new File(i2pContext.getConfigDir(), PluginStarter.PLUGIN_DIR);
pluginDir = new File(pluginDir, pluginName);
File dir = libDir;
String cp;

View File

@@ -43,6 +43,7 @@ public class WebAppStarter {
private static final Map<String, Long> warModTimes = new ConcurrentHashMap<String, Long>();
static final Map<String, String> INIT_PARAMS = new HashMap<String, String>(4);
static final String PARAM_PLUGIN_NAME = "net.i2p.router.web.WebAppStarter.PLUGIN_NAME";
// There are 4 additional jars that are required to do the Servlet 3.0 annotation scanning.
// The following 4 classes were the first to get thrown as not found, for each jar.
@@ -88,6 +89,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.
* Not for plugins, use 5-arg method.
*
* As of 0.9.34, the appName will be registered with the PortMapper.
*
@@ -96,10 +98,28 @@ public class WebAppStarter {
*/
public static void startWebApp(RouterContext ctx, ContextHandlerCollection server,
String appName, String warPath) throws Exception {
startWebApp(ctx, server, appName, warPath, null);
}
/**
* Adds and starts.
* Not for routerconsole.war, it's started in RouterConsoleRunner.
*
* The appName will be registered with the PortMapper.
*
* @param pluginName may be null, will look for console/webapps.config in that plugin
* @throws Exception just about anything, caller would be wise to catch Throwable
* @since 0.9.53 added pluginName param
*/
public static void startWebApp(RouterContext ctx, ContextHandlerCollection server,
String appName, String warPath, String pluginName) throws Exception {
File tmpdir = new SecureDirectory(ctx.getTempDir(), "jetty-work-" + appName + ctx.random().nextInt());
WebAppContext wac = addWebApp(ctx, server, appName, warPath, tmpdir);
//_log.debug("Loading war from: " + warPath);
LocaleWebAppHandler.setInitParams(wac, INIT_PARAMS);
// save plugin name so WebAppConfiguration can find it
if (pluginName != null)
wac.setInitParameter(PARAM_PLUGIN_NAME, pluginName);
// default false, set to true so we get good logging,
// and the caller will know it failed
wac.setThrowUnavailableOnStartupException(true);