Mercurial > hg > release > thermostat-0.9
changeset 987:527ed18dd395
Improve web archive servlet init.
Reviewed-by: vanaltj
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-February/005570.html
author | Severin Gehwolf <sgehwolf@redhat.com> |
---|---|
date | Mon, 11 Feb 2013 17:45:57 +0100 |
parents | c27dd7f147a9 |
children | 06cc96778e94 |
files | pom.xml web/server/src/main/java/com/redhat/thermostat/web/server/WebStorageEndPoint.java web/server/src/test/java/com/redhat/thermostat/web/server/WebStorageEndpointTest.java web/war/pom.xml web/war/src/main/webapp/WEB-INF/web.xml |
diffstat | 5 files changed, 63 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/pom.xml Wed Feb 20 10:24:38 2013 +0100 +++ b/pom.xml Mon Feb 11 17:45:57 2013 +0100 @@ -59,6 +59,7 @@ <thermostat.build.directory>target</thermostat.build.directory> <thermostat.java.version>1.7</thermostat.java.version> <thermostat.home>${project.build.directory}</thermostat.home> + <thermostat.web.deploy.dir>${thermostat.build.directory}/${project.build.finalName}</thermostat.web.deploy.dir> <java.dir>/usr/share/java</java.dir> <junit.version>4.10</junit.version>
--- a/web/server/src/main/java/com/redhat/thermostat/web/server/WebStorageEndPoint.java Wed Feb 20 10:24:38 2013 +0100 +++ b/web/server/src/main/java/com/redhat/thermostat/web/server/WebStorageEndPoint.java Mon Feb 11 17:45:57 2013 +0100 @@ -36,6 +36,7 @@ package com.redhat.thermostat.web.server; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -113,15 +114,20 @@ @Override public void init(ServletConfig config) throws ServletException { super.init(config); + logger.log(Level.INFO, "Initializing web service"); if (!isThermostatHomeSet()) { // This is the webapp and our entry point into thermostat's web // service. The launcher did not run and hence THERMOSTAT_HOME is // not set and we need to do this ourselves. - // In this case THERMOSTAT_HOME is in the WEB-INF/thermostat folder - // in order to make it inaccessible via HTTP. This is not a "real" - // THERMOSTAT_HOME. For now it only contains an ssl.properties file. - String thermostatHome = config.getServletContext().getRealPath( - "/WEB-INF/thermostat"); + String thermostatHome = config.getInitParameter("THERMOSTAT_HOME"); + File thermostatHomeFile = new File(thermostatHome); + if (!thermostatHomeFile.canRead()) { + // This is bad news. If we can't at least read THERMOSTAT_HOME + // we are bound to fail in some weird ways at some later point. + throw new RuntimeException("THERMOSTAT_HOME = " + + thermostatHome + + " is not readable or does not exist!"); + } logger.log(Level.INFO, "Setting THERMOSTAT_HOME for webapp to " + thermostatHome); System.setProperty("THERMOSTAT_HOME", thermostatHome);
--- a/web/server/src/test/java/com/redhat/thermostat/web/server/WebStorageEndpointTest.java Wed Feb 20 10:24:38 2013 +0100 +++ b/web/server/src/test/java/com/redhat/thermostat/web/server/WebStorageEndpointTest.java Mon Feb 11 17:45:57 2013 +0100 @@ -153,6 +153,10 @@ @Before public void setUp() throws Exception { + // Set thermostat home to something so we don't set + // it in WebStorageEndPoint.init() + System.setProperty("THERMOSTAT_HOME", "does not matter"); + mockStorage = mock(Storage.class); StorageWrapper.setStorage(mockStorage);
--- a/web/war/pom.xml Wed Feb 20 10:24:38 2013 +0100 +++ b/web/war/pom.xml Mon Feb 11 17:45:57 2013 +0100 @@ -88,28 +88,59 @@ <skip>true</skip> </configuration> </plugin> + + <!-- + Package the web archive (WAR) as an exploded WAR *and WAR. Downstream + distributions can build and deploy the war via a maven build call similar to + the following (from the top level dir): + $ mvn -Dthermostat.web.deploy.dir=<path-to-tomcat>/webapps/thermostat clean package + --> <plugin> - <artifactId>maven-resources-plugin</artifactId> - <version>2.5</version> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-war-plugin</artifactId> + <version>2.3</version> <executions> <execution> - <id>copy-logging-properties</id> - <phase>prepare-package</phase> + <id>exploded-war</id> + <phase>package</phase> <goals> - <goal>copy-resources</goal> + <goal>exploded</goal> </goals> <configuration> - <outputDirectory>src/main/webapp/WEB-INF/thermostat</outputDirectory> - <resources> + <!-- web.xml contains properties, which we'd like to have interpolated --> + <webResources> <resource> - <directory>src/../../../distribution/config</directory> - <targetPath>etc</targetPath> <filtering>true</filtering> + <directory>src/main/webapp</directory> <includes> - <include>ssl.properties</include> + <include>**/web.xml</include> </includes> </resource> - </resources> + </webResources> + <warSourceDirectory>src/main/webapp</warSourceDirectory> + <webXml>src/main/webapp/WEB-INF/web.xml</webXml> + <webappDirectory>${thermostat.web.deploy.dir}</webappDirectory> + </configuration> + </execution> + <execution> + <id>war</id> + <phase>package</phase> + <goals> + <goal>war</goal> + </goals> + <configuration> + <!-- web.xml contains properties, which we'd like to have interpolated --> + <webResources> + <resource> + <filtering>true</filtering> + <directory>src/main/webapp</directory> + <includes> + <include>**/web.xml</include> + </includes> + </resource> + </webResources> + <warSourceDirectory>src/main/webapp</warSourceDirectory> + <webXml>src/main/webapp/WEB-INF/web.xml</webXml> </configuration> </execution> </executions>
--- a/web/war/src/main/webapp/WEB-INF/web.xml Wed Feb 20 10:24:38 2013 +0100 +++ b/web/war/src/main/webapp/WEB-INF/web.xml Mon Feb 11 17:45:57 2013 +0100 @@ -12,6 +12,11 @@ <param-value>com.redhat.thermostat.storage.mongodb.MongoStorageProvider</param-value> </init-param> <init-param> + <!-- Absolute path to THERMOSTAT_HOME --> + <param-name>THERMOSTAT_HOME</param-name> + <param-value>${project.build.directory}/../../../distribution/target/</param-value> + </init-param> + <init-param> <param-name>storage.endpoint</param-name> <param-value>mongodb://127.0.0.1:27518</param-value> </init-param>