From 3f751b900fc97f787a87b58a685a0bf21702c1f0 Mon Sep 17 00:00:00 2001 From: Bert Frees Date: Tue, 10 Oct 2017 10:53:38 +0200 Subject: [PATCH] Support environment variables for all supported system properties in a uniform way. A utility function was added to read from both System.properties and System.env. If a property starts with "org.daisy.pipeline", the function first looks for an environment variable and falls back to a system property. Otherwise it looks only for a system property. For example, if the key is "org.daisy.pipeline.ws.host", an environment variable "PIPELINE2_WS_HOST" will have precedence over the system property. --- bom/pom.xml | 18 ++--- .../calabash/impl/CalabashXProcEngine.java | 4 +- .../impl/EventBusMessageListener.java | 4 +- framework-core/pom.xml | 4 +- .../daisy/pipeline/job/JobManagerFactory.java | 9 ++- .../job/impl/DefaultJobExecutionService.java | 4 +- .../daisy/pipeline/job/impl/JobURIUtils.java | 5 +- .../daisy/pipeline/properties/Properties.java | 49 +++++++++++ .../messaging/VolatileMessageStorage.java | 4 +- .../impl/derby/DerbyEntityManagerFactory.java | 4 +- .../impl/mysql/MySQLEntityManagerFactory.java | 8 +- updater-wrapper/pom.xml | 4 + .../org/daisy/pipeline/updater/Updater.java | 10 ++- webservice-utils/pom.xml | 4 +- .../pipeline/webserviceutils/Properties.java | 55 +++++++++---- .../pipeline/webserviceutils/Routes.java | 8 +- .../webserviceutils/xml/AliveXmlWriter.java | 6 +- webservice/pom.xml | 11 +++ .../webservice/impl/PipelineWebService.java | 4 +- .../impl/PipelineWebServiceConfiguration.java | 81 ++++++++++--------- 20 files changed, 203 insertions(+), 93 deletions(-) create mode 100644 framework-core/src/main/java/org/daisy/pipeline/properties/Properties.java diff --git a/bom/pom.xml b/bom/pom.xml index 9c854d2e2..12e08ad8b 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -20,22 +20,22 @@ - 2.0.5 + 2.0.6-SNAPSHOT 2.0.0 2.1.3 - 3.1.1 - 2.0.4 - 2.0.2 + 3.2.0-SNAPSHOT + 2.0.5-SNAPSHOT + 2.0.3-SNAPSHOT 1.0.0 2.0.2 1.1.1 2.0.1 - 2.0.1 - 2.0.0 + 2.0.2-SNAPSHOT + 2.0.1-SNAPSHOT 2.0.1 - 1.0.1 - 2.1.2 - 2.2.2 + 1.0.2-SNAPSHOT + 2.1.3-SNAPSHOT + 3.0.0-SNAPSHOT 2.0.1 2.0.2 1.0.2 diff --git a/calabash-adapter/src/main/java/org/daisy/common/xproc/calabash/impl/CalabashXProcEngine.java b/calabash-adapter/src/main/java/org/daisy/common/xproc/calabash/impl/CalabashXProcEngine.java index 93f209c34..5030dc122 100644 --- a/calabash-adapter/src/main/java/org/daisy/common/xproc/calabash/impl/CalabashXProcEngine.java +++ b/calabash-adapter/src/main/java/org/daisy/common/xproc/calabash/impl/CalabashXProcEngine.java @@ -13,6 +13,8 @@ import org.daisy.common.xproc.XProcResult; import org.daisy.common.xproc.calabash.XProcConfigurationFactory; import org.daisy.pipeline.event.EventBusProvider; +import org.daisy.pipeline.properties.Properties; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.EntityResolver; @@ -124,7 +126,7 @@ public void setEventBusProvider(EventBusProvider eventBusProvider){ public void setPropertyPublisherFactory(PropertyPublisherFactory propertyPublisherFactory){ PropertyPublisher propertyPublisher=propertyPublisherFactory.newPropertyPublisher(); //the property publishing step goes here - propertyPublisher.publish("org.daisy.pipeline.xproc.configuration" ,System.getProperty("org.daisy.pipeline.xproc.configuration" ),this.getClass()); + propertyPublisher.publish("org.daisy.pipeline.xproc.configuration" ,Properties.getProperty("org.daisy.pipeline.xproc.configuration" ),this.getClass()); propertyPublisher.publish("com.xmlcalabash.config.jar" ,System.getProperty("com.xmlcalabash.config.jar","true" ),this.getClass()); propertyPublisher.publish("com.xmlcalabash.config.home" ,System.getProperty("com.xmlcalabash.config.home","true" ),this.getClass()); propertyPublisher.publish("com.xmlcalabash.config.cwd" ,System.getProperty("com.xmlcalabash.config.cwd","true" ),this.getClass()); diff --git a/calabash-adapter/src/main/java/org/daisy/common/xproc/calabash/impl/EventBusMessageListener.java b/calabash-adapter/src/main/java/org/daisy/common/xproc/calabash/impl/EventBusMessageListener.java index f2ff0b67a..14e4c2e58 100644 --- a/calabash-adapter/src/main/java/org/daisy/common/xproc/calabash/impl/EventBusMessageListener.java +++ b/calabash-adapter/src/main/java/org/daisy/common/xproc/calabash/impl/EventBusMessageListener.java @@ -21,7 +21,9 @@ */ public class EventBusMessageListener implements XProcMessageListener { - private static boolean LOG_DEBUG = Boolean.parseBoolean(System.getProperty("org.daisy.pipeline.calabash.logDebug","false")); + private static boolean LOG_DEBUG = Boolean.parseBoolean( + org.daisy.pipeline.properties.Properties.getProperty("org.daisy.pipeline.calabash.logDebug","false")); + /** The listener. */ EventBusProvider eventBus; MessageBuliderFactory messageBuilderFactory; diff --git a/framework-core/pom.xml b/framework-core/pom.xml index 61feb68cb..84df9adba 100644 --- a/framework-core/pom.xml +++ b/framework-core/pom.xml @@ -8,7 +8,7 @@ ../parent framework-core - 3.1.2-SNAPSHOT + 3.2.0-SNAPSHOT bundle DAISY Pipeline 2 :: Framework Core @@ -76,4 +76,4 @@ - \ No newline at end of file + diff --git a/framework-core/src/main/java/org/daisy/pipeline/job/JobManagerFactory.java b/framework-core/src/main/java/org/daisy/pipeline/job/JobManagerFactory.java index 950faa5be..c97866759 100644 --- a/framework-core/src/main/java/org/daisy/pipeline/job/JobManagerFactory.java +++ b/framework-core/src/main/java/org/daisy/pipeline/job/JobManagerFactory.java @@ -4,6 +4,7 @@ import org.daisy.common.properties.PropertyPublisherFactory; import org.daisy.pipeline.clients.Client; import org.daisy.pipeline.job.impl.DefaultJobManager; +import org.daisy.pipeline.properties.Properties; public class JobManagerFactory { private JobStorage storage; @@ -47,10 +48,10 @@ public void setRuntimeConfigurator(RuntimeConfigurator configurator){ public void setPropertyPublisherFactory(PropertyPublisherFactory propertyPublisherFactory){ PropertyPublisher propertyPublisher=propertyPublisherFactory.newPropertyPublisher(); //the property publishing step goes here - propertyPublisher.publish("org.daisy.pipeline.iobase" ,System.getProperty("org.daisy.pipeline.iobase","" ),this.getClass()); - propertyPublisher.publish("org.daisy.pipeline.home" ,System.getProperty("org.daisy.pipeline.home","" ),this.getClass()); - propertyPublisher.publish("org.daisy.pipeline.logdir",System.getProperty("org.daisy.pipeline.logdir","" ),this.getClass()); - propertyPublisher.publish("org.daisy.pipeline.procs",System.getProperty("org.daisy.pipeline.procs","" ),this.getClass()); + propertyPublisher.publish("org.daisy.pipeline.iobase" ,Properties.getProperty("org.daisy.pipeline.iobase","" ),this.getClass()); + propertyPublisher.publish("org.daisy.pipeline.home" ,Properties.getProperty("org.daisy.pipeline.home","" ),this.getClass()); + propertyPublisher.publish("org.daisy.pipeline.logdir",Properties.getProperty("org.daisy.pipeline.logdir","" ),this.getClass()); + propertyPublisher.publish("org.daisy.pipeline.procs",Properties.getProperty("org.daisy.pipeline.procs","" ),this.getClass()); } public void unsetPropertyPublisherFactory(PropertyPublisherFactory propertyPublisherFactory){ diff --git a/framework-core/src/main/java/org/daisy/pipeline/job/impl/DefaultJobExecutionService.java b/framework-core/src/main/java/org/daisy/pipeline/job/impl/DefaultJobExecutionService.java index 552494f27..c09fb5221 100644 --- a/framework-core/src/main/java/org/daisy/pipeline/job/impl/DefaultJobExecutionService.java +++ b/framework-core/src/main/java/org/daisy/pipeline/job/impl/DefaultJobExecutionService.java @@ -12,6 +12,8 @@ import org.daisy.pipeline.job.JobExecutionService; import org.daisy.pipeline.job.JobQueue; import org.daisy.pipeline.job.impl.fuzzy.FuzzyJobFactory; +import org.daisy.pipeline.properties.Properties; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.Marker; @@ -39,7 +41,7 @@ static PriorityThreadPoolExecutor configureExecutor(){ int procs=2; try{ - String confProcs=System.getProperty(NUM_PROCS,"2"); + String confProcs=Properties.getProperty(NUM_PROCS,"2"); procs=Integer.parseInt(confProcs); }catch(NumberFormatException e){ logger.info(String.format("Error parsing %s %s",NUM_PROCS,procs)); diff --git a/framework-core/src/main/java/org/daisy/pipeline/job/impl/JobURIUtils.java b/framework-core/src/main/java/org/daisy/pipeline/job/impl/JobURIUtils.java index 257c93a1b..447ea4517 100644 --- a/framework-core/src/main/java/org/daisy/pipeline/job/impl/JobURIUtils.java +++ b/framework-core/src/main/java/org/daisy/pipeline/job/impl/JobURIUtils.java @@ -6,6 +6,7 @@ import org.daisy.pipeline.job.JobId; import org.daisy.pipeline.job.URIMapper; +import org.daisy.pipeline.properties.Properties; public class JobURIUtils { /** The Constant ORG_DAISY_PIPELINE_IOBASE. */ @@ -80,9 +81,9 @@ public static boolean cleanJobBase(JobId id){ } } private static String frameworkBase(){ - if (System.getProperty(ORG_DAISY_PIPELINE_IOBASE) == null) { + if (Properties.getProperty(ORG_DAISY_PIPELINE_IOBASE) == null) { throw new IllegalStateException(String.format("The property %s is not set",ORG_DAISY_PIPELINE_IOBASE )); } - return System.getProperty(ORG_DAISY_PIPELINE_IOBASE); + return Properties.getProperty(ORG_DAISY_PIPELINE_IOBASE); } } diff --git a/framework-core/src/main/java/org/daisy/pipeline/properties/Properties.java b/framework-core/src/main/java/org/daisy/pipeline/properties/Properties.java new file mode 100644 index 000000000..0dcb95967 --- /dev/null +++ b/framework-core/src/main/java/org/daisy/pipeline/properties/Properties.java @@ -0,0 +1,49 @@ +package org.daisy.pipeline.properties; + +import java.util.Map; + +public final class Properties { + + private Properties() { + } + + // System.getProperties() returns an object that is always up to date + private final static java.util.Properties systemProperties = System.getProperties(); + private final static Map systemEnv = System.getenv(); + + /** + * Gets the system property or environment variable indicated by the specified key. + * + * If the key starts with "org.daisy.pipeline", the function first looks for an + * environment variable and falls back to a system property. Otherwise it looks only + * for a system property. The name of the environment variable is derived from the + * name of the system property. + * + * For example, if the key is "org.daisy.pipeline.ws.host", an environment variable + * "PIPELINE2_WS_HOST" will have precedence over the system property. + * + * @param key The name of the system property. + * @return The string value of the system property or environment variable, or null if + * there is no property or variable with that key. + */ + public static String getProperty(String key) { + return getProperty(key, null); + } + + /** + * @param key The name of the system property. + * @param defaultValue A default value. + * @return The string value of the system property or environment variable, or the + * default value if there is no property or variable with that key. + */ + public static String getProperty(String key, String defaultValue) { + if (key == null) + throw new NullPointerException(); + if (key.startsWith("org.daisy.pipeline.")) { + String envKey = "PIPELINE2_" + key.substring(19).replace('.', '_').toUpperCase(); + if (systemEnv.containsKey(envKey)) + return systemEnv.get(envKey); + } + return systemProperties.getProperty(key, defaultValue); + } +} diff --git a/framework-volatile/src/main/java/org/daisy/pipeline/nonpersistent/impl/messaging/VolatileMessageStorage.java b/framework-volatile/src/main/java/org/daisy/pipeline/nonpersistent/impl/messaging/VolatileMessageStorage.java index 90cfb2b0c..e1a1435a4 100644 --- a/framework-volatile/src/main/java/org/daisy/pipeline/nonpersistent/impl/messaging/VolatileMessageStorage.java +++ b/framework-volatile/src/main/java/org/daisy/pipeline/nonpersistent/impl/messaging/VolatileMessageStorage.java @@ -7,6 +7,8 @@ import org.daisy.common.messaging.Message; import org.daisy.common.messaging.Message.Level; +import org.daisy.pipeline.properties.Properties; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,7 +31,7 @@ public final class VolatileMessageStorage { * */ private VolatileMessageStorage() { - int timeout = Integer.valueOf(System.getProperty( + int timeout = Integer.valueOf(Properties.getProperty( CACHE_TIMEOUT_PROPERTY, "60")); cache = CacheBuilder.newBuilder() .expireAfterAccess(timeout, TimeUnit.SECONDS) diff --git a/persistence-derby/src/main/java/org/daisy/pipeline/persistence/impl/derby/DerbyEntityManagerFactory.java b/persistence-derby/src/main/java/org/daisy/pipeline/persistence/impl/derby/DerbyEntityManagerFactory.java index 2a0fbb154..92e8a3618 100644 --- a/persistence-derby/src/main/java/org/daisy/pipeline/persistence/impl/derby/DerbyEntityManagerFactory.java +++ b/persistence-derby/src/main/java/org/daisy/pipeline/persistence/impl/derby/DerbyEntityManagerFactory.java @@ -6,6 +6,8 @@ import org.daisy.common.properties.PropertyPublisher; import org.daisy.common.properties.PropertyPublisherFactory; import org.daisy.pipeline.persistence.ForwardingEntityManagerFactory; +import org.daisy.pipeline.properties.Properties; + import org.osgi.service.jpa.EntityManagerFactoryBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,7 +15,7 @@ public class DerbyEntityManagerFactory extends ForwardingEntityManagerFactory{ private static final String DERBY_JDBC_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver"; - private static final String DERBY_DB_URL = "jdbc:derby:"+System.getProperty("org.daisy.pipeline.data")+"/db;create=true"; + private static final String DERBY_DB_URL = "jdbc:derby:"+Properties.getProperty("org.daisy.pipeline.data")+"/db;create=true"; protected static Logger logger = LoggerFactory .getLogger(DerbyEntityManagerFactory.class.getName()); diff --git a/persistence-mysql/src/main/java/org/daisy/pipeline/persistence/impl/mysql/MySQLEntityManagerFactory.java b/persistence-mysql/src/main/java/org/daisy/pipeline/persistence/impl/mysql/MySQLEntityManagerFactory.java index a837acc93..0cb66f087 100644 --- a/persistence-mysql/src/main/java/org/daisy/pipeline/persistence/impl/mysql/MySQLEntityManagerFactory.java +++ b/persistence-mysql/src/main/java/org/daisy/pipeline/persistence/impl/mysql/MySQLEntityManagerFactory.java @@ -4,6 +4,8 @@ import java.util.Map; import org.daisy.pipeline.persistence.ForwardingEntityManagerFactory; +import org.daisy.pipeline.properties.Properties; + import org.osgi.service.jpa.EntityManagerFactoryBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,11 +24,11 @@ public class MySQLEntityManagerFactory extends ForwardingEntityManagerFactory{ props.put(JAVAX_PERSISTENCE_JDBC_DRIVER, COM_MYSQL_JDBC_DRIVER); props.put(JAVAX_PERSISTENCE_JDBC_URL, - System.getProperty(ORG_DAISY_PERSISTENCE_URL)); + Properties.getProperty(ORG_DAISY_PERSISTENCE_URL)); props.put(JAVAX_PERSISTENCE_JDBC_USER, - System.getProperty(ORG_DAISY_PERSISTENCE_USER)); + Properties.getProperty(ORG_DAISY_PERSISTENCE_USER)); props.put(JAVAX_PERSISTENCE_JDBC_PASSWORD, - System.getProperty(ORG_DAISY_PERSISTENCE_PASSWORD)); + Properties.getProperty(ORG_DAISY_PERSISTENCE_PASSWORD)); } public void setBuilder(EntityManagerFactoryBuilder builder){ diff --git a/updater-wrapper/pom.xml b/updater-wrapper/pom.xml index a28bd9444..5e20afb7b 100644 --- a/updater-wrapper/pom.xml +++ b/updater-wrapper/pom.xml @@ -12,6 +12,10 @@ bundle DAISY Pipeline 2 :: Updater + + org.daisy.pipeline + framework-core + com.google.guava guava diff --git a/updater-wrapper/src/main/java/org/daisy/pipeline/updater/Updater.java b/updater-wrapper/src/main/java/org/daisy/pipeline/updater/Updater.java index de1438361..aa9e0999a 100644 --- a/updater-wrapper/src/main/java/org/daisy/pipeline/updater/Updater.java +++ b/updater-wrapper/src/main/java/org/daisy/pipeline/updater/Updater.java @@ -3,6 +3,8 @@ import java.io.IOException; import java.io.InputStream; +import org.daisy.pipeline.properties.Properties; + public class Updater { private static String UPDATER_BIN="org.pipeline.updater.bin"; @@ -14,10 +16,10 @@ public class Updater { //launches the pipeline and waits it to be up public void update(UpdaterObserver obs) throws IOException { - String bin=System.getProperty(UPDATER_BIN,""); - String deployPath=System.getProperty(DEPLOY_PATH,""); - String updateSite=System.getProperty(UPDATE_SITE,""); - String releaseDescriptor=System.getProperty(RELEASE_DESCRIPTOR,""); + String bin=Properties.getProperty(UPDATER_BIN,""); + String deployPath=Properties.getProperty(DEPLOY_PATH,""); + String updateSite=Properties.getProperty(UPDATE_SITE,""); + String releaseDescriptor=Properties.getProperty(RELEASE_DESCRIPTOR,""); if (bin.isEmpty()){ throw new IllegalArgumentException(String.format(ERROR,UPDATER_BIN)); } diff --git a/webservice-utils/pom.xml b/webservice-utils/pom.xml index e70af14eb..c3989022e 100644 --- a/webservice-utils/pom.xml +++ b/webservice-utils/pom.xml @@ -11,7 +11,7 @@ webservice-utils - 2.2.3-SNAPSHOT + 3.0.0-SNAPSHOT bundle DAISY Pipeline 2 :: Web Service Utils @@ -54,4 +54,4 @@ - \ No newline at end of file + diff --git a/webservice-utils/src/main/java/org/daisy/pipeline/webserviceutils/Properties.java b/webservice-utils/src/main/java/org/daisy/pipeline/webserviceutils/Properties.java index a1521fd5a..04c707972 100644 --- a/webservice-utils/src/main/java/org/daisy/pipeline/webserviceutils/Properties.java +++ b/webservice-utils/src/main/java/org/daisy/pipeline/webserviceutils/Properties.java @@ -1,22 +1,43 @@ package org.daisy.pipeline.webserviceutils; -public interface Properties { - public static final String MAX_REQUEST_TIME = "org.daisy.pipeline.ws.maxrequesttime"; - public static final String TMPDIR = "org.daisy.pipeline.ws.tmpdir"; - public static final String AUTHENTICATION = "org.daisy.pipeline.ws.authentication"; - public static final String LOCALFS= "org.daisy.pipeline.ws.localfs"; - public static final String FRAMEWORK_VERSION="org.daisy.pipeline.version"; - public static final String JAVA_IO_TMPDIR = "java.io.tmpdir"; - public static final String PORT = "org.daisy.pipeline.ws.port"; - public static final String PATH = "org.daisy.pipeline.ws.path"; - public static final String HOST = "org.daisy.pipeline.ws.host"; - public static final String SSL= "org.daisy.pipeline.ws.ssl"; - public static final String SSL_KEYSTORE= "org.daisy.pipeline.ws.ssl.keystore"; - public static final String SSL_KEYSTOREPASSWORD= "org.daisy.pipeline.ws.ssl.keystorepassword"; - public static final String CLEAN_UP_ON_START_UP = "org.daisy.pipeline.ws.cleanuponstartup"; +public enum Properties { - public static final String SSL_KEYPASSWORD= "org.daisy.pipeline.ws.ssl.keypassword"; - public static final String CLIENT_KEY= "org.daisy.pipeline.ws.authentication.key"; - public static final String CLIENT_SECRET= "org.daisy.pipeline.ws.authentication.secret"; + MAX_REQUEST_TIME("org.daisy.pipeline.ws.maxrequesttime"), + TMPDIR("org.daisy.pipeline.ws.tmpdir"), + AUTHENTICATION("org.daisy.pipeline.ws.authentication"), + LOCALFS("org.daisy.pipeline.ws.localfs"), + FRAMEWORK_VERSION("org.daisy.pipeline.version"), + PORT("org.daisy.pipeline.ws.port"), + PATH("org.daisy.pipeline.ws.path"), + HOST("org.daisy.pipeline.ws.host"), + SSL("org.daisy.pipeline.ws.ssl"), + SSL_KEYSTORE("org.daisy.pipeline.ws.ssl.keystore"), + SSL_KEYSTOREPASSWORD("org.daisy.pipeline.ws.ssl.keystorepassword"), + CLEAN_UP_ON_START_UP("org.daisy.pipeline.ws.cleanuponstartup"), + SSL_KEYPASSWORD("org.daisy.pipeline.ws.ssl.keypassword"), + CLIENT_KEY("org.daisy.pipeline.ws.authentication.key"), + CLIENT_SECRET("org.daisy.pipeline.ws.authentication.secret"); + private final String key; + + private Properties(String key) { + this.key = key; + } + + public String get() { + return org.daisy.pipeline.properties.Properties.getProperty(key); + } + + public String get(String defaultValue) { + return org.daisy.pipeline.properties.Properties.getProperty(key, defaultValue); + } + + public String getName() { + return key; + } + + @Override + public String toString() { + return key; + } } diff --git a/webservice-utils/src/main/java/org/daisy/pipeline/webserviceutils/Routes.java b/webservice-utils/src/main/java/org/daisy/pipeline/webserviceutils/Routes.java index c35dd3bff..e18b39282 100644 --- a/webservice-utils/src/main/java/org/daisy/pipeline/webserviceutils/Routes.java +++ b/webservice-utils/src/main/java/org/daisy/pipeline/webserviceutils/Routes.java @@ -58,7 +58,7 @@ public String getBaseUri() { } private void readOptions() { - String path = System.getProperty(Properties.PATH); + String path = Properties.PATH.get(); if (path != null) { if (!path.startsWith("/")) { path = "/" + path; @@ -66,15 +66,15 @@ private void readOptions() { this.path = path; } - String hostname = System.getProperty(Properties.HOST); + String hostname = Properties.HOST.get(); if (hostname != null) { host = hostname; } - if (System.getProperty(Properties.SSL)!=null&&System.getProperty(Properties.SSL).equalsIgnoreCase("true")){ + if (Properties.SSL.get()!=null&&Properties.SSL.get().equalsIgnoreCase("true")){ proto="https://"; } - String port = System.getProperty(Properties.PORT); + String port = Properties.PORT.get(); if (port != null) { try { int portnum = Integer.parseInt(port); diff --git a/webservice-utils/src/main/java/org/daisy/pipeline/webserviceutils/xml/AliveXmlWriter.java b/webservice-utils/src/main/java/org/daisy/pipeline/webserviceutils/xml/AliveXmlWriter.java index df9cd16df..599f208b9 100644 --- a/webservice-utils/src/main/java/org/daisy/pipeline/webserviceutils/xml/AliveXmlWriter.java +++ b/webservice-utils/src/main/java/org/daisy/pipeline/webserviceutils/xml/AliveXmlWriter.java @@ -11,9 +11,9 @@ public class AliveXmlWriter { public Document getXmlDocument() { Document doc = XmlUtils.createDom("alive"); Element aliveElm = doc.getDocumentElement(); - aliveElm.setAttribute("localfs", Boolean.valueOf(System.getProperty(Properties.LOCALFS)) ? "true" : "false"); - aliveElm.setAttribute("authentication", System.getProperty(Properties.AUTHENTICATION)); - aliveElm.setAttribute("version", System.getProperty(Properties.FRAMEWORK_VERSION)); + aliveElm.setAttribute("localfs", Boolean.valueOf(Properties.LOCALFS.get()) ? "true" : "false"); + aliveElm.setAttribute("authentication", Properties.AUTHENTICATION.get()); + aliveElm.setAttribute("version", Properties.FRAMEWORK_VERSION.get()); if (!XmlValidator.validate(doc, XmlValidator.ALIVE_SCHEMA_URL)) { logger.error("INVALID XML:\n" + XmlUtils.DOMToString(doc)); logger.error(XmlUtils.DOMToString(doc)); diff --git a/webservice/pom.xml b/webservice/pom.xml index 960e32d98..4461771bc 100644 --- a/webservice/pom.xml +++ b/webservice/pom.xml @@ -122,6 +122,17 @@ logging-activator test + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.1 + test + diff --git a/webservice/src/main/java/org/daisy/pipeline/webservice/impl/PipelineWebService.java b/webservice/src/main/java/org/daisy/pipeline/webservice/impl/PipelineWebService.java index 63024f163..0cb12f63b 100644 --- a/webservice/src/main/java/org/daisy/pipeline/webservice/impl/PipelineWebService.java +++ b/webservice/src/main/java/org/daisy/pipeline/webservice/impl/PipelineWebService.java @@ -224,11 +224,11 @@ private boolean checkAuthenticationSanity() { private void generateStopKey() throws IOException { shutDownKey = new Random().nextLong(); - File fout = new File(System.getProperty(Properties.JAVA_IO_TMPDIR)+File.separator+KEY_FILE_NAME); + File fout = new File(System.getProperty("java.io.tmpdir")+File.separator+KEY_FILE_NAME); FileOutputStream fos= new FileOutputStream(fout); fos.write((shutDownKey+"").getBytes()); fos.close(); - logger.info("Shutdown key stored to: "+System.getProperty(Properties.JAVA_IO_TMPDIR)+File.separator+KEY_FILE_NAME); + logger.info("Shutdown key stored to: "+System.getProperty("java.io.tmpdir")+File.separator+KEY_FILE_NAME); } public boolean shutDown(long key) throws BundleException{ diff --git a/webservice/src/main/java/org/daisy/pipeline/webservice/impl/PipelineWebServiceConfiguration.java b/webservice/src/main/java/org/daisy/pipeline/webservice/impl/PipelineWebServiceConfiguration.java index 9fb3b1d63..82c781990 100644 --- a/webservice/src/main/java/org/daisy/pipeline/webservice/impl/PipelineWebServiceConfiguration.java +++ b/webservice/src/main/java/org/daisy/pipeline/webservice/impl/PipelineWebServiceConfiguration.java @@ -34,7 +34,7 @@ public PipelineWebServiceConfiguration() { private void readOptions() { //Authentication - String authentication = System.getProperty(Properties.AUTHENTICATION); + String authentication = Properties.AUTHENTICATION.get(); if (authentication != null) { if (authentication.equalsIgnoreCase("true")) { usesAuthentication = true; @@ -50,7 +50,7 @@ else if (authentication.equalsIgnoreCase("false")) { } } //Temporal directory - String tmp = System.getProperty(Properties.TMPDIR); + String tmp = Properties.TMPDIR.get(); if (tmp != null) { File f = new File(tmp); if (f.exists()) { @@ -66,7 +66,7 @@ else if (authentication.equalsIgnoreCase("false")) { //Max req time - String maxrequesttime = System.getProperty(Properties.MAX_REQUEST_TIME); + String maxrequesttime = Properties.MAX_REQUEST_TIME.get(); if (maxrequesttime != null) { try { long ms = Long.parseLong(maxrequesttime); @@ -78,62 +78,71 @@ else if (authentication.equalsIgnoreCase("false")) { } } //ssl related stuff - ssl=System.getProperty(Properties.SSL)!=null&&System.getProperty(Properties.SSL).equalsIgnoreCase("true"); - sslKeystore=System.getProperty(Properties.SSL_KEYSTORE,""); - sslKeystorePassword=System.getProperty(Properties.SSL_KEYSTOREPASSWORD,""); - sslKeyPassword=System.getProperty(Properties.SSL_KEYPASSWORD,""); + ssl=Properties.SSL.get()!=null&&Properties.SSL.get().equalsIgnoreCase("true"); + sslKeystore=Properties.SSL_KEYSTORE.get(""); + sslKeystorePassword=Properties.SSL_KEYSTOREPASSWORD.get(""); + sslKeyPassword=Properties.SSL_KEYPASSWORD.get(""); - clientKey=System.getProperty(Properties.CLIENT_KEY); - clientSecret=System.getProperty(Properties.CLIENT_SECRET); + clientKey=Properties.CLIENT_KEY.get(); + clientSecret=Properties.CLIENT_SECRET.get(); - cleanUpOnStartUp = Boolean.valueOf(System.getProperty(Properties. CLEAN_UP_ON_START_UP,"false")); + cleanUpOnStartUp = Boolean.valueOf(Properties. CLEAN_UP_ON_START_UP.get("false")); } public void publishConfiguration(PropertyPublisher propPublisher){ //mode - propPublisher.publish(Properties.LOCALFS,System.getProperty(Properties.LOCALFS,"false"),this.getClass()); + publish(propPublisher, Properties.LOCALFS,Properties.LOCALFS.get("false")); //ssl related properties - propPublisher.publish(Properties.SSL,System.getProperty(Properties.SSL,"false"),this.getClass()); - propPublisher.publish(Properties.SSL_KEYSTORE,!System.getProperty(Properties.SSL_KEYSTORE,"").isEmpty()+"",this.getClass()); - propPublisher.publish(Properties.SSL_KEYSTOREPASSWORD,!System.getProperty(Properties.SSL_KEYSTOREPASSWORD,"").isEmpty()+"",this.getClass()); - propPublisher.publish(Properties.SSL_KEYPASSWORD,!System.getProperty(Properties.SSL_KEYPASSWORD,"").isEmpty()+"",this.getClass()); + publish(propPublisher, Properties.SSL,Properties.SSL.get("false")); + publish(propPublisher, Properties.SSL_KEYSTORE,!Properties.SSL_KEYSTORE.get("").isEmpty()+""); + publish(propPublisher, Properties.SSL_KEYSTOREPASSWORD,!Properties.SSL_KEYSTOREPASSWORD.get("").isEmpty()+""); + publish(propPublisher, Properties.SSL_KEYPASSWORD,!Properties.SSL_KEYPASSWORD.get("").isEmpty()+""); //client keys and secret - propPublisher.publish(Properties.CLIENT_KEY,System.getProperty(Properties.CLIENT_KEY,""),this.getClass()); - propPublisher.publish(Properties.CLIENT_SECRET,!System.getProperty(Properties.CLIENT_SECRET,"").isEmpty()+"",this.getClass()); + publish(propPublisher, Properties.CLIENT_KEY,Properties.CLIENT_KEY.get("")); + publish(propPublisher, Properties.CLIENT_SECRET,!Properties.CLIENT_SECRET.get("").isEmpty()+""); //request - propPublisher.publish(Properties.MAX_REQUEST_TIME,this.getMaxRequestTime()+"",this.getClass()); + publish(propPublisher, Properties.MAX_REQUEST_TIME,this.getMaxRequestTime()+""); //tmp dir - propPublisher.publish(Properties.TMPDIR,this.getTmpDir(),this.getClass()); - propPublisher.publish(Properties.AUTHENTICATION,this.isAuthenticationEnabled()+"",this.getClass()); + publish(propPublisher, Properties.TMPDIR,this.getTmpDir()); + publish(propPublisher, Properties.AUTHENTICATION,this.isAuthenticationEnabled()+""); Routes routes=new Routes(); - propPublisher.publish(Properties.HOST,routes.getHost()+"",this.getClass()); - propPublisher.publish(Properties.PATH,routes.getPath()+"",this.getClass()); - propPublisher.publish(Properties.PORT,routes.getPort()+"",this.getClass()); + publish(propPublisher, Properties.HOST,routes.getHost()+""); + publish(propPublisher, Properties.PATH,routes.getPath()+""); + publish(propPublisher, Properties.PORT,routes.getPort()+""); - propPublisher.publish(Properties.CLEAN_UP_ON_START_UP,this.getCleanUpOnStartUp()+"",this.getClass()); + publish(propPublisher, Properties.CLEAN_UP_ON_START_UP,this.getCleanUpOnStartUp()+""); } public void unpublishConfiguration(PropertyPublisher propPublisher){ //mode - propPublisher.unpublish(Properties.LOCALFS, this.getClass()); + unpublish(propPublisher, Properties.LOCALFS); //ssl related properties - propPublisher.unpublish(Properties.SSL , this.getClass()); - propPublisher.unpublish(Properties.SSL_KEYSTORE , this.getClass()); - propPublisher.unpublish(Properties.SSL_KEYSTOREPASSWORD , this.getClass()); - propPublisher.unpublish(Properties.SSL_KEYPASSWORD , this.getClass()); + unpublish(propPublisher, Properties.SSL); + unpublish(propPublisher, Properties.SSL_KEYSTORE); + unpublish(propPublisher, Properties.SSL_KEYSTOREPASSWORD); + unpublish(propPublisher, Properties.SSL_KEYPASSWORD); //client keys and secret - propPublisher.unpublish(Properties.CLIENT_KEY , this.getClass()); - propPublisher.unpublish(Properties.CLIENT_SECRET , this.getClass()); + unpublish(propPublisher, Properties.CLIENT_KEY); + unpublish(propPublisher, Properties.CLIENT_SECRET); //request - propPublisher.unpublish(Properties.MAX_REQUEST_TIME , this.getClass()); + unpublish(propPublisher, Properties.MAX_REQUEST_TIME); //tmp dir - propPublisher.unpublish(Properties.TMPDIR , this.getClass()); - propPublisher.unpublish(Properties.AUTHENTICATION , this.getClass()); - propPublisher.unpublish(Properties.CLEAN_UP_ON_START_UP , this.getClass()); + unpublish(propPublisher, Properties.TMPDIR); + unpublish(propPublisher, Properties.AUTHENTICATION); + unpublish(propPublisher, Properties.CLEAN_UP_ON_START_UP); } + + private static void publish(PropertyPublisher publisher, Properties propertyName, String value) { + publisher.publish(propertyName.getName(), value, PipelineWebServiceConfiguration.class); + } + + private static void unpublish(PropertyPublisher publisher, Properties propertyName) { + publisher.unpublish(propertyName.getName(), PipelineWebServiceConfiguration.class); + } + public String getTmpDir() { return tmpDir; } @@ -198,7 +207,7 @@ public boolean isAuthenticationEnabled() { public boolean isLocalFS() { - return Boolean.valueOf(System.getProperty(Properties.LOCALFS,"false")); + return Boolean.valueOf(Properties.LOCALFS.get("false")); } // the length of time in ms that a request is valid for, counting from its timestamp value