From 2a6422bc6f8bf07b2f82ea8552775c2517e44376 Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Mon, 4 May 2015 18:33:53 -0400 Subject: [PATCH] Fixing WebServer integration after created server The web page was not loading --- .../artemis/cli/commands/Configurable.java | 19 +++++++++++++++++++ .../activemq/artemis/cli/commands/Run.java | 2 +- .../artemis/components/ExternalComponent.java | 2 +- .../artemis/component/WebServerComponent.java | 12 ++++++------ .../artemis/test/WebServerComponentTest.java | 12 ++++++------ 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java index 404b746448..7f695a76f6 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java @@ -42,6 +42,8 @@ public abstract class Configurable private String brokerInstance; + private String brokerHome; + private FileConfiguration fileConfiguration; protected String getBrokerInstance() @@ -61,6 +63,23 @@ public abstract class Configurable return brokerInstance; } + protected String getBrokerHome() + { + if (brokerHome == null) + { + /* We use File URI for locating files. The ARTEMIS_HOME variable is used to determine file paths. For Windows + the ARTEMIS_HOME variable will include back slashes (An invalid file URI character path separator). For this + reason we overwrite the ARTEMIS_HOME variable with backslashes replaced with forward slashes. */ + brokerHome = System.getProperty("artemis.home"); + if (brokerHome != null) + { + brokerHome = brokerHome.replace("\\", "/"); + System.setProperty("artemis.home", brokerHome); + } + } + return brokerHome; + } + protected FileConfiguration getFileConfiguration() throws Exception { diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java index 3aa6c96c8e..8a278e78b5 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java @@ -66,7 +66,7 @@ public class Run extends Configurable implements Action { Class clazz = this.getClass().getClassLoader().loadClass(componentDTO.componentClassName); ExternalComponent component = (ExternalComponent)clazz.newInstance(); - component.configure(componentDTO, getBrokerInstance()); + component.configure(componentDTO, getBrokerInstance(), getBrokerHome()); component.start(); components.add(component); } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/components/ExternalComponent.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/components/ExternalComponent.java index 9317c1bcb2..88398c7bf5 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/components/ExternalComponent.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/components/ExternalComponent.java @@ -21,5 +21,5 @@ import org.apache.activemq.artemis.dto.ComponentDTO; public interface ExternalComponent extends ActiveMQComponent { - void configure(ComponentDTO config, String activemqHome) throws Exception; + void configure(ComponentDTO config, String artemisInstance, String artemisHome) throws Exception; } 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 665f03bab3..0ef6de32ef 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,6 +16,8 @@ */ package org.apache.activemq.artemis.component; +import java.net.URI; + import org.apache.activemq.artemis.components.ExternalComponent; import org.apache.activemq.artemis.dto.AppDTO; import org.apache.activemq.artemis.dto.ComponentDTO; @@ -28,8 +30,6 @@ import org.eclipse.jetty.server.handler.ResourceHandler; import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.webapp.WebAppContext; -import java.net.URI; - public class WebServerComponent implements ExternalComponent { @@ -38,7 +38,7 @@ public class WebServerComponent implements ExternalComponent private WebServerDTO webServerConfig; @Override - public void configure(ComponentDTO config, String activemqHome) throws Exception + public void configure(ComponentDTO config, String artemisInstance, String artemisHome) throws Exception { webServerConfig = (WebServerDTO)config; String path = webServerConfig.path.startsWith("/") ? webServerConfig.path : "/" + webServerConfig.path; @@ -56,17 +56,17 @@ public class WebServerComponent implements ExternalComponent { for (AppDTO app : webServerConfig.apps) { - deployWar(app.url, app.war, activemqHome, path); + deployWar(app.url, app.war, artemisHome, path); } } WebAppContext handler = new WebAppContext(); handler.setContextPath("/"); - handler.setResourceBase(activemqHome + path); + handler.setResourceBase(artemisHome + path); handler.setLogUrlOnStart(true); ResourceHandler resourceHandler = new ResourceHandler(); - resourceHandler.setResourceBase(activemqHome + path); + resourceHandler.setResourceBase(artemisHome + path); resourceHandler.setDirectoriesListed(true); resourceHandler.setWelcomeFiles(new String[]{"index.html"}); diff --git a/artemis-web/src/test/java/org/apache/activemq/artemis/test/WebServerComponentTest.java b/artemis-web/src/test/java/org/apache/activemq/artemis/test/WebServerComponentTest.java index 71e1860cf2..4acaac164f 100644 --- a/artemis-web/src/test/java/org/apache/activemq/artemis/test/WebServerComponentTest.java +++ b/artemis-web/src/test/java/org/apache/activemq/artemis/test/WebServerComponentTest.java @@ -16,6 +16,11 @@ */ package org.apache.activemq.artemis.test; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; @@ -39,11 +44,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - public class WebServerComponentTest extends Assert { static final String URL = System.getProperty("url", "http://localhost:8161/WebServerComponentTest.txt"); @@ -64,7 +64,7 @@ public class WebServerComponentTest extends Assert webServerDTO.bind = "http://localhost:8161"; webServerDTO.path = "webapps"; WebServerComponent webServerComponent = new WebServerComponent(); - webServerComponent.configure(webServerDTO, "./src/test/resources/"); + webServerComponent.configure(webServerDTO, "./src/test/resources/", "./src/test/resources/"); webServerComponent.start(); // Make the connection attempt. CountDownLatch latch = new CountDownLatch(1);