summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BKUOnline/src/main/webapp/WEB-INF/applicationContext.xml1
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/conf/MoccaConfigurationException.java45
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/spring/ConfigurationFactoryBean.java43
3 files changed, 81 insertions, 8 deletions
diff --git a/BKUOnline/src/main/webapp/WEB-INF/applicationContext.xml b/BKUOnline/src/main/webapp/WEB-INF/applicationContext.xml
index 6ed5ec3e..ca5ffccc 100644
--- a/BKUOnline/src/main/webapp/WEB-INF/applicationContext.xml
+++ b/BKUOnline/src/main/webapp/WEB-INF/applicationContext.xml
@@ -23,6 +23,7 @@
<bean id="configuration" class="at.gv.egiz.bku.spring.ConfigurationFactoryBean">
<property name="configurationResource" ref="configurationResource" />
+ <property name="failOnMissingResource" value="true" />
</bean>
<bean id="sslPKIProfile" class="at.gv.egiz.bku.spring.PKIProfileFactoryBean">
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/conf/MoccaConfigurationException.java b/bkucommon/src/main/java/at/gv/egiz/bku/conf/MoccaConfigurationException.java
new file mode 100644
index 00000000..3846e88a
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/conf/MoccaConfigurationException.java
@@ -0,0 +1,45 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+/**
+ *
+ */
+package at.gv.egiz.bku.conf;
+
+/**
+ * @author mcentner
+ */
+public class MoccaConfigurationException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public MoccaConfigurationException() {
+ }
+
+ public MoccaConfigurationException(String message) {
+ super(message);
+ }
+
+ public MoccaConfigurationException(Throwable cause) {
+ super(cause);
+ }
+
+ public MoccaConfigurationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/spring/ConfigurationFactoryBean.java b/bkucommon/src/main/java/at/gv/egiz/bku/spring/ConfigurationFactoryBean.java
index a6a7c346..dd0aa1a6 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/spring/ConfigurationFactoryBean.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/spring/ConfigurationFactoryBean.java
@@ -36,6 +36,7 @@ import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
+import at.gv.egiz.bku.conf.MoccaConfigurationException;
import at.gv.egiz.bku.slcommands.impl.CreateXMLSignatureCommandImpl;
/**
@@ -59,6 +60,12 @@ public class ConfigurationFactoryBean implements FactoryBean, ResourceLoaderAwar
* The URL of the configuration file.
*/
protected Resource configurationResource;
+
+ /**
+ * Should building the configuration fail if the given configuration resource
+ * is not available?
+ */
+ protected boolean failOnMissingResource = false;
/**
* The ResourceLoader.
@@ -84,6 +91,14 @@ public class ConfigurationFactoryBean implements FactoryBean, ResourceLoaderAwar
this.configurationResource = configurationResource;
}
+ /**
+ * @param failOnMissingConfigurationResource the failOnMissingConfigurationResource to set
+ */
+ public void setfailOnMissingResource(
+ Boolean failOnMissingResource) {
+ this.failOnMissingResource = failOnMissingResource;
+ }
+
protected Configuration getDefaultConfiguration()
throws ConfigurationException, IOException {
Resource resource = resourceLoader.getResource(DEFAULT_CONFIG);
@@ -141,18 +156,30 @@ public class ConfigurationFactoryBean implements FactoryBean, ResourceLoaderAwar
log.info("Configuration resource is {}.", configurationResource);
- CompositeConfiguration configuration;
- if (configurationResource == null) {
+ CompositeConfiguration configuration = null;
+ if (configurationResource != null) {
+ if (configurationResource.exists()) {
+ // initialize with writable configuration
+ URL url = configurationResource.getURL();
+ XMLConfiguration writableConfiguration = new XMLConfiguration(url);
+ configuration = new CompositeConfiguration(writableConfiguration);
+ log.info("Initialized with configuration from '{}'.", url);
+ } else if (failOnMissingResource) {
+ StringBuilder message = new StringBuilder();
+ message.append("ConfigurationResource '");
+ message.append(configurationResource.getDescription());
+ message.append("' does not exist!");
+ log.error(message.toString());
+ throw new MoccaConfigurationException(message.toString());
+ }
+ }
+
+ if (configuration == null) {
// initialize default configuration
log.warn("Initializing with default configuration.");
configuration = new CompositeConfiguration();
- } else {
- // initialize with writable configuration
- URL url = configurationResource.getURL();
- XMLConfiguration writableConfiguration = new XMLConfiguration(url);
- configuration = new CompositeConfiguration(writableConfiguration);
- log.info("Initialized with configuration from '{}'.", url);
}
+
configuration.addConfiguration(getDefaultConfiguration());
configuration.addConfiguration(getVersionConfiguration());
return configuration;