in modules/core/src/main/java/org/apache/sandesha2/SandeshaModule.java [67:239]
public void init(ConfigurationContext configContext,
AxisModule module) throws AxisFault {
if(log.isDebugEnabled()) log.debug("Entry: SandeshaModule::init, " + configContext);
EndpointReference.addAnonymousEquivalentURI(Sandesha2Constants.SPEC_2007_02.ANONYMOUS_URI_PREFIX);
AxisConfiguration config = configContext.getAxisConfiguration();
//load the Sandesha2Constants.STORAGE_MANAGER_PARAMETER if it is availabel in module.xml
Parameter storageManagerParameter = module.getParameter(Sandesha2Constants.STORAGE_MANAGER_PARAMETER);
if ((storageManagerParameter != null)
&& (config.getParameter(Sandesha2Constants.STORAGE_MANAGER_PARAMETER) == null)) {
config.addParameter(storageManagerParameter.getName(), storageManagerParameter.getValue());
}
//storing the Sandesha module as a parameter.
Parameter parameter = new Parameter(Sandesha2Constants.MODULE_CLASS_LOADER,module.getModuleClassLoader());
config.addParameter(parameter);
//init the i18n messages
SandeshaMessageHelper.innit();
//storing the module as a static variable
SandeshaUtil.setAxisModule(module);
// continueUncompletedSequences (storageManager,configCtx);
SandeshaPolicyBean constantPropertyBean = new SandeshaPolicyBean ();
SandeshaPolicyBean propertyBean = PropertyManager.loadPropertiesFromModuleDescPolicy(module,constantPropertyBean);
if (propertyBean==null) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.couldNotLoadModulePolicies);
log.error (message);
propertyBean = new SandeshaPolicyBean ();
} else {
if (log.isDebugEnabled()) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.modulePoliciesLoaded);
log.info (message);
}
}
parameter = new Parameter (Sandesha2Constants.SANDESHA_PROPERTY_BEAN, propertyBean);
config.addParameter(parameter);
// Reset both storage managers
parameter = config.getParameter(Sandesha2Constants.INMEMORY_STORAGE_MANAGER);
if(parameter != null) config.removeParameter(parameter);
parameter = config.getParameter(Sandesha2Constants.PERMANENT_STORAGE_MANAGER);
if(parameter != null) config.removeParameter(parameter);
try {
StorageManager inMemorytorageManager = SandeshaUtil.getInMemoryStorageManager(configContext);
inMemorytorageManager.initStorage(module);
} catch (SandeshaStorageException e) {
String message = SandeshaMessageHelper.getMessage(
SandeshaMessageKeys.cannotInitInMemoryStorageManager,
e.toString());
if (log.isDebugEnabled()) log.debug(message,e);
}
try {
StorageManager permanentStorageManager = SandeshaUtil.getPermanentStorageManager(configContext);
permanentStorageManager.initStorage(module);
} catch (SandeshaStorageException e) {
String message = SandeshaMessageHelper.getMessage(
SandeshaMessageKeys.cannotInitPersistentStorageManager,
e.toString());
if (log.isDebugEnabled()) log.debug(message,e);
}
// Reset the security manager, and then load it
parameter = config.getParameter(Sandesha2Constants.SECURITY_MANAGER);
if(parameter != null) config.removeParameter(parameter);
SecurityManager util = SandeshaUtil.getSecurityManager(configContext);
util.initSecurity(module);
// Mark the config context so that we can run sync 2-way interations over
// RM, but at the same time switch it off for unreliable messages.
// We do a similar trick with the code that does an early HTTP 202 for
// messages that don't need their backchannel.
configContext.setProperty(Constants.Configuration.USE_ASYNC_OPERATIONS, Boolean.TRUE);
configContext.getAxisConfiguration().addTargetResolver(
new TargetResolver() {
public void resolveTarget(MessageContext messageContext) {
//if Sandesha2 is not engaged we can set the property straight away
boolean engaged = false;
//checking weather the module is engaged at the System level
AxisConfiguration axisConfiguration = messageContext.getConfigurationContext().getAxisConfiguration();
if (axisConfiguration!=null) {
Collection<AxisModule> modules = axisConfiguration.getEngagedModules();
for (Iterator<AxisModule> iter = modules.iterator();iter.hasNext();) {
AxisModule module = (AxisModule) iter.next();
String moduleName = module.getName();
if (moduleName!=null && moduleName.startsWith (Sandesha2Constants.MODULE_NAME)) {
engaged = true;
}
}
}
//checking weather the module is engaged at the Service level
AxisService service = messageContext.getAxisService();
if (service!=null) {
Collection<AxisModule> modules = service.getEngagedModules();
for (Iterator<AxisModule> iter = modules.iterator();iter.hasNext();) {
AxisModule module = (AxisModule) iter.next();
String name = module.getName();
if (name!=null && name.startsWith (Sandesha2Constants.MODULE_NAME)) {
engaged = true;
}
}
}
//checking weather the module is engaged at the Operation level
AxisOperation operation = messageContext.getAxisOperation();
if (operation!=null) {
Collection<AxisModule> modules = operation.getEngagedModules();
for (Iterator<AxisModule> iter = modules.iterator();iter.hasNext();) {
AxisModule module = (AxisModule) iter.next();
String name = module.getName();
if (name!=null && name.startsWith (Sandesha2Constants.MODULE_NAME)) {
engaged = true;
}
}
}
//if the module is not engaed we mark the message as unreliable.
if (!engaged) {
if(log.isDebugEnabled()) log.debug("Unsetting USE_ASYNC_OPERATIONS and DISABLE_RESPONSE_ACK for unreliable message");
messageContext.setProperty(Constants.Configuration.USE_ASYNC_OPERATIONS, Boolean.FALSE);
messageContext.setProperty(Constants.Configuration.DISABLE_RESPONSE_ACK, Boolean.FALSE);
}
//Even when Sandesha2 is engaged this may be marked as unreliable.
if(log.isDebugEnabled()) log.debug("Entry: SandeshaModule::resolveTarget");
if(SandeshaUtil.isMessageUnreliable(messageContext)) {
if(log.isDebugEnabled()) log.debug("Unsetting USE_ASYNC_OPERATIONS for unreliable message");
messageContext.setProperty(Constants.Configuration.USE_ASYNC_OPERATIONS, Boolean.FALSE);
}
if(log.isDebugEnabled()) log.debug("Exit: SandeshaModule::resolveTarget");
}
}
);
Parameter propertiesFromRefMsg = module.getParameter(Sandesha2Constants.propertiesToCopyFromReferenceMessage);
if (propertiesFromRefMsg!=null) {
String value = (String) propertiesFromRefMsg.getValue();
if (value!=null) {
value = value.trim();
String[] propertyNames = value.split(",");
Parameter param = new Parameter();
param.setName(Sandesha2Constants.propertiesToCopyFromReferenceMessageAsStringArray);
param.setValue(propertyNames);
module.addParameter(param);
}
}
Parameter propertiesFromRefReqMsg = module.getParameter(Sandesha2Constants.propertiesToCopyFromReferenceRequestMessage);
if (propertiesFromRefReqMsg!=null) {
String value = (String) propertiesFromRefReqMsg.getValue();
if (value!=null) {
value = value.trim();
String[] propertyNames = value.split(",");
Parameter param = new Parameter();
param.setName(Sandesha2Constants.propertiesToCopyFromReferenceRequestMessageAsStringArray);
param.setValue(propertyNames);
module.addParameter(param);
}
}
if(log.isDebugEnabled()) log.debug("Exit: SandeshaModule::init");
}