Merge pull request #5 from xluandc/master
Support for optional, external configuration file Added additional configurable properties
This commit is contained in:
@@ -48,6 +48,10 @@ public class FhirServerConfigCommon {
|
||||
Boolean allowPlaceholderReferences = HapiProperties.getAllowPlaceholderReferences();
|
||||
retVal.setAutoCreatePlaceholderReferenceTargets(allowPlaceholderReferences);
|
||||
ourLog.info("Server configured to " + (allowPlaceholderReferences ? "allow" : "deny") + " placeholder references");
|
||||
|
||||
Integer maxFetchSize = HapiProperties.getMaximumFetchSize();
|
||||
retVal.setFetchSizeDefaultMaximum(maxFetchSize);
|
||||
ourLog.info("Server configured to have a maximum fetch size of " + (maxFetchSize == Integer.MAX_VALUE? "'unlimited'": maxFetchSize));
|
||||
|
||||
// You can enable these if you want to support Subscriptions from your server
|
||||
if (HapiProperties.getSubscriptionRestHookEnabled()) {
|
||||
@@ -82,6 +86,7 @@ public class FhirServerConfigCommon {
|
||||
retVal.setUrl(HapiProperties.getDataSourceUrl());
|
||||
retVal.setUsername(HapiProperties.getDataSourceUsername());
|
||||
retVal.setPassword(HapiProperties.getDataSourcePassword());
|
||||
retVal.setMaxTotal(HapiProperties.getDataSourceMaxPoolSize());
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import ca.uhn.fhir.rest.server.ETagSupportEnum;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
public class HapiProperties {
|
||||
@@ -14,6 +15,7 @@ public class HapiProperties {
|
||||
static final String ALLOW_MULTIPLE_DELETE = "allow_multiple_delete";
|
||||
static final String ALLOW_PLACEHOLDER_REFERENCES = "allow_placeholder_references";
|
||||
static final String DATASOURCE_DRIVER = "datasource.driver";
|
||||
static final String DATASOURCE_MAX_POOL_SIZE = "datasource.max_pool_size";
|
||||
static final String DATASOURCE_PASSWORD = "datasource.password";
|
||||
static final String DATASOURCE_URL = "datasource.url";
|
||||
static final String DATASOURCE_USERNAME = "datasource.username";
|
||||
@@ -27,6 +29,7 @@ public class HapiProperties {
|
||||
static final String LOGGER_FORMAT = "logger.format";
|
||||
static final String LOGGER_LOG_EXCEPTIONS = "logger.log_exceptions";
|
||||
static final String LOGGER_NAME = "logger.name";
|
||||
static final String MAX_FETCH_SIZE = "max_fetch_size";
|
||||
static final String MAX_PAGE_SIZE = "max_page_size";
|
||||
static final String PERSISTENCE_UNIT_NAME = "persistence_unit_name";
|
||||
static final String SERVER_ADDRESS = "server_address";
|
||||
@@ -65,11 +68,37 @@ public class HapiProperties {
|
||||
} catch (Exception e) {
|
||||
throw new ConfigurationException("Could not load HAPI properties", e);
|
||||
}
|
||||
|
||||
Properties overrideProps = loadOverrideProperties();
|
||||
if(overrideProps != null) {
|
||||
properties.putAll(overrideProps);
|
||||
}
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a configuration file path is explicitly specified via -Dhapi.properties=<path>, the properties there will
|
||||
* be used to override the entries in the default hapi.properties file (currently under WEB-INF/classes)
|
||||
* @return properties loaded from the explicitly specified configuraiton file if there is one, or null otherwise.
|
||||
*/
|
||||
private static Properties loadOverrideProperties() {
|
||||
String confFile = System.getProperty(HAPI_PROPERTIES);
|
||||
if(confFile != null) {
|
||||
try {
|
||||
Properties props = new Properties();
|
||||
props.load(new FileInputStream(confFile));
|
||||
return props;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ConfigurationException("Could not load HAPI properties file: " + confFile, e);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getProperty(String propertyName) {
|
||||
Properties properties = HapiProperties.getProperties();
|
||||
|
||||
@@ -160,6 +189,10 @@ public class HapiProperties {
|
||||
return HapiProperties.getIntegerProperty(MAX_PAGE_SIZE, 200);
|
||||
}
|
||||
|
||||
public static Integer getMaximumFetchSize() {
|
||||
return HapiProperties.getIntegerProperty(MAX_FETCH_SIZE, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public static String getPersistenceUnitName() {
|
||||
return HapiProperties.getProperty(PERSISTENCE_UNIT_NAME, "HAPI_PU");
|
||||
}
|
||||
@@ -184,6 +217,10 @@ public class HapiProperties {
|
||||
return HapiProperties.getProperty(DATASOURCE_DRIVER, "org.apache.derby.jdbc.EmbeddedDriver");
|
||||
}
|
||||
|
||||
public static Integer getDataSourceMaxPoolSize() {
|
||||
return HapiProperties.getIntegerProperty(DATASOURCE_MAX_POOL_SIZE, 10);
|
||||
}
|
||||
|
||||
public static String getDataSourceUrl() {
|
||||
return HapiProperties.getProperty(DATASOURCE_URL, "jdbc:derby:directory:target/jpaserver_derby_files;create=true");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user