log.debug("Start Sending the Message ");
}
try {
MessageContext messageOut = MessageHelper.cloneMessageContext(messageIn);
Options options = new Options();
options.setTo(new EndpointReference(serviceUrl));
if(messageIn.getSoapAction() != null) {
options.setAction(messageIn.getSoapAction());
} else {
if (messageIn.isSOAP11()) {
options.setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, true);
} else {
Axis2MessageContext axis2smc = (Axis2MessageContext) messageOut;
org.apache.axis2.context.MessageContext axis2MessageCtx =
axis2smc.getAxis2MessageContext();
axis2MessageCtx.getTransportOut().addParameter(
new Parameter(HTTPConstants.OMIT_SOAP_12_ACTION, true));
}
}
//After setting all the options we need to find the MEP of the Message
org.apache.axis2.context.MessageContext axis2Ctx =
((Axis2MessageContext)messageOut).getAxis2MessageContext();
boolean outOnlyMessage = "true".equals(messageIn.getProperty(
SynapseConstants.OUT_ONLY)) || WSDL2Constants.MEP_URI_IN_ONLY.equals(
axis2Ctx.getOperationContext()
.getAxisOperation().getMessageExchangePattern());
// Here We consider all other Messages that evaluates to outOnlyMessage == false
// follows out in mep.
if(log.isDebugEnabled()) {
log.debug("Invoking service Url " + serviceUrl + " with Message" +
messageIn.getMessageID());
}
options.setProperty(
AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES, Boolean.TRUE);
//clean existing headers
// otherwise when retrying same header element will add multiple times
sc.removeHeaders();
axis2Ctx.getAttachmentMap();
Iterator itr = axis2Ctx.getEnvelope().getHeader().getChildren();
while (itr.hasNext()) {
Object o =itr.next();
if ( o instanceof OMElement ){
sc.addHeader((OMElement)o);
}
}
sc.setOptions(options);
OMElement result = null;
try {
OMElement payload = axis2Ctx.getEnvelope().getBody().getFirstElement();
if(outOnlyMessage) {
sc.sendRobust(payload);
} else {
result = sc.sendReceive(payload);
}
} catch (Exception axisFault) {
// Here if Message is not a Out only Message
// To indicate that it is a Error we set a new Message Context property
// and return the message context
// If its not we throw an Exception
if (!outOnlyMessage) {
messageOut.setProperty(ForwardingProcessorConstants.BLOCKING_SENDER_ERROR,
"true");
return messageOut;
}