Runtime properties
This commit is contained in:
@@ -20,10 +20,14 @@ package org.jeudego.pairgoth.container;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
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.server.Server;
|
||||||
import org.eclipse.jetty.util.resource.PathResource;
|
import org.eclipse.jetty.util.resource.PathResource;
|
||||||
@@ -53,8 +57,8 @@ public class ServerMain
|
|||||||
|
|
||||||
private void run() throws Throwable
|
private void run() throws Throwable
|
||||||
{
|
{
|
||||||
|
// create server and web context
|
||||||
Server server = new Server(8080);
|
Server server = new Server(8080);
|
||||||
|
|
||||||
WebAppContext context = new WebAppContext() {
|
WebAppContext context = new WebAppContext() {
|
||||||
@Override
|
@Override
|
||||||
public boolean isServerResource(String name, URL url)
|
public boolean isServerResource(String name, URL url)
|
||||||
@@ -64,6 +68,22 @@ public class ServerMain
|
|||||||
};
|
};
|
||||||
context.setContextPath("/");
|
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())
|
switch (getOperationalMode())
|
||||||
{
|
{
|
||||||
case PROD:
|
case PROD:
|
||||||
|
3
debug.sh
3
debug.sh
@@ -1,4 +1,3 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
mvn package
|
mvn package && java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5006 -jar application/target/pairgoth-engine.war
|
||||||
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
|
# logging
|
||||||
logger.level = trace
|
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)
|
context.setAttribute("manager", this)
|
||||||
webappRoot = context.getRealPath("/")
|
webappRoot = context.getRealPath("/")
|
||||||
try {
|
try {
|
||||||
properties.load(context.getResourceAsStream("/WEB-INF/pairgoth.properties"))
|
// load default properties
|
||||||
val submaps: MutableMap<String, MutableMap<String, String>> = HashMap()
|
properties.load(context.getResourceAsStream("/WEB-INF/pairgoth.default.properties"))
|
||||||
for (prop in properties.stringPropertyNames()) {
|
// override with system properties after stripping off the 'pairgoth.' prefix
|
||||||
val value = properties.getProperty(prop)
|
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"))
|
logger.info("Using profile {}", properties.getProperty("webapp.env"))
|
||||||
|
|
||||||
// set system user agent string to empty string
|
// set system user agent string to empty string
|
||||||
@@ -119,6 +101,7 @@ class WebappManager : ServletContextListener, ServletContextAttributeListener, H
|
|||||||
override fun sessionDestroyed(se: HttpSessionEvent) {}
|
override fun sessionDestroyed(se: HttpSessionEvent) {}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
const val PAIRGOTH_PROPERTIES_PREFIX = "pairgoth."
|
||||||
lateinit var webappRoot: String
|
lateinit var webappRoot: String
|
||||||
lateinit var context: ServletContext
|
lateinit var context: ServletContext
|
||||||
private val webServices: MutableMap<String?, Pair<Runnable, Thread?>> = TreeMap()
|
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-name>webapp-slf4j-logger.format</param-name>
|
||||||
<param-value>%logger [%level] [%ip] %message @%file:%line:%column</param-value>
|
<param-value>%logger [%level] [%ip] %message @%file:%line:%column</param-value>
|
||||||
</context-param>
|
</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>
|
</web-app>
|
||||||
|
Reference in New Issue
Block a user