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.
This commit is contained in:
Hiram Chirino 2016-01-06 14:20:14 -05:00
parent 3e6dcd05e1
commit 2e8ce98891
1 changed files with 14 additions and 8 deletions

View File

@ -16,8 +16,6 @@
*/ */
package org.apache.activemq.artemis.component; package org.apache.activemq.artemis.component;
import java.net.URI;
import org.apache.activemq.artemis.ActiveMQWebLogger; import org.apache.activemq.artemis.ActiveMQWebLogger;
import org.apache.activemq.artemis.components.ExternalComponent; import org.apache.activemq.artemis.components.ExternalComponent;
import org.apache.activemq.artemis.dto.AppDTO; 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.server.handler.ResourceHandler;
import org.eclipse.jetty.webapp.WebAppContext; 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 { public class WebServerComponent implements ExternalComponent {
private Server server; private Server server;
@ -42,7 +45,6 @@ public class WebServerComponent implements ExternalComponent {
@Override @Override
public void configure(ComponentDTO config, String artemisInstance, String artemisHome) throws Exception { public void configure(ComponentDTO config, String artemisInstance, String artemisHome) throws Exception {
webServerConfig = (WebServerDTO) config; webServerConfig = (WebServerDTO) config;
String path = webServerConfig.path.startsWith("/") ? webServerConfig.path : "/" + webServerConfig.path;
uri = new URI(webServerConfig.bind); uri = new URI(webServerConfig.bind);
server = new Server(); server = new Server();
ServerConnector connector = new ServerConnector(server); ServerConnector connector = new ServerConnector(server);
@ -53,9 +55,12 @@ public class WebServerComponent implements ExternalComponent {
handlers = new HandlerList(); handlers = new HandlerList();
Path warDir = Paths.get(artemisHome != null ? artemisHome : ".")
.resolve( webServerConfig.path ).toAbsolutePath();
if (webServerConfig.apps != null) { if (webServerConfig.apps != null) {
for (AppDTO app : webServerConfig.apps) { for (AppDTO app : webServerConfig.apps) {
deployWar(app.url, app.war, artemisHome, path); deployWar(app.url, app.war, warDir);
if (app.war.startsWith("jolokia")) { if (app.war.startsWith("jolokia")) {
jolokiaUrl = webServerConfig.bind + "/" + app.url; jolokiaUrl = webServerConfig.bind + "/" + app.url;
} }
@ -64,11 +69,11 @@ public class WebServerComponent implements ExternalComponent {
WebAppContext handler = new WebAppContext(); WebAppContext handler = new WebAppContext();
handler.setContextPath("/"); handler.setContextPath("/");
handler.setResourceBase(artemisHome + path); handler.setResourceBase(warDir.toString());
handler.setLogUrlOnStart(true); handler.setLogUrlOnStart(true);
ResourceHandler resourceHandler = new ResourceHandler(); ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(artemisHome + path); resourceHandler.setResourceBase(warDir.toString());
resourceHandler.setDirectoriesListed(true); resourceHandler.setDirectoriesListed(true);
resourceHandler.setWelcomeFiles(new String[]{"index.html"}); resourceHandler.setWelcomeFiles(new String[]{"index.html"});
@ -99,7 +104,7 @@ public class WebServerComponent implements ExternalComponent {
return server != null && server.isStarted(); 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(); WebAppContext webapp = new WebAppContext();
if (url.startsWith("/")) { if (url.startsWith("/")) {
webapp.setContextPath(url); webapp.setContextPath(url);
@ -107,7 +112,8 @@ public class WebServerComponent implements ExternalComponent {
else { else {
webapp.setContextPath("/" + url); webapp.setContextPath("/" + url);
} }
webapp.setWar(activeMQHome + path + "/" + warURL);
webapp.setWar(warDirectory.resolve(warFile).toString());
handlers.addHandler(webapp); handlers.addHandler(webapp);
} }
} }