Allow optional, external configurations to override the entries in hapi.properties.
Such configurations can be specified in a properteis file outside of the war (or webapps/hapi-fhir-jpaserver) and the server may be instructed to load the configuration using -Dhapi.properties=<path-of-external-configuration-file> This is helpful in at least two use cases: 1. Deploying multiple instances with different configurations (e.g., differnt databases) 2. Future upgrade - just update the war without the need to change hapi.properties after update.
This commit is contained in:
@@ -44,6 +44,7 @@ public class FhirServerConfig extends BaseJavaConfigDstu3 {
|
|||||||
public DaoConfig daoConfig() {
|
public DaoConfig daoConfig() {
|
||||||
DaoConfig retVal = new DaoConfig();
|
DaoConfig retVal = new DaoConfig();
|
||||||
retVal.setAllowMultipleDelete(HapiProperties.getAllowMultipleDelete());
|
retVal.setAllowMultipleDelete(HapiProperties.getAllowMultipleDelete());
|
||||||
|
retVal.setFetchSizeDefaultMaximum(HapiProperties.getMaximumFetchSize());
|
||||||
retVal.setAllowExternalReferences(HapiProperties.getAllowExternalReferences());
|
retVal.setAllowExternalReferences(HapiProperties.getAllowExternalReferences());
|
||||||
retVal.setExpungeEnabled(HapiProperties.getExpungeEnabled());
|
retVal.setExpungeEnabled(HapiProperties.getExpungeEnabled());
|
||||||
|
|
||||||
@@ -90,6 +91,7 @@ public class FhirServerConfig extends BaseJavaConfigDstu3 {
|
|||||||
retVal.setUrl(HapiProperties.getDataSourceUrl());
|
retVal.setUrl(HapiProperties.getDataSourceUrl());
|
||||||
retVal.setUsername(HapiProperties.getDataSourceUsername());
|
retVal.setUsername(HapiProperties.getDataSourceUsername());
|
||||||
retVal.setPassword(HapiProperties.getDataSourcePassword());
|
retVal.setPassword(HapiProperties.getDataSourcePassword());
|
||||||
|
retVal.setMaxTotal(HapiProperties.getDataSourceMaxPoolSize());
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,14 @@ import ca.uhn.fhir.rest.server.ETagSupportEnum;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class HapiProperties {
|
public class HapiProperties {
|
||||||
public static final String SERVER_ADDRESS = "server_address";
|
public static final String SERVER_ADDRESS = "server_address";
|
||||||
public static final String DEFAULT_PRETTY_PRINT = "default_pretty_print";
|
public static final String DEFAULT_PRETTY_PRINT = "default_pretty_print";
|
||||||
public static final String MAX_PAGE_SIZE = "max_page_size";
|
public static final String MAX_PAGE_SIZE = "max_page_size";
|
||||||
|
public static final String MAX_FETCH_SIZE = "max_fetch_size";
|
||||||
public static final String DEFAULT_PAGE_SIZE = "default_page_size";
|
public static final String DEFAULT_PAGE_SIZE = "default_page_size";
|
||||||
public static final String LOGGER_NAME = "logger.name";
|
public static final String LOGGER_NAME = "logger.name";
|
||||||
public static final String LOGGER_FORMAT = "logger.format";
|
public static final String LOGGER_FORMAT = "logger.format";
|
||||||
@@ -23,6 +25,7 @@ public class HapiProperties {
|
|||||||
public static final String DATASOURCE_USERNAME = "datasource.username";
|
public static final String DATASOURCE_USERNAME = "datasource.username";
|
||||||
public static final String DATASOURCE_URL = "datasource.url";
|
public static final String DATASOURCE_URL = "datasource.url";
|
||||||
public static final String DATASOURCE_DRIVER = "datasource.driver";
|
public static final String DATASOURCE_DRIVER = "datasource.driver";
|
||||||
|
public static final String DATASOURCE_MAX_POOL_SIZE = "datasource.max_pool_size";
|
||||||
public static final String LOGGER_LOG_EXCEPTIONS = "logger.log_exceptions";
|
public static final String LOGGER_LOG_EXCEPTIONS = "logger.log_exceptions";
|
||||||
public static final String LOGGER_ERROR_FORMAT = "logger.error_format";
|
public static final String LOGGER_ERROR_FORMAT = "logger.error_format";
|
||||||
public static final String PERSISTENCE_UNIT_NAME = "persistence_unit_name";
|
public static final String PERSISTENCE_UNIT_NAME = "persistence_unit_name";
|
||||||
@@ -49,11 +52,37 @@ public class HapiProperties {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ConfigurationException("Could not load HAPI properties", e);
|
throw new ConfigurationException("Could not load HAPI properties", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Properties overrideProps = loadOverrideProperties();
|
||||||
|
if(overrideProps != null) {
|
||||||
|
properties.putAll(overrideProps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return properties;
|
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) {
|
private static String getProperty(String propertyName) {
|
||||||
Properties properties = HapiProperties.getProperties();
|
Properties properties = HapiProperties.getProperties();
|
||||||
|
|
||||||
@@ -144,6 +173,10 @@ public class HapiProperties {
|
|||||||
return HapiProperties.getIntegerProperty(MAX_PAGE_SIZE, 200);
|
return HapiProperties.getIntegerProperty(MAX_PAGE_SIZE, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Integer getMaximumFetchSize() {
|
||||||
|
return HapiProperties.getIntegerProperty(MAX_FETCH_SIZE, Integer.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
public static String getPersistenceUnitName() {
|
public static String getPersistenceUnitName() {
|
||||||
return HapiProperties.getProperty(PERSISTENCE_UNIT_NAME, "HAPI_PU");
|
return HapiProperties.getProperty(PERSISTENCE_UNIT_NAME, "HAPI_PU");
|
||||||
}
|
}
|
||||||
@@ -168,6 +201,10 @@ public class HapiProperties {
|
|||||||
return HapiProperties.getProperty(DATASOURCE_DRIVER, "org.apache.derby.jdbc.EmbeddedDriver");
|
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() {
|
public static String getDataSourceUrl() {
|
||||||
return HapiProperties.getProperty(DATASOURCE_URL, "jdbc:derby:directory:target/jpaserver_derby_files;create=true");
|
return HapiProperties.getProperty(DATASOURCE_URL, "jdbc:derby:directory:target/jpaserver_derby_files;create=true");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user