Newer
Older
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
*
* The Original Code is Java RASP toolkit.
*
* The Initial Developer of the Original Code is Lenio. Portions
* created by Lenio are Copyright (C) 2007 Danish National IT and
* Telecom Agency (http://www.itst.dk). All Rights Reserved.
*/
package dk.gov.oiosi.configuration;
import dk.gov.oiosi.common.startup.IStartupTask;
import dk.gov.oiosi.common.startup.StartupTaskConfiguration;
import dk.gov.oiosi.communication.RMPolicy;
import dk.gov.oiosi.communication.SendPolicy;
Jacob Lund Mogensen
committed
import dk.gov.oiosi.communication.configuration.*;
import dk.gov.oiosi.security.RootCertificateConfig;
import dk.gov.oiosi.security.ldap.LdapLookupFactoryConfig;
import dk.gov.oiosi.security.ldap.LdapSettings;
import dk.gov.oiosi.security.oces.InvalidOcesCertificateSubjectKeyException;
import dk.gov.oiosi.security.oces.OcesCertificateSubjectKey;
import dk.gov.oiosi.security.oces.OcesX509CertificateConfig;
import dk.gov.oiosi.security.revocation.RevocationLookupFactoryConfig;
import dk.gov.oiosi.security.revocation.ocsp.OcspConfig;
Jacob Lund Mogensen
committed
import dk.gov.oiosi.uddi.*;
import dk.gov.oiosi.xml.schematron.SchematronValidationConfig;
import dk.gov.oiosi.xml.xpath.PrefixedNamespace;
import dk.gov.oiosi.xml.xpath.discriminator.XPathDiscriminatorConfig;
import dk.gov.oiosi.xml.xpath.discriminator.XPathDiscriminatorConfigCollection;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.SubnodeConfiguration;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.File;
import java.io.IOException;
import java.security.Security;
import java.util.*;
/**
* ReadOnly version of RaspConfigurationHandler.
* Reads RaspConfiguration.xml - and initializes configuration classes.
public class ConfigurationHandler {
private static final Log log = LogFactory.getLog(ConfigurationHandler.class);
private static final String RASPCONFIGURATION_XML_DEFAULT = "RaspConfiguration.xml";
private static String versionNumber;
private static String raspConfigurationFileName = RASPCONFIGURATION_XML_DEFAULT;
private static ConfigurationHandler static_configurationHandler = null;
private XMLConfiguration raspConfigurationFile = null;
private LdapSettings ldapSettings = null;
private OcspConfig ocspConfig = null;
private CacheConfig cacheConfig = null;
private UddiConfig uddiConfig = null;
private LdapLookupFactoryConfig ldapFactory = null;
private RevocationLookupFactoryConfig revocationFactory = null;
private UddiLookupClientFactoryConfig uddiClientFactory = null;
private RegistryLookupClientFactoryConfig registryClientFactory = null;
private DocumentTypeCollectionConfig raspDocumentTypeCollectionConfig;
initEnvironment();
/**
* Returns the static instance of the configuration handler.
*
* @return ConfigurationHandler The static instance of the configuration handler
*/
public synchronized static ConfigurationHandler getInstance() {
return getInstance(false);
}
/**
* Returns the static instance of the configuration handler.
*
* @return ConfigurationHandler The static instance of the configuration handler
*/
public synchronized static ConfigurationHandler getInstance(final boolean forceReload) {
if (static_configurationHandler == null || forceReload) {
static_configurationHandler = new ConfigurationHandler();
static_configurationHandler.loadXMLConfiguration();
}
return static_configurationHandler;
}
/**
* Sets the file name of the configuration file.
*
* @param file The file name.
*/
public static void setConfigurationFile(String file) {
raspConfigurationFileName = file;
}
/**
* Actual building start task list configurations
*/
@SuppressWarnings("unchecked")
static List<IStartupTask> parseStartTaskList(XMLConfiguration xmlConfig) {
List<IStartupTask> taskList = new ArrayList<>();
String startupConfigKey = "//ConfigurationSection[@*=\"StartupConfig\"]/StartupTasks/StartupTask";
List<HierarchicalConfiguration> startupTaskConfigList = xmlConfig.configurationsAt(startupConfigKey);
if (startupTaskConfigList != null) {
for (HierarchicalConfiguration taskConfig : startupTaskConfigList) {
String className = taskConfig.getString("ImplementationNamespaceClass");
if (className != null) {
className = className.trim();
} else {
log.warn("ConfigurationHandler: in RaspConfiguration a section StartupTask is found without subtag ImplementationNamespaceClass, section is ignored");
continue;
}
List<StartupTaskConfiguration> configList = new ArrayList<>();
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
List<HierarchicalConfiguration> configs = taskConfig.configurationsAt("ConfigurationList/Configuration");
if (configs != null) {
for (HierarchicalConfiguration config : configs) {
String name = config.getString("Name");
String value = config.getString("Value");
if (name != null) {
name = name.trim();
}
if (value != null) {
value = value.trim();
}
if (name != null && value != null) {
configList.add(new StartupTaskConfiguration(name, value));
} else {
log.warn("ConfigurationHandler: in RaspConfiguration.xml a section StartupTask for class " + className + " is found with tag ConfigurationList/Configuration but empty Name or Value subtags, configuration is ignored.");
}
}
}
if (className.length() > 0) {
Class<?> taskImpl;
try {
taskImpl = Class.forName(className);
} catch (Exception e) {
log.warn("ConfigurationHandler: can not find class " + className + ", defined as Startup task implementation in RaspConfiguration.xml", e);
continue;
}
Object taskInstance;
try {
taskInstance = taskImpl.newInstance();
} catch (Exception e) {
log.warn("ConfigurationHandler: cannot create new instance with empty constructor for " + className + ", defined as Startup task implementation in RaspConfiguration.xml", e);
continue;
}
if (taskInstance instanceof IStartupTask) {
IStartupTask startupTask = (IStartupTask) taskInstance;
try {
startupTask.init(configList);
} catch (Exception e) {
log.warn("ConfigurationHandler: failed to initialize instance of class " + className + " with config values " + configList + ", startup task is skipped", e);
continue;
}
taskList.add(startupTask);
} else {
log.warn("ConfigurationHandler: class " + className + ", defined as Startup task implementation in RaspConfiguration.xml, does not implement interface " + IStartupTask.class.getName() + ", skipped.");
}
}
}
}
return taskList;
}
/**
* Clear loaded configuration.
* <p/>
* Marked as protected to be clearable from unit tests only.
*/
protected static void clear() {
ConfigurationHandler.static_configurationHandler = null;
}
static String getVersionNumber() {
return versionNumber;
}
* Environment check and initializes related libraries
try {
if (Cipher.getMaxAllowedKeyLength("AES") < 1024) {
log.fatal("Java JCE is not installed - see https://en.wikipedia.org/wiki/Java_Cryptography_Extension");
throw new RaspLibraryException("Java JCE is not installed - see https://en.wikipedia.org/wiki/Java_Cryptography_Extension");
}
} catch (NoSuchAlgorithmException e) {
log.fatal("Java JCE might not be installed - see https://en.wikipedia.org/wiki/Java_Cryptography_Extension", e);
throw new RaspLibraryException("Java JCE is not installed - see https://en.wikipedia.org/wiki/Java_Cryptography_Extension", e);
}
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
// http://stackoverflow.com/questions/16651005/workaround-for-xmlschema-not-supporting-maxoccurs-larger-than-5000
System.setProperty("jdk.xml.maxOccurLimit", "10000");
// Support XSLT 2 for PEPPOL schematron files - se http://stackoverflow.com/questions/16455276/saxon-9-xslt-transformer-vs-xalan-2-7
// Force default Transformation to be XSLT 1.0: org.apache.xalan.processor.TransformerFactoryImpl
// Explicit choice of Saxon as Transformer is done in XsltUtility.getTransformerFactory().
System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl");
* Loads the configuration from the file specified with setConfigurationFile(String file).
synchronized public void loadXMLConfiguration() {
// Empty local cache:
uddiConfig = null;
raspConfigurationFile = ConfigurationLoaderUtil.loadXMLConfiguration(raspConfigurationFileName, log);
log.debug("Loading RaspConfiguration from file=" + raspConfigurationFileName);
versionNumber = loadVersionNumber();
Version.initNumbering();
log.info("This RASP is: " + Version.getVersion());
public LdapSettings getLdapSettings() {
// The XPath for our configuration section
String xpathBase = "//ConfigurationSection[@*=\"LdapSettings\"]/";
log.debug("Loading LDAP settings from RaspConfiguration file...");
if (ldapSettings == null) {
ldapSettings = new LdapSettings();
pjohansson
committed
ldapSettings.setHost(raspConfigurationFile.getString(xpathBase + "Host"));
ldapSettings.setMaxResults(raspConfigurationFile.getInt(xpathBase + "MaxResults"));
ldapSettings.setPort(raspConfigurationFile.getInt(xpathBase + "Port"));
ldapSettings.setSearchServerTimeoutMsec(raspConfigurationFile.getInt(xpathBase + "SearchServerTimeoutMsec"));
pjohansson
committed
ldapSettings.setSearchClientTimeoutMsec(raspConfigurationFile.getInt(xpathBase + "ConnectionTimeoutMsec"));
return ldapSettings;
}
/**
public OcspConfig getOcspConfig() throws URISyntaxException {
log.debug("RaspConfigurationHandler.getOcspConfig");
if (ocspConfig == null) {
// The XPath for our configuration section
String xpathBase = "//ConfigurationSection[@*=\"OcspConfig\"]/";
synchronized (RASPCONFIGURATION_XML_DEFAULT) {
ocspConfig.setDefaultTimeoutMsec(raspConfigurationFile.getInt(xpathBase + "DefaultTimeoutMsec"));
String serverUrl = raspConfigurationFile.getString(xpathBase + "ServerUrl");
if (serverUrl != null) {
ocspConfig.setServerUrl(serverUrl);
}
return ocspConfig;
}
/**
* Get the OCSP settings.
*
* @return OCSP settings
*/
public CacheConfig getCacheConfig() {
log.debug("RaspConfigurationHandler.getCacheConfig");
if (cacheConfig == null) {
synchronized (RASPCONFIGURATION_XML_DEFAULT) {
cacheConfig = new CacheConfig();
cacheConfig.setOcspLookupCache(parseCacheConfigElement(CacheConfigKey.OcspLookupCache));
cacheConfig.setCrlLookupCache(parseCacheConfigElement(CacheConfigKey.CrlLookupCache));
cacheConfig.setUddiServiceCache(parseCacheConfigElement(CacheConfigKey.UddiServiceCache));
cacheConfig.setUddiTModelCache(parseCacheConfigElement(CacheConfigKey.UddiTModelCache));
cacheConfig.setCertificateCache(parseCacheConfigElement(CacheConfigKey.CertificateCache));
cacheConfig.setSchematronCache(parseCacheConfigElement(CacheConfigKey.SchematronCache));
}
}
return cacheConfig;
}
@SuppressWarnings("unchecked")
private CacheConfigElement parseCacheConfigElement(CacheConfigKey cacheConfigKey) {
String cacheElementName = cacheConfigKey.name();
String xpathCacheBase = "//ConfigurationSection[@*=\"CacheConfig\"]//" + cacheElementName;
String implementationNamespaceClass = raspConfigurationFile.getString(xpathCacheBase + "/ImplementationNamespaceClass");
String implementationAssembly = raspConfigurationFile.getString(xpathCacheBase + "/ImplementationAssembly");
List<SubnodeConfiguration> list = raspConfigurationFile.configurationsAt(xpathCacheBase + "/CacheConfigurationCollection");
Map<String, String> configuration = null;
* Each ConfigurationSection can contain only one
* CacheConfigurationCollection, but method configurationAt
* IllegalArgumentException throws exception, if it cannot find
* given key, so we replace it with configurationsAt() to support
* old versions of RaspConfiguration.xml
*/
SubnodeConfiguration subnodeConfiguration = list.get(0);
configuration = this.cacheConfiguration(subnodeConfiguration);
}
return new CacheConfigElement(cacheElementName, implementationNamespaceClass, implementationAssembly, configuration);
}
@SuppressWarnings("unchecked")
private Map<String, String> cacheConfiguration(SubnodeConfiguration subnodeConfiguration) {
Map<String, String> configurationMap = new HashMap<>();
List<HierarchicalConfiguration> configurationCollection = subnodeConfiguration.configurationsAt("Configuration");
for (HierarchicalConfiguration cacheConfiguration : configurationCollection) {
String key = cacheConfiguration.getString("Key");
String value = cacheConfiguration.getString("Value");
configurationMap.put(key, value);
}
return configurationMap;
}
/**
* Get the Root certificate settings. In case of old version of RaspConfiguration.xml, returns collection with only one value from
* The reason for such method to be used - from some point OIORASP will support multiple root certificates from different issuers or
* with different roots.
dlk-truelink
committed
@SuppressWarnings("unchecked")
public List<RootCertificateConfig> getRootCertificateLocationCollection() {
Jacob Lund Mogensen
committed
String xpathBase = "//ConfigurationSection[@*=\"RootCertificateCollectionConfig\"]/";
List<RootCertificateConfig> collection = new ArrayList<>();
List<SubnodeConfiguration> subnodeConfigurationList = raspConfigurationFile.configurationsAt(xpathBase + "RootCertificateLocationCollection");
if (subnodeConfigurationList.isEmpty()) {
// Get the Root certificate settings for old versions of RaspConfiguration.xml
String xpathBaseOld = "//ConfigurationSection[@*=\"RootCertificateConfig\"]/";
rootCertificateConfig = new RootCertificateConfig();
rootCertificateConfig.setKeyStoreLocation(raspConfigurationFile.getString(xpathBaseOld + "KeyStoreLocation"));
rootCertificateConfig.setKeyStorePassword(raspConfigurationFile.getString(xpathBaseOld + "KeyStorePassword"));
rootCertificateConfig.setKeyLabel(raspConfigurationFile.getString(xpathBaseOld + "KeyLabel"));
collection.add(rootCertificateConfig);
} else {
// New version of RaspConfiguration.xml - contains tag RootCertificateLocationCollection
SubnodeConfiguration subnodeConfiguration = subnodeConfigurationList.get(0);
List<HierarchicalConfiguration> rootCertificateLocationList = subnodeConfiguration.configurationsAt("RootCertificateLocation");
log.debug("RootCertificateLocationCollection: Elements found, count=" + rootCertificateLocationList.size());
for (HierarchicalConfiguration rootCertificateLocation : rootCertificateLocationList) {
rootCertificateConfig = new RootCertificateConfig();
rootCertificateConfig.setKeyStoreLocation(rootCertificateLocation.getString("KeyStoreLocation"));
rootCertificateConfig.setKeyStorePassword(rootCertificateLocation.getString("KeyStorePassword"));
rootCertificateConfig.setKeyLabel(rootCertificateLocation.getString("KeyLabel"));
// add the rootCert
collection.add(rootCertificateConfig);
}
}
log.debug("Root certificates loaded from RootCertificateLocationCollection, count=" + collection.size());
return collection;
}
*/
public OcesX509CertificateConfig getOcesX509CertificateConfig() throws InvalidOcesCertificateSubjectKeyException {
// The XPath for our configuration section
String xpathBase = "//ConfigurationSection[@*=\"OcesX509CertificateConfig\"]/";
OcesX509CertificateConfig ocesX509CertConfig = new OcesX509CertificateConfig();
ocesX509CertConfig.set_personalCertificateSubjectKey(new OcesCertificateSubjectKey(raspConfigurationFile.getString(xpathBase + "/PersonalCertificateSubjectKey/SubjectKeyString")));
ocesX509CertConfig.set_organizationCertificateSubjectKey(new OcesCertificateSubjectKey(raspConfigurationFile.getString(xpathBase + "/OrganizationCertificateSubjectKey/SubjectKeyString")));
ocesX509CertConfig.set_employeeCertificateSubjectKey(new OcesCertificateSubjectKey(raspConfigurationFile.getString(xpathBase + "/EmployeeCertificateSubjectKey/SubjectKeyString")));
ocesX509CertConfig.set_functionCertificateSubjectKey(new OcesCertificateSubjectKey(raspConfigurationFile.getString(xpathBase + "/FunctionCertificateSubjectKey/SubjectKeyString")));
}
return ocesX509CertConfig;
}
* Get the settings used for NHR/UDDI lookup.
public UddiConfig getUddiConfig() throws URISyntaxException {
/**
* Get the settings used for NHR/UDDI lookup. Loaded uddiConfig can be bypassed.
*
* @return UDDI settings
* @throws URISyntaxException On error...
*/
public UddiConfig getUddiConfig(final boolean forceReload) throws URISyntaxException {
log.debug("RaspConfigurationHandler.getUddiConfig");
if (uddiConfig == null || forceReload) {
// The XPath for our configuration section
String xpathBase = "//ConfigurationSection[@*=\"UddiConfig\"]/";
synchronized (RASPCONFIGURATION_XML_DEFAULT) {
uddiConfig = new UddiConfig();
uddiConfig.setFallbackTimeoutMinutes(raspConfigurationFile.getInt(xpathBase + "FallbackTimeoutMinutes"));
SubnodeConfiguration lookupRegistryFallbackSubNodes = raspConfigurationFile.configurationAt(xpathBase + "LookupRegistryFallbackConfig");
LookupRegistryFallbackConfig lookupRegistryFallbackConfig = getLookupRegistryFallbackConfig(lookupRegistryFallbackSubNodes);
uddiConfig.setLookupRegistryFallbackConfig(lookupRegistryFallbackConfig);
}
private LookupRegistryFallbackConfig getLookupRegistryFallbackConfig(SubnodeConfiguration lookupRegistryFallbackSubNodes) throws URISyntaxException {
LookupRegistryFallbackConfig config = new LookupRegistryFallbackConfig();
ArrayList<Registry> registries = new ArrayList<>();
List<?> registrySubNodes = lookupRegistryFallbackSubNodes.configurationsAt("PrioritizedRegistryList/Registry");
for (Object registrySubNodeObject : registrySubNodes) {
SubnodeConfiguration registrySubNode = (SubnodeConfiguration) registrySubNodeObject;
Registry registry = loadRegistry(registrySubNode);
registries.add(registry);
}
config.setRegistries(registries);
return config;
private Registry loadRegistry(SubnodeConfiguration registrySubNode) throws URISyntaxException {
String[] endpoints = registrySubNode.getStringArray(xpath);
int uddiLookupTimeoutSeconds = registrySubNode.getInt("/UddiLookupTimeoutSeconds", 120);
return new Registry(endpoints, uddiLookupTimeoutSeconds);
public DocumentTypeCollectionConfig getRaspDocumentTypeCollectionConfig() throws ConfigurationException {
return getRaspDocumentTypeCollectionConfig(false);
}
/**
* Gets the document type configurations.
*
* @return Document type configurations
* @throws ConfigurationException On error...
*/
public DocumentTypeCollectionConfig getRaspDocumentTypeCollectionConfig(final boolean forceReload) throws ConfigurationException {
log.debug("RaspConfigurationHandler.getRaspDocumentTypeCollectionConfig");
if (raspDocumentTypeCollectionConfig == null || forceReload) {
synchronized (RASPCONFIGURATION_XML_DEFAULT) {
raspDocumentTypeCollectionConfig = new DocumentTypeCollectionConfig();
String[] docs = raspConfigurationFile.getStringArray("//DocumentTypes/DocumentTypeConfig/RootName");
for (int i = 0; i < docs.length; i++) {
DocumentTypeConfig typeConfig = initDocumentTypeConfig(i);
raspDocumentTypeCollectionConfig.addDocumentType(typeConfig);
} catch (Exception e) {
log.error("Could not init DocumentTypeConfig " + e.getMessage(), e);
ConfigurationException ex = new ConfigurationException("Could not init DocumentTypeConfig " + e);
ex.setStackTrace(e.getStackTrace());
return raspDocumentTypeCollectionConfig;
public SendPolicy getSendPolicy() throws ConfigurationException {
if (sendPolicy == null) {
synchronized (RASPCONFIGURATION_XML_DEFAULT) {
log.debug("RaspConfigurationHandler.getSendPolicy");
// The XPath for our configuration section
String xpathBase = "//ConfigurationSection[@*=\"Axis2JavaRasp\"]/";
sendPolicy = new SendPolicy();
pjohansson
committed
String wssPolicy = raspConfigurationFile.getString(xpathBase + "WSSPolicyFile");
if (log.isInfoEnabled()) {
log.info("Config: wss policy file: " + wssPolicy);
sendPolicy.setWSSPolicyFileName(wssPolicy);
pjohansson
committed
String axisConf = raspConfigurationFile.getString(xpathBase + "AxisConfigurationFile");
log.info("Config: axis configuration: " + axisConf);
sendPolicy.setAxisConfigurationFile(axisConf);
pjohansson
committed
String repoDir = raspConfigurationFile.getString(xpathBase + "AxisRepositoryDir");
log.info("Config: axis repository dir: " + repoDir);
sendPolicy.setAxisRepositoryDir(repoDir);
String httpPrefix = xpathBase + "RMPolicy/HTTPTransport/RMAssertion/Policy/";
RMPolicy httpPolicy = initRMPolicy(httpPrefix);
sendPolicy.setHttpRMPolicy(httpPolicy);
* @return UDDI factory configuration
*/
public UddiLookupClientFactoryConfig getUddiLookupClientFactoryConfig() {
log.debug("RaspConfigurationHandler.getUddiLookupClientFactoryConfig");
if (uddiClientFactory == null) {
synchronized (RASPCONFIGURATION_XML_DEFAULT) {
initFactories();
}
}
return uddiClientFactory;
}
* @return Registry factory configuration
*/
public RegistryLookupClientFactoryConfig getRegistryLookupClientFactoryConfig() {
log.debug("RaspConfigurationHandler.getUddiLookupClientFactoryConfig");
if (registryClientFactory == null) {
synchronized (RASPCONFIGURATION_XML_DEFAULT) {
initFactories();
}
}
return registryClientFactory;
}
* @return LDAP factory configuration
*/
public LdapLookupFactoryConfig getLdapLookupFactoryConfig() {
if (ldapFactory == null) {
synchronized (RASPCONFIGURATION_XML_DEFAULT) {
initFactories();
}
}
return ldapFactory;
}
/**
public RevocationLookupFactoryConfig getRevocationLookupFactoryConfig() {
log.debug("getRevocationLookupFactoryConfig called...");
if (revocationFactory == null) {
synchronized (RASPCONFIGURATION_XML_DEFAULT) {
* @return ProfileMappingCollectionConfig object.
* @throws ConfigurationException On error...
public ProfileMappingCollectionConfig getProfileMappingCollectionConfig() throws ConfigurationException {
if (profileMappingCollectionConfig == null) {
synchronized (RASPCONFIGURATION_XML_DEFAULT) {
profileMappingCollectionConfig = new ProfileMappingCollectionConfig();
String[] names = raspConfigurationFile.getStringArray("//ProfileMappingCollection/ProfileMapping/Name");
String[] tModelIds = raspConfigurationFile.getStringArray("//ProfileMappingCollection/ProfileMapping/TModelGuid");
Peter Sone Koldkjær
committed
if (names == null || tModelIds == null) {
throw new ConfigurationException("ProfileMappingCollectionConfig: Names or tModelGuids are null");
} else if (names.length != tModelIds.length) {
throw new ConfigurationException("ProfileMappingCollectionConfig: Different number of names and tModelGuids");
Peter Sone Koldkjær
committed
for (int i = 0; i < names.length; i++) {
ProfileMapping profileMapping = new ProfileMapping(names[i], tModelIds[i]);
ConfigurationException ex = new ConfigurationException("Could not init ProfileMappingCollectionConfig: " + e);
ex.setStackTrace(e.getStackTrace());
throw ex;
}
}
}
* Initiate the reliable messaging configuration.
* @param xpath where to find the configuration in the XML-document
* @return RMPolicy
* @throws ConfigurationException On error...
private RMPolicy initRMPolicy(String xpath) throws ConfigurationException {
boolean eb = raspConfigurationFile.getBoolean(xpath + "ExponentialBackoff");
long retr = raspConfigurationFile.getLong(xpath + "RetransmissionInterval");
int max = raspConfigurationFile.getInt(xpath + "MaximumRetransmissionCount");
return new RMPolicy(max, retr, eb);
} catch (Exception e) {
ConfigurationException ex = new ConfigurationException("Could not init SendPolicy " + e);
ex.setStackTrace(e.getStackTrace());
/**
* Read document.
* @return configuration for document
*/
private DocumentTypeConfig initDocumentTypeConfig(int docIndex) {
// The XPath for our configuration section
String xpathBase = "//ConfigurationSection[@*=\"DocumentTypeCollectionConfig\"]/";
DocumentTypeConfig documentTypeConfig = new DocumentTypeConfig();
String documentSelect = xpathBase + "DocumentTypes/DocumentTypeConfig[" + (docIndex + 1) + "]";
if (log.isDebugEnabled()) {
log.debug("Retrieving basic data for " + documentSelect);
}
documentTypeConfig.setRootName(raspConfigurationFile.getString(documentSelect + "/RootName"));
documentTypeConfig.setFriendlyName(raspConfigurationFile.getString(documentSelect + "/FriendlyName"));
documentTypeConfig.setRootNamespace(raspConfigurationFile.getString(documentSelect + "/RootNamespace"));
documentTypeConfig.setSchemaPath(raspConfigurationFile.getString(documentSelect + "/SchemaPath"));
documentTypeConfig.setServiceContractTModel(raspConfigurationFile.getString(documentSelect + "/ServiceContractTModel"));
documentTypeConfig.setStylesheetPath(raspConfigurationFile.getString(documentSelect + "/StylesheetPath"));
pjohansson
committed
String tmp = raspConfigurationFile.getString(documentSelect + "/XsltTransformStylesheetPath");
if (tmp != null && tmp.length() > 0) {
documentTypeConfig.setXsltTransformStylesheetPath(tmp);
int noOfSchematronValidationConfigs = raspConfigurationFile.getList(documentSelect + "/SchematronValidationConfigs/SchematronValidationConfig/SchematronDocumentPath").size();
documentTypeConfig.getSchematronValidationConfigList().clear();
for (int x = 0; x < noOfSchematronValidationConfigs; x++) {
Peter Sone Koldkjær
committed
SchematronValidationConfig svc = new SchematronValidationConfig(raspConfigurationFile.getString(documentSelect + "/SchematronValidationConfigs/SchematronValidationConfig[" + (x + 1) + "]/SchematronDocumentPath"),
raspConfigurationFile.getString(documentSelect + "/SchematronValidationConfigs/SchematronValidationConfig[" + (x + 1) + "]/ErrorXPath"),
raspConfigurationFile.getString(documentSelect + "/SchematronValidationConfigs/SchematronValidationConfig[" + (x + 1) + "]/ErrorMessageXPath"));
documentTypeConfig.getSchematronValidationConfigList().add(svc);
}
//
DocumentEndpointInformation rdept = new DocumentEndpointInformation();
rdept.setEndpointFriendlyName(new ServiceEndpointFriendlyName(raspConfigurationFile.getString(documentSelect
pjohansson
committed
+ "/EndpointType/EndpointFriendlyName/XPath")));
rdept.setSenderFriendlyName(new ServiceEndpointFriendlyName(raspConfigurationFile.getString(documentSelect
pjohansson
committed
+ "/EndpointType/SenderFriendlyName/XPath")));
pjohansson
committed
rdept.setReplyAction(raspConfigurationFile.getString(documentSelect + "/EndpointType/ReplyAction"));
rdept.setRequestAction(raspConfigurationFile.getString(documentSelect + "/EndpointType/RequestAction"));
ServiceEndpointKey recipientRdk = new ServiceEndpointKey();
recipientRdk.setXPath(raspConfigurationFile.getString(documentSelect + "/EndpointType/Key/Xpath"));
pjohansson
committed
KeyTypeMappingExpression recipientKeyTypeMapping = getKeyTypeMappingExpression(documentSelect + "/EndpointType/Key");
recipientRdk.addMappingExpression(recipientKeyTypeMapping);
// Sender Key
ServiceEndpointKey senderRdk = new ServiceEndpointKey();
pjohansson
committed
senderRdk.setXPath(raspConfigurationFile.getString(documentSelect + "/EndpointType/SenderKey/Xpath"));
pjohansson
committed
KeyTypeMappingExpression senderKeyTypeMapping = getKeyTypeMappingExpression(documentSelect + "/EndpointType/SenderKey");
senderRdk.addMappingExpression(senderKeyTypeMapping);
rdept.setKey(recipientRdk);
documentTypeConfig.setEndpointType(rdept);
String profileIdXPath = raspConfigurationFile.getString(documentSelect + "/ProfileIdXPath/XPath");
documentTypeConfig.setProfileIdXPath(profileIdXPath);
pjohansson
committed
int noOfEndNameSpaces = raspConfigurationFile.getList(documentSelect + "/Namespaces/PrefixedNamespace/Namespace").size();
documentTypeConfig.getNamespacesList().clear();
for (int x = 0; x < noOfEndNameSpaces; x++) {
PrefixedNamespace namespace = new PrefixedNamespace();
namespace.setPrefix(raspConfigurationFile.getString(documentSelect + "/Namespaces/PrefixedNamespace[" + (x + 1) + "]/Prefix"));
namespace.setNamespace(raspConfigurationFile.getString(documentSelect + "/Namespaces/PrefixedNamespace[" + (x + 1) + "]/Namespace"));
documentTypeConfig.getNamespacesList().add(namespace);
pjohansson
committed
String csXpath = documentSelect + "/CustomHeaderConfiguration/XPaths";
CustomHeaderConfiguration chc = new CustomHeaderConfiguration();
List<CustomHeaderXPathConfiguration> headerList = new ArrayList<>();
for (Iterator<?> it = raspConfigurationFile.getKeys(csXpath); it.hasNext(); ) {
String key = it.next().toString();
String xpath = raspConfigurationFile.getString(key);
if (xpath.length() > 0) {
String elementName = key.substring(csXpath.length() + 1);
CustomHeaderXPathConfiguration chxc = new CustomHeaderXPathConfiguration();
chxc.setName(elementName);
chxc.setXPath(xpath);
headerList.add(chxc);
}
}
chc.setXPaths(headerList.toArray(new CustomHeaderXPathConfiguration[0]));
documentTypeConfig.setCustomHeaderConfiguration(chc);
// xpath discriminator collection
String[] identifierList = raspConfigurationFile.getStringArray(documentSelect + "/IdentifierDiscriminators/XPathDiscriminatorConfig/XPathExpression");
if (identifierList.length > 0) {
XPathDiscriminatorConfigCollection xpathIdentifiers = new XPathDiscriminatorConfigCollection();
for (int i = 0; i < identifierList.length; i++) {
XPathDiscriminatorConfig identifier = new XPathDiscriminatorConfig();
String expression = raspConfigurationFile.getString(documentSelect
+ "/IdentifierDiscriminators/XPathDiscriminatorConfig[" + (i + 1) + "]/XPathExpression");
String expectedResult = raspConfigurationFile.getString(documentSelect
+ "/IdentifierDiscriminators/XPathDiscriminatorConfig[" + (i + 1) + "]/XPathExpectedResult");
identifier.setXPathExpression(expression);
identifier.setXPathExpectedResult(expectedResult);
xpathIdentifiers.add(identifier);
}
documentTypeConfig.setIdentifierDiscriminators(xpathIdentifiers);
Peter Sone Koldkjær
committed
log.debug("Finished loading documentType");
return documentTypeConfig;
* Utility to initiate key type for sender/receiver key (CVR, EAN...).
* @return mapping
*/
private KeyTypeMappingExpression getKeyTypeMappingExpression(String path) {
KeyTypeMappingExpression keyTypeMapping = new KeyTypeMappingExpression();
String keyTypeMappingXPath = path + "/MappingExpressions/KeyTypeMappingExpressions/Name";
String[] mappings = raspConfigurationFile.getStringArray(keyTypeMappingXPath);
for (int i = 0; i < mappings.length; i++) {
String mapExprKey = path + "/MappingExpressions/KeyTypeMappingExpressions[" + (i + 1) + "]";
pjohansson
committed
String mapName = raspConfigurationFile.getString(mapExprKey + "/Name");
String mapXPath = raspConfigurationFile.getString(mapExprKey + "/XPathExpression");
keyTypeMapping.setName(mapName);
keyTypeMapping.setXPathExpression(mapXPath);
pjohansson
committed
String[] mapList = raspConfigurationFile.getStringArray(mapExprKey + "/Mappings/Mapping/Value");
for (int j = 0; j < mapList.length; j++) {
String mapListKey = mapExprKey + "/Mappings/Mapping[" + (j + 1) + "]";
pjohansson
committed
String value = raspConfigurationFile.getString(mapListKey + "/Value");
String mapsTo = raspConfigurationFile.getString(mapListKey + "/MapsTo");
KeyTypeMapping map = new KeyTypeMapping();
map.setValue(value);
map.setMapsTo(mapsTo);
keyTypeMapping.addMapping(map);
}
}
return keyTypeMapping;
}
registryClientFactory = new RegistryLookupClientFactoryConfig();
registryClientFactory.setImplementationNamespaceClass(raspConfigurationFile.getString("//ConfigurationSection[@*=\"RegistryLookupClientFactoryConfig\"]/ImplementationNamespaceClass"));
pjohansson
committed
uddiClientFactory.setImplementationNamespaceClass(raspConfigurationFile.getString("//ConfigurationSection[@*=\"UddiLookupClientFactoryConfig\"]/ImplementationNamespaceClass"));
pjohansson
committed
ldapFactory = new LdapLookupFactoryConfig();
ldapFactory.setImplementationNamespaceClass(raspConfigurationFile.getString("//ConfigurationSection[@*=\"LdapLookupFactoryConfig\"]/ImplementationNamespaceClass"));
revocationFactory = new RevocationLookupFactoryConfig();
revocationFactory.setImplementationNamespaceClass(raspConfigurationFile.getString("//ConfigurationSection[@*=\"RevocationLookupFactoryConfig\"]/ImplementationNamespaceClass"));
public void executeStartupTasks() throws MainException {
List<IStartupTask> taskList = this.getStartupTaskList();
if (taskList != null && !taskList.isEmpty()) {
int failedExecutionCount = 0;
Exception firstException = null;
long start = System.currentTimeMillis();
for (IStartupTask task : taskList) {
try {
task.doTask();
} catch (Exception e) {
log.error("Failure during startup execution of task " + task + ": " + e.getMessage(), e);
if (firstException == null) {
firstException = e;
}
}
}
if (firstException == null) {
if (log.isInfoEnabled()) {
log.info("ConfigurationHandler successfully executed " + taskList.size() + " startup tasks in " + (System.currentTimeMillis() - start) + " ms");
}
} else {
throw new MainException("ConfigurationHandler failed to execute " + failedExecutionCount + " startup tasks, see first exception in stack trace", firstException);
}
} else {
log.warn("ConfigurationHandler: executeStartupTasks method was called but no startup tasks are configured. Please check RaspConfiguration.xml file to be updated with StartupConfig ConfigurationSection");
}
}
/**
* Returns list of startup tasks. This list can be modified before call of executeStartupTasks().
if (this.startupTaskList == null) {
try {
/*
* In case if several threads try to initialize tasks, we should
* not restrict it, as it is not critical to have several
* instances of them - only last instance of List will be kept in memory
*/
long start = System.currentTimeMillis();
List<IStartupTask> taskList;
synchronized (RASPCONFIGURATION_XML_DEFAULT) {
taskList = parseStartTaskList(this.raspConfigurationFile);
this.startupTaskList = taskList;
}
if (log.isInfoEnabled()) {
// Skip showing success message if no task is correctly configured
log.info("ConfigurationHandler: startup tasks are initialized in " + (System.currentTimeMillis() - start) + " ms, found " + taskList.size() + " tasks.");
* Additionally protect start task initialization from
* unexpected exceptions, they should not prevent the system to
* start, as they are not necessary should be executed.
*/
}
}
return startupTaskList;
}
/**
* Overwrites configured startup task list
*
* @param startupTaskList List of IStartupTasks.
*/
public void setStartupTaskList(List<IStartupTask> startupTaskList) {
this.startupTaskList = startupTaskList;
}
/**
* Load version number from file "version-number.txt".
* <p/>
* 1st priority is to load it from root of JAR file, 2nd priority is loading it from source root (for unit tests).
*
* @return Text with version number.
*/
private String loadVersionNumber() {
InputStream is = getClass().getResourceAsStream("/version-number.txt");
if (is == null) {
return loadVersionNumberFromLocalFile();
}
//noinspection ResultOfMethodCallIgnored
// Non-JAR/Unit test scenario
return loadVersionNumberFromLocalFile();
}
} catch (IOException e) {
log.fatal("Problem loading version file: " + e.getMessage(), e);
}
log.fatal("Problem loading version file... but no exception thrown");
return null;
}
* Load version number from local file "version-number.txt" as part of unit test.
*
* @return Text with version number.
*/
private String loadVersionNumberFromLocalFile() {
File versionFile = new File("target/version-number.txt");
try {
// Unit test scenario, where the
return FileUtils.readFileToString(versionFile);
} catch (IOException e) {
log.warn("Problem loading version file from " + versionFile.getAbsolutePath() + ": " + e.getMessage());