Runtime properties
This commit is contained in:
@@ -20,10 +20,14 @@ package org.jeudego.pairgoth.container;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
@@ -53,8 +57,8 @@ public class ServerMain
|
||||
|
||||
private void run() throws Throwable
|
||||
{
|
||||
// create server and web context
|
||||
Server server = new Server(8080);
|
||||
|
||||
WebAppContext context = new WebAppContext() {
|
||||
@Override
|
||||
public boolean isServerResource(String name, URL url)
|
||||
@@ -64,6 +68,22 @@ public class ServerMain
|
||||
};
|
||||
context.setContextPath("/");
|
||||
|
||||
// pairgoth runtime properties
|
||||
File properties = new File("./pairgoth.properties");
|
||||
if (properties.exists()) {
|
||||
Properties props = new Properties();
|
||||
props.load(new FileReader(properties));
|
||||
for (Map.Entry<Object, Object> entry: props.entrySet()) {
|
||||
String property = (String)entry.getKey();
|
||||
String value = (String)entry.getValue();
|
||||
if (property.startsWith("logger.")) {
|
||||
context.setInitParameter("webapp-slf4j-logger." + property.substring(7), value);
|
||||
} else {
|
||||
System.setProperty("pairgoth." + property, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (getOperationalMode())
|
||||
{
|
||||
case PROD:
|
||||
|
3
debug.sh
3
debug.sh
@@ -1,4 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
mvn package
|
||||
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5006 -jar application/target/pairgoth-engine.war
|
||||
mvn package && java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5006 -jar application/target/pairgoth-engine.war
|
||||
|
@@ -11,5 +11,3 @@ smtp.password =
|
||||
|
||||
# logging
|
||||
logger.level = trace
|
||||
logger.notification = false
|
||||
# logger.notification = <level>:smtp:<smtp-host>:<smtp-port>:<from-address>:<to-address>
|
||||
|
@@ -55,32 +55,14 @@ class WebappManager : ServletContextListener, ServletContextAttributeListener, H
|
||||
context.setAttribute("manager", this)
|
||||
webappRoot = context.getRealPath("/")
|
||||
try {
|
||||
properties.load(context.getResourceAsStream("/WEB-INF/pairgoth.properties"))
|
||||
val submaps: MutableMap<String, MutableMap<String, String>> = HashMap()
|
||||
for (prop in properties.stringPropertyNames()) {
|
||||
val value = properties.getProperty(prop)
|
||||
// load default properties
|
||||
properties.load(context.getResourceAsStream("/WEB-INF/pairgoth.default.properties"))
|
||||
// override with system properties after stripping off the 'pairgoth.' prefix
|
||||
System.getProperties().filter { (key, value) -> key is String && key.startsWith(PAIRGOTH_PROPERTIES_PREFIX)
|
||||
}.forEach { (key, value) ->
|
||||
properties[(key as String).removePrefix(PAIRGOTH_PROPERTIES_PREFIX)] = value
|
||||
}
|
||||
|
||||
// filter out missing values and passwords
|
||||
if (value.startsWith("\${") || prop.contains("password")) continue
|
||||
context.setAttribute(prop, value)
|
||||
|
||||
// also support one level of submaps (TODO - more)
|
||||
val dot = prop.indexOf('.')
|
||||
if (dot != -1) {
|
||||
val topKey = prop.substring(0, dot)
|
||||
val subKey = prop.substring(dot + 1)
|
||||
if ("password" == subKey) continue
|
||||
var submap = submaps[topKey]
|
||||
if (submap == null) {
|
||||
submap = HashMap()
|
||||
submaps[topKey] = submap
|
||||
}
|
||||
submap[subKey] = value
|
||||
}
|
||||
}
|
||||
for ((key, value) in submaps) {
|
||||
context.setAttribute(key, value)
|
||||
}
|
||||
logger.info("Using profile {}", properties.getProperty("webapp.env"))
|
||||
|
||||
// set system user agent string to empty string
|
||||
@@ -119,6 +101,7 @@ class WebappManager : ServletContextListener, ServletContextAttributeListener, H
|
||||
override fun sessionDestroyed(se: HttpSessionEvent) {}
|
||||
|
||||
companion object {
|
||||
const val PAIRGOTH_PROPERTIES_PREFIX = "pairgoth."
|
||||
lateinit var webappRoot: String
|
||||
lateinit var context: ServletContext
|
||||
private val webServices: MutableMap<String?, Pair<Runnable, Thread?>> = TreeMap()
|
||||
|
@@ -1,2 +0,0 @@
|
||||
format = [%level] %ip [%logger] %message (@%file:%line:%column)
|
||||
level = trace
|
14
webapp/src/main/webapp/WEB-INF/pairgoth.default.properties
Normal file
14
webapp/src/main/webapp/WEB-INF/pairgoth.default.properties
Normal file
@@ -0,0 +1,14 @@
|
||||
# webapp
|
||||
webapp.env = dev
|
||||
webapp.url = http://localhost:8080
|
||||
|
||||
# smtp
|
||||
smtp.sender =
|
||||
smtp.host =
|
||||
smtp.port = 587
|
||||
smtp.user =
|
||||
smtp.password =
|
||||
|
||||
# logging
|
||||
logger.level = trace
|
||||
logger.format = [%level] %ip [%logger] %message
|
@@ -53,17 +53,4 @@
|
||||
<param-name>webapp-slf4j-logger.format</param-name>
|
||||
<param-value>%logger [%level] [%ip] %message @%file:%line:%column</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>webapp-slf4j-logger.level</param-name>
|
||||
<param-value>trace</param-value>
|
||||
<!-- CB TODO parametrize from webapp properties file
|
||||
<param-value>${logger.level}</param-value>
|
||||
-->
|
||||
</context-param>
|
||||
<!--
|
||||
<context-param>
|
||||
<param-name>webapp-slf4j-logger.notification</param-name>
|
||||
<param-value>${logger.notification}</param-value>
|
||||
</context-param>
|
||||
-->
|
||||
</web-app>
|
||||
|
Reference in New Issue
Block a user