Mercurial > hg > thermostat-ng > web-gateway
changeset 149:98a6b5520bf5
[config] Read gateway home from env var too.
Reviewed-by: jkang
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-May/022911.html
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/core/src/main/java/com/redhat/thermostat/gateway/common/core/servlet/GatewayHomeSettingContextListener.java Fri Apr 28 15:20:43 2017 +0200 @@ -0,0 +1,104 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.gateway.common.core.servlet; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +/** + * + * Sets the gateway home servlet context attribute variable by: + * <ol> + * <li>Looking at the init parameter com.redhat.thermostat.gateway.HOME + * from web.xml</li> + * <li>Looking at the environment variable THERMOSTAT_GATEWAY_HOME</li> + * </ol> + * + * in that order. The latter overrides the former. When using this listener + * then users can be assured that {@link GlobalConstants#GATEWAY_HOME_KEY} will + * be set as a servlet context attribute. + */ +public class GatewayHomeSettingContextListener implements ServletContextListener { + + private final EnvHelper envHelper; + + public GatewayHomeSettingContextListener() { + this(new EnvHelper()); + } + + GatewayHomeSettingContextListener(EnvHelper helper) { + this.envHelper = helper; + } + + @Override + public void contextInitialized(ServletContextEvent sce) { + ServletContext ctx = sce.getServletContext(); + String envGwHome = envHelper.getEnv(GlobalConstants.GATEWAY_HOME_ENV); + synchronized(ctx) { + String webXmlGwHome = ctx.getInitParameter(GlobalConstants.GATEWAY_HOME_KEY); + String gwHome; + if (envGwHome != null) { + gwHome = envGwHome; + } else if (webXmlGwHome != null) { + gwHome = webXmlGwHome; + } else { + String msg = "Gateway home not defined. " + + "Neither via THERMOSTAT_GATEWAY_HOME env var nor via web.xml"; + throw new IllegalStateException(msg); + } + ctx.setAttribute(GlobalConstants.GATEWAY_HOME_KEY, gwHome); + } + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + ServletContext ctx = sce.getServletContext(); + synchronized (ctx) { + ctx.setAttribute(GlobalConstants.GATEWAY_HOME_KEY, null); + } + } + + static class EnvHelper { + + String getEnv(String variable) { + return System.getenv(variable); + } + + } + +}
--- a/common/core/src/main/java/com/redhat/thermostat/gateway/common/core/servlet/GlobalConstants.java Tue Apr 25 14:56:15 2017 +0200 +++ b/common/core/src/main/java/com/redhat/thermostat/gateway/common/core/servlet/GlobalConstants.java Fri Apr 28 15:20:43 2017 +0200 @@ -39,5 +39,6 @@ public interface GlobalConstants { public static final String GATEWAY_PREFIX = "com.redhat.thermostat.gateway"; public static final String GATEWAY_HOME_KEY = GATEWAY_PREFIX + ".HOME"; + public static final String GATEWAY_HOME_ENV = "THERMOSTAT_GATEWAY_HOME"; public static final String SERVICE_NAME_KEY = GATEWAY_PREFIX + ".SERVICE_NAME"; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/core/src/main/java/com/redhat/thermostat/gateway/common/core/servlet/ServiceConfigGettingContextListener.java Fri Apr 28 15:20:43 2017 +0200 @@ -0,0 +1,77 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.gateway.common.core.servlet; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; + +import com.redhat.thermostat.gateway.common.core.config.Configuration; +import com.redhat.thermostat.gateway.common.core.config.ConfigurationFactory; + +public class ServiceConfigGettingContextListener extends GatewayHomeSettingContextListener { + + private ServletContext ctx; + + public ServiceConfigGettingContextListener() { + super(); + } + + ServiceConfigGettingContextListener(EnvHelper helper) { + super(helper); + } + + @Override + public void contextInitialized(ServletContextEvent sce) { + super.contextInitialized(sce); + ctx = sce.getServletContext(); + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + super.contextDestroyed(sce); + ctx = null; + } + + public Configuration getServiceConfig(String serviceName) { + String gatewayHome; + synchronized (ctx) { + gatewayHome = (String)ctx.getAttribute(GlobalConstants.GATEWAY_HOME_KEY); + } + ConfigurationFactory factory = new ConfigurationFactory(gatewayHome); + return factory.createServiceConfiguration(serviceName); + } +}
--- a/common/core/src/test/java/com/redhat/thermostat/gateway/common/core/config/ConfigurationTest.java Tue Apr 25 14:56:15 2017 +0200 +++ b/common/core/src/test/java/com/redhat/thermostat/gateway/common/core/config/ConfigurationTest.java Fri Apr 28 15:20:43 2017 +0200 @@ -40,7 +40,7 @@ import java.net.URL; import java.nio.file.Paths; -abstract class ConfigurationTest { +public abstract class ConfigurationTest { protected String getTestRoot() { URL rootUrl = ConfigurationTest.class.getResource("/test_root");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/core/src/test/java/com/redhat/thermostat/gateway/common/core/servlet/GatewayHomeSettingContextListenerTest.java Fri Apr 28 15:20:43 2017 +0200 @@ -0,0 +1,101 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.gateway.common.core.servlet; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; + +import org.junit.Before; +import org.junit.Test; + +import com.redhat.thermostat.gateway.common.core.servlet.GatewayHomeSettingContextListener.EnvHelper; + +public class GatewayHomeSettingContextListenerTest { + + private ServletContext ctxt; + private ServletContextEvent evt; + private EnvHelper mockEnv; + + @Before + public void setup() { + evt = mock(ServletContextEvent.class); + ctxt = mock(ServletContext.class); + when(evt.getServletContext()).thenReturn(ctxt); + mockEnv = mock(EnvHelper.class); + } + + @Test + public void initializedSetsGatewayHomeAsSCAfromEnv() { + String gatewayHome = "bar-gw-home-from-env"; + when(mockEnv.getEnv(eq(GlobalConstants.GATEWAY_HOME_ENV))).thenReturn(gatewayHome); + GatewayHomeSettingContextListener listener = new GatewayHomeSettingContextListener(mockEnv); + listener.contextInitialized(evt); + verify(ctxt).setAttribute(eq(GlobalConstants.GATEWAY_HOME_KEY), eq(gatewayHome)); + } + + @Test + public void initializedSetsGatewayHomeAsSCAfromWebXml() { + String gatewayHome = "foo-gw-home"; + when(ctxt.getInitParameter(eq(GlobalConstants.GATEWAY_HOME_KEY))).thenReturn(gatewayHome); + GatewayHomeSettingContextListener listener = new GatewayHomeSettingContextListener(mockEnv); + listener.contextInitialized(evt); + verify(ctxt).setAttribute(eq(GlobalConstants.GATEWAY_HOME_KEY), eq(gatewayHome)); + } + + @Test + public void envOverridesWebXml() { + String webXmlGwHome = "foo-gw-home"; + String envGwHome = "bar-gw-home-from-env"; + when(ctxt.getInitParameter(eq(GlobalConstants.GATEWAY_HOME_KEY))).thenReturn(webXmlGwHome); + when(mockEnv.getEnv(eq(GlobalConstants.GATEWAY_HOME_ENV))).thenReturn(envGwHome); + GatewayHomeSettingContextListener listener = new GatewayHomeSettingContextListener(mockEnv); + listener.contextInitialized(evt); + verify(ctxt).setAttribute(eq(GlobalConstants.GATEWAY_HOME_KEY), eq(envGwHome)); + } + + @Test + public void destroyedRemovesAttribute() { + GatewayHomeSettingContextListener listener = new GatewayHomeSettingContextListener(mockEnv); + listener.contextDestroyed(evt); + verify(ctxt).setAttribute(eq(GlobalConstants.GATEWAY_HOME_KEY), eq(null)); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/core/src/test/java/com/redhat/thermostat/gateway/common/core/servlet/ServiceConfigGettingContextListenerTest.java Fri Apr 28 15:20:43 2017 +0200 @@ -0,0 +1,93 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.gateway.common.core.servlet; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; + +import org.junit.Before; +import org.junit.Test; + +import com.redhat.thermostat.gateway.common.core.config.Configuration; +import com.redhat.thermostat.gateway.common.core.config.ConfigurationTest; +import com.redhat.thermostat.gateway.common.core.servlet.GatewayHomeSettingContextListener.EnvHelper; + +public class ServiceConfigGettingContextListenerTest extends ConfigurationTest { + + private ServletContext ctxt; + private ServletContextEvent evt; + private EnvHelper mockEnv; + private String testRoot; + + @Before + public void setup() { + evt = mock(ServletContextEvent.class); + ctxt = mock(ServletContext.class); + when(evt.getServletContext()).thenReturn(ctxt); + mockEnv = mock(EnvHelper.class); + testRoot = getTestRoot(); + when(mockEnv.getEnv(eq(GlobalConstants.GATEWAY_HOME_ENV))).thenReturn(testRoot); + } + + @Test + public void canGetServiceConfigViaListener() { + String serviceName = "test-service"; + Map<String, Object> expected = new HashMap<String, Object>(); + expected.put("foo", "service-value"); + expected.put("test", "me"); + expected.put("bar", "baz"); + Map<String, Object> servicesConfig = new HashMap<String, Object>(); + servicesConfig.put("/service1", "/path/to/microservice.war"); + expected.put("SERVICES", servicesConfig); + ServiceConfigGettingContextListener listener = new ServiceConfigGettingContextListener(mockEnv); + listener.contextInitialized(evt); + verify(ctxt).setAttribute(eq(GlobalConstants.GATEWAY_HOME_KEY), eq(testRoot)); + when(ctxt.getAttribute(eq(GlobalConstants.GATEWAY_HOME_KEY))).thenReturn(testRoot); + Configuration config = listener.getServiceConfig(serviceName); + Map<String, Object> actual = config.asMap(); + assertEquals(expected, actual); + } +}
--- a/common/mongodb/src/main/java/com/redhat/thermostat/gateway/common/mongodb/servlet/StorageConnectionSettingListener.java Tue Apr 25 14:56:15 2017 +0200 +++ b/common/mongodb/src/main/java/com/redhat/thermostat/gateway/common/mongodb/servlet/StorageConnectionSettingListener.java Fri Apr 28 15:20:43 2017 +0200 @@ -42,17 +42,17 @@ import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; import com.redhat.thermostat.gateway.common.core.config.Configuration; -import com.redhat.thermostat.gateway.common.core.config.ConfigurationFactory; import com.redhat.thermostat.gateway.common.core.servlet.GlobalConstants; +import com.redhat.thermostat.gateway.common.core.servlet.ServiceConfigGettingContextListener; import com.redhat.thermostat.gateway.common.mongodb.ThermostatMongoStorage; -public class StorageConnectionSettingListener implements ServletContextListener { +public class StorageConnectionSettingListener extends ServiceConfigGettingContextListener { @Override public void contextDestroyed(ServletContextEvent event) { + super.contextDestroyed(event); ServletContext ctx = event.getServletContext(); synchronized (ctx) { ctx.setAttribute(ServletContextConstants.MONGODB_CLIENT_ATTRIBUTE, null); @@ -61,6 +61,7 @@ @Override public void contextInitialized(ServletContextEvent event) { + super.contextInitialized(event); ServletContext ctx = event.getServletContext(); synchronized (ctx) { Map<String, String> config = getMongoStorageConfig(ctx); @@ -70,10 +71,8 @@ } Map<String, String> getMongoStorageConfig(ServletContext ctx) { - String gatewayHome = ctx.getInitParameter(GlobalConstants.GATEWAY_HOME_KEY); String serviceName = ctx.getInitParameter(GlobalConstants.SERVICE_NAME_KEY); - ConfigurationFactory factory = new ConfigurationFactory(gatewayHome); - Configuration serviceConfig = factory.createServiceConfiguration(serviceName); + Configuration serviceConfig = getServiceConfig(serviceName); Configuration mongoConfiguration = new MongoConfigurationAdapter(serviceConfig); return convert(mongoConfiguration.asMap()); }
--- a/common/mongodb/src/test/java/com/redhat/thermostat/gateway/common/mongodb/servlet/StorageConnectionSettingListenerTest.java Tue Apr 25 14:56:15 2017 +0200 +++ b/common/mongodb/src/test/java/com/redhat/thermostat/gateway/common/mongodb/servlet/StorageConnectionSettingListenerTest.java Fri Apr 28 15:20:43 2017 +0200 @@ -69,12 +69,14 @@ ctxt = mock(ServletContext.class); when(evt.getServletContext()).thenReturn(ctxt); when(ctxt.getInitParameter(eq(GlobalConstants.GATEWAY_HOME_KEY))).thenReturn(getTestGatewayRoot()); + when(ctxt.getAttribute(eq(GlobalConstants.GATEWAY_HOME_KEY))).thenReturn(getTestGatewayRoot()); when(ctxt.getInitParameter(eq(GlobalConstants.SERVICE_NAME_KEY))).thenReturn("foo-service"); } @Test public void canGetConfigFromServletContext() { StorageConnectionSettingListener listener = new StorageConnectionSettingListener(); + listener.contextInitialized(evt); Map<String, String> actual = listener.getMongoStorageConfig(ctxt); assertEquals("foo", actual.get(MongoConfiguration.MONGO_DB.name())); assertEquals("foo-user", actual.get(MongoConfiguration.MONGO_USERNAME.name()));
--- a/distribution/src/bin/thermostat-web-gateway.sh Tue Apr 25 14:56:15 2017 +0200 +++ b/distribution/src/bin/thermostat-web-gateway.sh Fri Apr 28 15:20:43 2017 +0200 @@ -63,4 +63,5 @@ sed -i -e "s|__SERVICES__|${THERMOSTAT_GATEWAY_SERVICES}|g" ${THERMOSTAT_GATEWAY_CONFIG} -java -cp "${THERMOSTAT_GATEWAY_LIBS}/*" com.redhat.thermostat.gateway.server.Start ${THERMOSTAT_GATEWAY_HOME} \ No newline at end of file +export THERMOSTAT_GATEWAY_HOME +java -cp "${THERMOSTAT_GATEWAY_LIBS}/*" com.redhat.thermostat.gateway.server.Start
--- a/server/src/main/java/com/redhat/thermostat/gateway/server/Start.java Tue Apr 25 14:56:15 2017 +0200 +++ b/server/src/main/java/com/redhat/thermostat/gateway/server/Start.java Fri Apr 28 15:20:43 2017 +0200 @@ -40,6 +40,7 @@ import com.redhat.thermostat.gateway.common.core.config.Configuration; import com.redhat.thermostat.gateway.common.core.config.ConfigurationFactory; +import com.redhat.thermostat.gateway.common.core.servlet.GlobalConstants; import com.redhat.thermostat.gateway.server.services.CoreServiceBuilder; import com.redhat.thermostat.gateway.server.services.CoreServiceBuilderFactory; import com.redhat.thermostat.gateway.server.services.CoreServiceBuilderFactory.CoreServiceType; @@ -47,10 +48,10 @@ public class Start { public static void main(String[] args) { - if (args.length != 1) { - throw new RuntimeException("Expected 1 and only one init param: THERMOSTAT_GATEWAY_HOME"); + String gatewayHome = System.getenv(GlobalConstants.GATEWAY_HOME_ENV); + if (gatewayHome == null) { + throw new RuntimeException("Environment variable THERMOSTAT_GATEWAY_HOME not defined!"); } - String gatewayHome = args[0]; ConfigurationFactory factory = new ConfigurationFactory(gatewayHome); CoreServerBuilder serverBuilder = new CoreServerBuilder();
--- a/services/jvm-gc/pom.xml Tue Apr 25 14:56:15 2017 +0200 +++ b/services/jvm-gc/pom.xml Fri Apr 28 15:20:43 2017 +0200 @@ -52,7 +52,6 @@ <properties> <com.redhat.thermostat.gateway.SERVICE_NAME>jvm-gc</com.redhat.thermostat.gateway.SERVICE_NAME> - <com.redhat.thermostat.gateway.HOME>${project.parent.parent.basedir}/distribution/target/image</com.redhat.thermostat.gateway.HOME> </properties> <build>
--- a/services/jvm-gc/src/main/webapp/WEB-INF/web.xml Tue Apr 25 14:56:15 2017 +0200 +++ b/services/jvm-gc/src/main/webapp/WEB-INF/web.xml Fri Apr 28 15:20:43 2017 +0200 @@ -58,10 +58,6 @@ </servlet-mapping> <!-- Service configuration --> <context-param> - <param-name>com.redhat.thermostat.gateway.HOME</param-name> - <param-value>@com.redhat.thermostat.gateway.HOME@</param-value> - </context-param> - <context-param> <param-name>com.redhat.thermostat.gateway.SERVICE_NAME</param-name> <param-value>@com.redhat.thermostat.gateway.SERVICE_NAME@</param-value> </context-param>
--- a/services/jvm-memory/pom.xml Tue Apr 25 14:56:15 2017 +0200 +++ b/services/jvm-memory/pom.xml Fri Apr 28 15:20:43 2017 +0200 @@ -52,7 +52,6 @@ <properties> <com.redhat.thermostat.gateway.SERVICE_NAME>jvm-memory</com.redhat.thermostat.gateway.SERVICE_NAME> - <com.redhat.thermostat.gateway.HOME>${project.parent.parent.basedir}/distribution/target/image</com.redhat.thermostat.gateway.HOME> </properties> <build> <plugins>
--- a/services/jvm-memory/src/main/webapp/WEB-INF/web.xml Tue Apr 25 14:56:15 2017 +0200 +++ b/services/jvm-memory/src/main/webapp/WEB-INF/web.xml Fri Apr 28 15:20:43 2017 +0200 @@ -58,10 +58,6 @@ </servlet-mapping> <!-- Service configuration --> <context-param> - <param-name>com.redhat.thermostat.gateway.HOME</param-name> - <param-value>@com.redhat.thermostat.gateway.HOME@</param-value> - </context-param> - <context-param> <param-name>com.redhat.thermostat.gateway.SERVICE_NAME</param-name> <param-value>@com.redhat.thermostat.gateway.SERVICE_NAME@</param-value> </context-param>
--- a/services/white-pages/pom.xml Tue Apr 25 14:56:15 2017 +0200 +++ b/services/white-pages/pom.xml Fri Apr 28 15:20:43 2017 +0200 @@ -53,7 +53,6 @@ <properties> <com.redhat.thermostat.gateway.SERVICE_NAME>white-pages</com.redhat.thermostat.gateway.SERVICE_NAME> - <com.redhat.thermostat.gateway.HOME>${project.parent.parent.basedir}/distribution/target/image</com.redhat.thermostat.gateway.HOME> </properties>
--- a/services/white-pages/src/main/java/com/redhat/thermostat/wp/service/WPConfigurationKeys.java Tue Apr 25 14:56:15 2017 +0200 +++ b/services/white-pages/src/main/java/com/redhat/thermostat/wp/service/WPConfigurationKeys.java Fri Apr 28 15:20:43 2017 +0200 @@ -36,14 +36,15 @@ package com.redhat.thermostat.wp.service; +import java.util.Arrays; +import java.util.List; + +import javax.servlet.ServletContext; + import com.redhat.thermostat.gateway.common.core.config.Configuration; import com.redhat.thermostat.gateway.common.core.config.ConfigurationFactory; import com.redhat.thermostat.gateway.common.core.servlet.GlobalConstants; -import javax.servlet.ServletContext; -import java.util.Arrays; -import java.util.List; - enum WPConfigurationKeys { JVM_GATEWAY_URLS, @@ -53,7 +54,7 @@ public List<String> get(ServletContext ctx) { String thisService = ctx.getInitParameter(GlobalConstants.SERVICE_NAME_KEY); - String gatewayHome = ctx.getInitParameter(GlobalConstants.GATEWAY_HOME_KEY); + String gatewayHome = (String)ctx.getAttribute(GlobalConstants.GATEWAY_HOME_KEY); ConfigurationFactory factory = new ConfigurationFactory(gatewayHome); Configuration serviceConfig = factory.createServiceConfiguration(thisService);
--- a/services/white-pages/src/main/webapp/WEB-INF/web.xml Tue Apr 25 14:56:15 2017 +0200 +++ b/services/white-pages/src/main/webapp/WEB-INF/web.xml Fri Apr 28 15:20:43 2017 +0200 @@ -59,11 +59,11 @@ <url-pattern>/0.0.1/*</url-pattern> </servlet-mapping> <context-param> - <param-name>com.redhat.thermostat.gateway.HOME</param-name> - <param-value>@com.redhat.thermostat.gateway.HOME@</param-value> - </context-param> - <context-param> <param-name>com.redhat.thermostat.gateway.SERVICE_NAME</param-name> <param-value>@com.redhat.thermostat.gateway.SERVICE_NAME@</param-value> </context-param> + <!-- Listener for setting gateway home properly --> + <listener> + <listener-class>com.redhat.thermostat.gateway.common.core.servlet.GatewayHomeSettingContextListener</listener-class> + </listener> </web-app>