From 5a6522399ce01e964f3028a511b60a41071a4414 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Fri, 3 May 2024 16:46:11 -0700 Subject: [PATCH] Remove support for multiple WAR files (#377) --- README.md | 21 +---- src/main/java/winstone/HostConfiguration.java | 83 ++----------------- src/main/java/winstone/HostGroup.java | 15 +--- src/main/java/winstone/Launcher.java | 4 +- src/main/java/winstone/cmdline/Option.java | 1 - .../winstone/LocalStrings.properties | 8 +- 6 files changed, 13 insertions(+), 119 deletions(-) diff --git a/README.md b/README.md index b5ad9ffb..8d565387 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,6 @@ To run a single war file: java -jar winstone.jar --warfile= (+ other options) -To run a directory full of war files: - - java -jar winstone.jar --webappsDir= (+ other options) - To run locally exploded web archive: java -jar winstone.jar --webroot= (+ other options) @@ -51,10 +47,9 @@ To run locally exploded web archive: Winstone Servlet Engine, (c) 2003-2006 Rick Knowles Usage: java winstone.jar [--option=value] [--option=value] [etc] - Required options: either --webroot OR --warfile OR --webappsDir + Required options: either --webroot OR --warfile --webroot = set document root folder. --warfile = set location of warfile to extract from. - --webappsDir = set directory for multiple webapps to be deployed from Other options: --javaHome = Override the JAVA_HOME variable --config = load configuration properties from here. Default is ./winstone.properties @@ -146,20 +141,6 @@ just supply the warfile or webroot directory as an argument: * `java -jar winstone.jar --webroot=`, or * `java -jar winstone.jar --warfile=` -If you need to support *multiple webapps*, use the `--webappsDir` switch, -to which you pass a directory that contains multiple warfiles/webroots. - -* `java -jar winstone.jar --webappsDir=` - -The directory becomes the prefix name for that webapp (so hello becomes `/hello`, etc). -The directory named ROOT becomes the no-prefix webapp. - -So, for example, if you had a directory `/usr/local/webapps` which contained -sub-directories `ROOT` and `test`, if you executed -`java -jar winstone.jar --webappsDir=/usr/local/webapps`, you would find that -the test folder would act as a webroot for requests prefixed with -`/test`, while other requests would go to the webapp in the `ROOT` folder - ## Development If you have some unit test failures you may add an interface/ip alias such diff --git a/src/main/java/winstone/HostConfiguration.java b/src/main/java/winstone/HostConfiguration.java index cdfd204d..ddb185f1 100644 --- a/src/main/java/winstone/HostConfiguration.java +++ b/src/main/java/winstone/HostConfiguration.java @@ -13,7 +13,6 @@ import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.RequestLog; import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.server.handler.RequestLogHandler; import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer; @@ -58,8 +57,8 @@ public class HostConfiguration { private MimeTypes mimeTypes = new MimeTypes(); private final LoginService loginService; - public HostConfiguration(Server server, String hostname, ClassLoader commonLibCL, - @NonNull Map args, File webappsDir) throws IOException { + public HostConfiguration(Server server, String hostname, ClassLoader commonLibCL, @NonNull Map args) + throws IOException { this.server = server; this.hostname = hostname; this.args = new HashMap<>(args); @@ -79,18 +78,12 @@ public HostConfiguration(Server server, String hostname, ClassLoader commonLibCL File warfile = Option.WARFILE.get(this.args); File webroot = Option.WEBROOT.get(this.args); - Handler handler; - // If single-webapp mode - if (webappsDir == null && ((warfile != null) || (webroot != null))) { - String prefix = Option.PREFIX.get(this.args); - if (prefix.endsWith("/")) // trim off the trailing '/' that Jetty doesn't like - prefix = prefix.substring(0,prefix.length()-1); - handler = configureAccessLog(create(getWebRoot(webroot,warfile), prefix),"webapp"); - } - // Otherwise multi-webapp mode - else { - handler = initMultiWebappDir(webappsDir); + String prefix = Option.PREFIX.get(this.args); + if (prefix.endsWith("/")) { + // trim off the trailing '/' that Jetty doesn't like + prefix = prefix.substring(0, prefix.length() - 1); } + Handler handler = configureAccessLog(create(getWebRoot(webroot, warfile), prefix), "webapp"); {// load additional mime types loadBuiltinMimeTypes(); @@ -343,66 +336,4 @@ private void deleteRecursive(File dir) { Logger.logDirectMessage(Level.WARNING, null, "Failed to delete dirs " + dir.getAbsolutePath(), ex); } } - - @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "false positive, we're not being called from a webapp") - protected ContextHandlerCollection initMultiWebappDir(File webappsDir) { - ContextHandlerCollection webApps = new ContextHandlerCollection(); - - if (webappsDir == null) { - webappsDir = new File("webapps"); - } - if (!webappsDir.exists()) { - throw new WinstoneException(Launcher.RESOURCES.getString("HostConfig.WebAppDirNotFound", webappsDir.getPath())); - } else if (!webappsDir.isDirectory()) { - throw new WinstoneException(Launcher.RESOURCES.getString("HostConfig.WebAppDirIsNotDirectory", webappsDir.getPath())); - } else { - File[] children = webappsDir.listFiles(); - if (children != null) { - for (File aChildren : children) { - String childName = aChildren.getName(); - - // Check any directories for warfiles that match, and skip: only deploy the war file - if (aChildren.isDirectory()) { - File matchingWarFile = new File(webappsDir, aChildren.getName() + ".war"); - if (matchingWarFile.exists() && matchingWarFile.isFile()) { - Logger.log(Level.FINER, Launcher.RESOURCES, "HostConfig.SkippingWarfileDir", childName); - } else { - String prefix = childName.equalsIgnoreCase("ROOT") ? "" : "/" + childName; - if (!this.webapps.containsKey(prefix)) { - try { - WebAppContext context = create(aChildren, prefix); - webApps.addHandler(configureAccessLog(context,childName)); - Logger.log(Level.INFO, Launcher.RESOURCES, "HostConfig.DeployingWebapp", childName); - } catch (Throwable err) { - Logger.log(Level.SEVERE, Launcher.RESOURCES, "HostConfig.WebappInitError", prefix, err); - } - } - } - } else if (childName.endsWith(".war")) { - String outputName = childName.substring(0, childName.lastIndexOf(".war")); - String prefix = outputName.equalsIgnoreCase("ROOT") ? "" : "/" + outputName; - - if (!this.webapps.containsKey(prefix)) { - File outputDir = new File(webappsDir, outputName); - try { - Files.createDirectories(outputDir.toPath()); - } catch (Exception ex) { - Logger.logDirectMessage(Level.WARNING, null, "Failed to mkdirs " + outputDir.getAbsolutePath(), ex); - } - try { - WebAppContext context = create( - getWebRoot(new File(webappsDir, outputName), aChildren), prefix); - webApps.addHandler(configureAccessLog(context,outputName)); - Logger.log(Level.INFO, Launcher.RESOURCES, "HostConfig.DeployingWebapp", childName); - } catch (Throwable err) { - Logger.log(Level.SEVERE, Launcher.RESOURCES, "HostConfig.WebappInitError", prefix, err); - } - } - } - } - } - } - - return webApps; - } } diff --git a/src/main/java/winstone/HostGroup.java b/src/main/java/winstone/HostGroup.java index 05134f15..e22f1f1d 100644 --- a/src/main/java/winstone/HostGroup.java +++ b/src/main/java/winstone/HostGroup.java @@ -7,9 +7,7 @@ package winstone; import org.eclipse.jetty.server.Server; -import winstone.cmdline.Option; -import java.io.File; import java.io.IOException; import java.util.Hashtable; import java.util.Map; @@ -38,12 +36,8 @@ public HostGroup( this.server = server; this.hostConfigs = new Hashtable<>(); - // Is this the single or multiple configuration ? Check args - File webappsDir = Option.WEBAPPS_DIR.get(args); - // If host mode - initHost(webappsDir, DEFAULT_HOSTNAME, commonLibCL, - args); + initHost(DEFAULT_HOSTNAME, commonLibCL, args); this.defaultHostName = DEFAULT_HOSTNAME; Logger.log(Level.FINER, Launcher.RESOURCES, "HostGroup.InitSingleComplete", this.hostConfigs.size() + "", this.hostConfigs.keySet() + ""); @@ -59,12 +53,9 @@ public HostConfiguration getHostByName(String hostname) { return this.hostConfigs.get(this.defaultHostName); } - protected void initHost(File webappsDir, String hostname, - ClassLoader commonLibCL, - Map args) throws IOException { + protected void initHost(String hostname, ClassLoader commonLibCL, Map args) throws IOException { Logger.log(Level.FINER, Launcher.RESOURCES, "HostGroup.DeployingHost", hostname); - HostConfiguration config = new HostConfiguration(server, hostname, commonLibCL, - args, webappsDir); + HostConfiguration config = new HostConfiguration(server, hostname, commonLibCL, args); this.hostConfigs.put(hostname, config); } } diff --git a/src/main/java/winstone/Launcher.java b/src/main/java/winstone/Launcher.java index 23341cae..98997b36 100644 --- a/src/main/java/winstone/Launcher.java +++ b/src/main/java/winstone/Launcher.java @@ -484,8 +484,7 @@ public static void main(String[] argv) throws IOException { deployEmbeddedWarfile(args); // Check for embedded warfile - if (!Option.WEBROOT.isIn(args) && !Option.WARFILE.isIn(args) - && !Option.WEBAPPS_DIR.isIn(args)) { + if (!Option.WEBROOT.isIn(args) && !Option.WARFILE.isIn(args)) { printUsage(); return; } @@ -561,7 +560,6 @@ protected static void deployEmbeddedWarfile(Map args) throws IOE Option.WARFILE.put(args, tempWarfile.getAbsolutePath()); Option.WARFILE.put(args, tempWebroot.getAbsolutePath()); - Option.WEBAPPS_DIR.remove(args); } } diff --git a/src/main/java/winstone/cmdline/Option.java b/src/main/java/winstone/cmdline/Option.java index 4aaa8f8e..eea378ac 100644 --- a/src/main/java/winstone/cmdline/Option.java +++ b/src/main/java/winstone/cmdline/Option.java @@ -37,7 +37,6 @@ public static List> all(Class clazz) { public static final OFile WEBROOT=file("webroot"); public static final OFile WARFILE=file("warfile"); - public static final OFile WEBAPPS_DIR=file("webappsDir"); public static final OFile JAVA_HOME=file("javaHome"); public static final OFile CONFIG=file("config"); public static final OString PREFIX=string("prefix",""); diff --git a/src/main/resources/winstone/LocalStrings.properties b/src/main/resources/winstone/LocalStrings.properties index 1785ed5c..ad3acb12 100644 --- a/src/main/resources/winstone/LocalStrings.properties +++ b/src/main/resources/winstone/LocalStrings.properties @@ -4,16 +4,11 @@ WebAppConfig.LoggerError=Error instantiating access logger class: [#0] WebAppConfig.LoggerDisabled=Access logging disabled - no logger class defined HostConfig.PrefixUnknown=Unknown webapp prefix: [#0] -HostConfig.WebAppDirNotFound=Webapps dir [#0] not found -HostConfig.WebAppDirIsNotDirectory=Webapps dir [#0] is not a directory HostConfig.InitComplete=Initialized [#0] webapps: prefixes - [#1] -HostConfig.SkippingWarfileDir=Webapp dir deployment [#0] skipped, since there is a war file of the same name to check for re-extraction -HostConfig.DeployingWebapp=Deployed web application found at [#0] HostConfig.WarFileInvalid=The warfile supplied is unavailable or invalid ([#0]) HostConfig.WebRootNotDirectory=The webroot supplied is not a valid directory ([#0]) HostConfig.WebRootExists=The webroot supplied already exists - overwriting where newer ([#0]) HostConfig.BeginningWarExtraction=Beginning extraction from war file -HostConfig.WebappInitError=Error initializing web application: prefix [[#0]] HostGroup.InitSingleComplete=Initialized in non-virtual-host mode HostGroup.DeployingHost=Deploying host found at [#0] @@ -47,10 +42,9 @@ Launcher.ExtraLibFolder=You are using an extra library folder, support for which # Keep synchronized with jenkinsci/jenkins/war/src/main/java/executable/Main.java Launcher.UsageInstructions.Header=[#0], (c) 2003-2006 Rick Knowles\n\ Usage: java winstone.jar [--option=value] [--option=value] [etc]\n\n\ -Required options: either --webroot OR --warfile OR --webappsDir \n\ +Required options: either --webroot OR --warfile \n\ \ --webroot = set document root folder.\n\ \ --warfile = set location of warfile to extract from.\n\ -\ --webappsDir = set directory for multiple webapps to be deployed from\n\ Other options:\n\ Launcher.UsageInstructions.Options=\