}
private static SynapseConfiguration initializeSynapse(
ConfigurationContext cfgCtx) {
AxisConfiguration axisConfiguration = cfgCtx.getAxisConfiguration();
/*
First check, if synapse.xml URL is provided as a system property, if so use it..
else check if synapse.xml location is available from the axis2.xml
"SynapseConfiguration" else use the default config
*/
SynapseConfiguration synapseConfiguration;
Parameter configParam = axisConfiguration.getParameter(Constants.SYNAPSE_CONFIGURATION);
String config = System.getProperty(Constants.SYNAPSE_XML);
if (config != null) {
log.info("System property '" + Constants.SYNAPSE_XML +
"' specifies synapse configuration as " + config);
synapseConfiguration =
SynapseConfigurationBuilder.getConfiguration(config);
} else if (configParam != null) {
log.info(
"Synapse configuration is available via the " +
"'SynapseConfiguration' parameter in axis2.xml");
synapseConfiguration = SynapseConfigurationBuilder
.getConfiguration(configParam.getValue().toString().trim());
} else {
log.warn("System property '" + Constants.SYNAPSE_XML +
"' is not specified or 'SynapseConfiguration' Parameter " +
"is not available via axis2.xml. Using default configuration..");
synapseConfiguration =
SynapseConfigurationBuilder.getDefaultConfiguration();
}
// Set the Axis2 ConfigurationContext to the SynapseConfiguration
synapseConfiguration.setAxisConfiguration(cfgCtx.getAxisConfiguration());
// set the Synapse configuration and environment into the Axis2 configuration
Parameter synapseCtxParam = new Parameter(Constants.SYNAPSE_CONFIG, null);
synapseCtxParam.setValue(synapseConfiguration);
Parameter synapseEnvParam = new Parameter(Constants.SYNAPSE_ENV, null);
Parameter synEnvImpl = axisConfiguration.getParameter(Constants.SYNAPSE_ENV_IMPL);
if (synEnvImpl != null && synEnvImpl.getValue() != null) {
String clazz = (String) synEnvImpl.getValue();
try {
Constructor constr = Class.forName(clazz).getDeclaredConstructor(
new Class[]{ConfigurationContext.class});
synapseEnvParam.setValue(constr.newInstance(new Object[]{cfgCtx}));
} catch (ClassNotFoundException e) {
handleException("Cannot find Synapse environment implementation : " + clazz, e);
} catch (NoSuchMethodException e) {
handleException("Cannot find Synapse environment constructor : " + clazz, e);
} catch (IllegalAccessException e) {
handleException("Error instantiating Synapse environment with : " + clazz, e);
} catch (InvocationTargetException e) {
handleException("Error invoking constructor of Synapse environment : " + clazz, e);
} catch (InstantiationException e) {
handleException("Error instantiating Synapse environment with : " + clazz, e);
}
} else {
synapseEnvParam.setValue(new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration));
}
try {
axisConfiguration.addParameter(synapseCtxParam);
axisConfiguration.addParameter(synapseEnvParam);
} catch (AxisFault e) {
String msg =
"Could not set parameters '" + Constants.SYNAPSE_CONFIG +
"' and/or '" + Constants.SYNAPSE_ENV +