in modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java [133:243]
public boolean injectMessage(final MessageContext synCtx) {
if (log.isDebugEnabled()) {
log.debug("Injecting MessageContext");
}
synCtx.setEnvironment(this);
Mediator mandatorySeq = synCtx.getConfiguration().getMandatorySequence();
// the mandatory sequence is optional and hence check for the existence before mediation
if (mandatorySeq != null) {
if (log.isDebugEnabled()) {
log.debug("Start mediating the message in the " +
"pre-mediate state using the mandatory sequence");
}
if(!mandatorySeq.mediate(synCtx)) {
if(log.isDebugEnabled()) {
log.debug((synCtx.isResponse() ? "Response" : "Request") + " message for the "
+ (synCtx.getProperty(SynapseConstants.PROXY_SERVICE) != null ?
"proxy service " + synCtx.getProperty(SynapseConstants.PROXY_SERVICE) :
"message mediation") + " dropped in the " +
"pre-mediation state by the mandatory sequence : \n" + synCtx);
}
return false;
}
}
String receivingSequence = (String) synCtx.getProperty(SynapseConstants.RECEIVING_SEQUENCE);
// remove the receivingSequence property
Set keySet = synCtx.getPropertyKeySet();
if (keySet != null) {
keySet.remove(SynapseConstants.RECEIVING_SEQUENCE);
}
// if this is not a response to a proxy service
String proxyName = (String) synCtx.getProperty(SynapseConstants.PROXY_SERVICE);
if (proxyName == null || "".equals(proxyName)) {
// set default fault handler
synCtx.pushFaultHandler(new MediatorFaultHandler(synCtx.getFaultSequence()));
if (receivingSequence != null) {
if (log.isDebugEnabled()) {
log.debug("Using Sequence with name: " + receivingSequence
+ " for injected message");
}
Mediator seqMediator = synCtx.getSequence(receivingSequence);
if (seqMediator != null) {
return seqMediator.mediate(synCtx);
} else {
log.warn("Cannot find a Sequence with name: " + receivingSequence
+ " for injecting the response message");
return false;
}
} else {
boolean processed = restHandler.process(synCtx);
if (processed) {
return true;
}
if (log.isDebugEnabled()) {
log.debug("Using Main Sequence for injected message");
}
return synCtx.getMainSequence().mediate(synCtx);
}
}
ProxyService proxyService = synCtx.getConfiguration().getProxyService(proxyName);
if (proxyService != null) {
if (proxyService.getTargetFaultSequence() != null) {
Mediator faultSequence = synCtx.getSequence(proxyService.getTargetFaultSequence());
if (faultSequence != null) {
synCtx.pushFaultHandler(new MediatorFaultHandler(faultSequence));
} else {
log.warn("Cloud not find any fault-sequence named :" +
proxyService.getTargetFaultSequence() + "; Setting the default" +
" fault sequence for out path");
synCtx.pushFaultHandler(new MediatorFaultHandler(synCtx.getFaultSequence()));
}
} else if (proxyService.getTargetInLineFaultSequence() != null) {
synCtx.pushFaultHandler(
new MediatorFaultHandler(proxyService.getTargetInLineFaultSequence()));
} else {
synCtx.pushFaultHandler(new MediatorFaultHandler(synCtx.getFaultSequence()));
}
Mediator outSequence = getProxyOutSequence(synCtx, proxyService);
if (receivingSequence != null) {
if (log.isDebugEnabled()) {
log.debug("Using Sequence with name: " + receivingSequence
+ " for injected message");
}
Mediator seqMediator = synCtx.getSequence(receivingSequence);
if (seqMediator != null) {
seqMediator.mediate(synCtx);
} else {
log.warn("Cannot find a Sequence with name: " + receivingSequence
+ " for injecting the message");
return false;
}
} else if (outSequence != null) {
outSequence.mediate(synCtx);
} else {
if (log.isDebugEnabled()) {
log.debug(proxyService
+ " does not specifies an out-sequence - sending the response back");
}
Axis2Sender.sendBack(synCtx);
}
}
return true;
}