From d552e4d2c8b835e5f973ca13856e199488b0ccbb Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Fri, 17 Nov 2017 12:18:21 -0600 Subject: [PATCH] ARTEMIS-1698 support 'instance' web deployments --- .../artemis/component/WebServerComponent.java | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java b/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java index dedbcfd7b6..988bb535f5 100644 --- a/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java +++ b/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java @@ -95,12 +95,17 @@ public class WebServerComponent implements ExternalComponent { handlers = new HandlerList(); - Path warDir = Paths.get(artemisHome != null ? artemisHome : ".").resolve(webServerConfig.path).toAbsolutePath(); + Path homeWarDir = Paths.get(artemisHome != null ? artemisHome : ".").resolve(webServerConfig.path).toAbsolutePath(); + Path instanceWarDir = Paths.get(artemisInstance != null ? artemisInstance : ".").resolve(webServerConfig.path).toAbsolutePath(); if (webServerConfig.apps != null && webServerConfig.apps.size() > 0) { webContexts = new ArrayList<>(); for (AppDTO app : webServerConfig.apps) { - WebAppContext webContext = deployWar(app.url, app.war, warDir); + Path dirToUse = homeWarDir; + if (new File(instanceWarDir.toFile().toString() + File.separator + app.war).exists()) { + dirToUse = instanceWarDir; + } + WebAppContext webContext = deployWar(app.url, app.war, dirToUse); webContexts.add(webContext); if (app.war.startsWith("console")) { consoleUrl = webServerConfig.bind + "/" + app.url; @@ -108,21 +113,33 @@ public class WebServerComponent implements ExternalComponent { } } - ResourceHandler resourceHandler = new ResourceHandler(); - resourceHandler.setResourceBase(warDir.toString()); - resourceHandler.setDirectoriesListed(false); - resourceHandler.setWelcomeFiles(new String[]{"index.html"}); + ResourceHandler homeResourceHandler = new ResourceHandler(); + homeResourceHandler.setResourceBase(homeWarDir.toString()); + homeResourceHandler.setDirectoriesListed(false); + homeResourceHandler.setWelcomeFiles(new String[]{"index.html"}); + + ContextHandler homeContext = new ContextHandler(); + homeContext.setContextPath("/"); + homeContext.setResourceBase(homeWarDir.toString()); + homeContext.setHandler(homeResourceHandler); + homeContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); + + ResourceHandler instanceResourceHandler = new ResourceHandler(); + instanceResourceHandler.setResourceBase(instanceWarDir.toString()); + instanceResourceHandler.setDirectoriesListed(false); + instanceResourceHandler.setWelcomeFiles(new String[]{"index.html"}); + + ContextHandler instanceContext = new ContextHandler(); + instanceContext.setContextPath("/"); + instanceContext.setResourceBase(instanceWarDir.toString()); + instanceContext.setHandler(instanceResourceHandler); + homeContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); DefaultHandler defaultHandler = new DefaultHandler(); defaultHandler.setServeIcon(false); - ContextHandler context = new ContextHandler(); - context.setContextPath("/"); - context.setResourceBase(warDir.toString()); - context.setHandler(resourceHandler); - context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); - - handlers.addHandler(context); + handlers.addHandler(homeContext); + handlers.addHandler(instanceContext); handlers.addHandler(defaultHandler); server.setHandler(handlers); }