From 2e8ce98891f38c62b3c2a4e8762349a50ed6bc32 Mon Sep 17 00:00:00 2001 From: Hiram Chirino Date: Wed, 6 Jan 2016 14:20:14 -0500 Subject: [PATCH] Clean up path handling in in the WebServerComponent a bit. - The if the web element's path attribute is configured with an absolute path like `path="/tmp/artemis/web"` then use it as an absolute path instead of trying to make it a sub dir of artemis home. --- .../artemis/component/WebServerComponent.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 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 05bf7fd7f9..396c2d4748 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 @@ -16,8 +16,6 @@ */ package org.apache.activemq.artemis.component; -import java.net.URI; - import org.apache.activemq.artemis.ActiveMQWebLogger; import org.apache.activemq.artemis.components.ExternalComponent; import org.apache.activemq.artemis.dto.AppDTO; @@ -31,6 +29,11 @@ import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.server.handler.ResourceHandler; import org.eclipse.jetty.webapp.WebAppContext; +import java.io.IOException; +import java.net.URI; +import java.nio.file.Path; +import java.nio.file.Paths; + public class WebServerComponent implements ExternalComponent { private Server server; @@ -42,7 +45,6 @@ public class WebServerComponent implements ExternalComponent { @Override public void configure(ComponentDTO config, String artemisInstance, String artemisHome) throws Exception { webServerConfig = (WebServerDTO) config; - String path = webServerConfig.path.startsWith("/") ? webServerConfig.path : "/" + webServerConfig.path; uri = new URI(webServerConfig.bind); server = new Server(); ServerConnector connector = new ServerConnector(server); @@ -53,9 +55,12 @@ public class WebServerComponent implements ExternalComponent { handlers = new HandlerList(); + Path warDir = Paths.get(artemisHome != null ? artemisHome : ".") + .resolve( webServerConfig.path ).toAbsolutePath(); + if (webServerConfig.apps != null) { for (AppDTO app : webServerConfig.apps) { - deployWar(app.url, app.war, artemisHome, path); + deployWar(app.url, app.war, warDir); if (app.war.startsWith("jolokia")) { jolokiaUrl = webServerConfig.bind + "/" + app.url; } @@ -64,11 +69,11 @@ public class WebServerComponent implements ExternalComponent { WebAppContext handler = new WebAppContext(); handler.setContextPath("/"); - handler.setResourceBase(artemisHome + path); + handler.setResourceBase(warDir.toString()); handler.setLogUrlOnStart(true); ResourceHandler resourceHandler = new ResourceHandler(); - resourceHandler.setResourceBase(artemisHome + path); + resourceHandler.setResourceBase(warDir.toString()); resourceHandler.setDirectoriesListed(true); resourceHandler.setWelcomeFiles(new String[]{"index.html"}); @@ -99,7 +104,7 @@ public class WebServerComponent implements ExternalComponent { return server != null && server.isStarted(); } - private void deployWar(String url, String warURL, String activeMQHome, String path) { + private void deployWar(String url, String warFile, Path warDirectory) throws IOException { WebAppContext webapp = new WebAppContext(); if (url.startsWith("/")) { webapp.setContextPath(url); @@ -107,7 +112,8 @@ public class WebServerComponent implements ExternalComponent { else { webapp.setContextPath("/" + url); } - webapp.setWar(activeMQHome + path + "/" + warURL); + + webapp.setWar(warDirectory.resolve(warFile).toString()); handlers.addHandler(webapp); } }