File synapseConfigLocation = new File(configFile);
if (!synapseConfigLocation.exists()) {
String message = "Unable to load the Synapse configuration from : "
+ configFile + ". Specified file not found";
log.fatal(message);
throw new SynapseException(message);
}
SynapseConfiguration synCfg = null;
if (synapseConfigLocation.isFile()) {
// build the Synapse configuration parsing the XML config file
try {
synCfg = XMLConfigurationBuilder.getConfiguration(
new FileInputStream(configFile), properties);
log.info("Loaded Synapse configuration from : " + configFile);
} catch (Exception e) {
handleException("Could not initialize Synapse : " + e.getMessage(), e);
}
} else if (synapseConfigLocation.isDirectory()) {
// build the Synapse configuration by processing given directory hierarchy
try {
synCfg = MultiXMLConfigurationBuilder.getConfiguration(configFile, properties);
log.info("Loaded Synapse configuration from the artifact " +
"repository at : " + configFile);
} catch (XMLStreamException e) {
handleException("Could not initialize Synapse : " + e.getMessage(), e);
}
}
assert synCfg != null;
synCfg.setPathToConfigFile(new File(configFile).getAbsolutePath());
Registry localConfigReg = synCfg.getRegistry();
if (synCfg.getLocalRegistry().isEmpty() && synCfg.getProxyServices().isEmpty()
&& localConfigReg != null) {
if (log.isDebugEnabled()) {
log.debug("Only the registry is defined in the synapse configuration, trying " +
"to fetch a configuration from the registry");
}
// TODO: support a artifact repo for registry as well instead of just the synapse.xml
OMNode remoteConfigNode = localConfigReg.lookup("synapse.xml");
if (remoteConfigNode != null) {
try {
synCfg = XMLConfigurationBuilder.getConfiguration(SynapseConfigUtils
.getStreamSource(remoteConfigNode).getInputStream(), properties);
// TODO: when you fetch the configuration and serialize the config in any case
// TODO: the remote config is serialized to the synapse.xml we should prevent
// TODO: that, and should serialize the config to the registry
if (synCfg.getRegistry() == null) {
synCfg.setRegistry(localConfigReg);
} else {
log.warn("Registry declaration has been overwriten by the registry " +
"declaration found at the remote configuration");
}
} catch (XMLStreamException xse) {
throw new SynapseException("Problem loading remote synapse.xml ", xse);
}
} else if (log.isDebugEnabled()) {
log.debug("Couldn't find a synapse configuration on the registry");
}
}