Skip to content

Commit

Permalink
moved loading of ovodata.props from WebappListener to PropertyManager…
Browse files Browse the repository at this point in the history
… and added env override to make stand-alone config loading consistent with hosted server
  • Loading branch information
ronreynolds committed Feb 6, 2012
1 parent d228500 commit c2d35d5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
24 changes: 7 additions & 17 deletions src/ovation/odata/service/servlet/WebappListener.java
@@ -1,6 +1,5 @@
package ovation.odata.service.servlet;

import java.io.FileInputStream;
import java.util.Properties;

import javax.servlet.ServletContext;
Expand All @@ -10,7 +9,6 @@
import org.apache.log4j.Logger;

import ovation.odata.util.CollectionUtils;
import ovation.odata.util.DataContextCache;
import ovation.odata.util.PropertyManager;
import ovation.odata.util.Props;

Expand All @@ -25,25 +23,17 @@ public class WebappListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
_log.info("context started");
ServletContext ctx = event.getServletContext();

Properties rootProps = PropertyManager.getProperties(null);
// add web.xml init-params to the global root properties
for (String name : CollectionUtils.makeIterable(ctx.getInitParameterNames())) {
rootProps.setProperty(name, ctx.getInitParameter(name));
}
// check for props file prop and load that as well
String propFilePath = rootProps.getProperty("ovodata.props");
if (propFilePath != null) {
FileInputStream fis = null;
try {
fis = new FileInputStream(propFilePath);
rootProps.load(fis);
} catch (Exception ex) {
_log.warn("failed to load '" + propFilePath + "'");
} finally {
try { fis.close(); } catch (Exception ignore) {}
}
}

String dbFile = System.getenv("OVODATA_CONNECTION_FILE");

// this environment variable must take precedence over all other settings (including web.xml <init-params>)
// this code is duplicated in PropertyManager to maintain consistent prop loading with stand-alone servers
// (which don't have a web.xml collection of over-rides).
String dbFile = System.getenv(PropertyManager.OVODATA_CON_FILE);
if (dbFile != null) {
rootProps.setProperty(Props.DC_FILE_DEFAULT, dbFile);
}
Expand Down
39 changes: 36 additions & 3 deletions src/ovation/odata/util/PropertyManager.java
Expand Up @@ -10,10 +10,43 @@
import com.google.common.collect.Maps;

public class PropertyManager {
public static final Logger _log = Logger.getLogger(PropertyManager.class);
public static final Logger _log = Logger.getLogger(PropertyManager.class);
public static final String OVODATA_CON_FILE = "OVODATA_CONNECTION_FILE";
public static final String OVODATA_PROP_FILE = "ovodata.props";
public static final String OVODATA_PROP_FILE_DEF= "/var/lib/ovation/ovodata.props";

// map of classes to their associated properties (not really used, except for the 'null' entry, which is the root prop)
private static final HashMap<Class<?>, Properties> _propertiesMap = Maps.newHashMap();
static {
setProperties(null, System.getProperties()); // start with system props
Properties rootProps = new Properties();
// set up the defaults
rootProps.setProperty(OVODATA_PROP_FILE, OVODATA_PROP_FILE_DEF);
rootProps.putAll(System.getProperties()); // add system props

// check for props file prop and load that on top of System props
String propFilePath = rootProps.getProperty(OVODATA_PROP_FILE);
if (propFilePath != null) {
FileInputStream fis = null;
try {
fis = new FileInputStream(propFilePath);
rootProps.load(fis);
} catch (Exception ex) {
_log.warn("failed to load '" + propFilePath + "'");
} finally {
try { fis.close(); } catch (Exception ignore) {}
}
}

// check for OVODATA_CONNECTION_FILE environment variable as final over-ride of Ovation DB file
String dbFile = System.getenv(OVODATA_CON_FILE);
if (dbFile != null) {
rootProps.setProperty(Props.DC_FILE_DEFAULT, dbFile);
}

setProperties(null, rootProps);
if (_log.isDebugEnabled()) {
_log.debug("default root props : " + rootProps);
}
}

/**
Expand All @@ -36,7 +69,7 @@ public static Properties getProperties(Class<?> clazz) {
String propName = "props";
int nextDot = 0;
while (true) {
_log.debug(propName);
_log.trace(propName);
String propFile = System.getProperty(propName, null);
if (propFile != null) {
FileInputStream fis = null;
Expand Down

0 comments on commit c2d35d5

Please sign in to comment.