use of org.apache.synapse.inbound.InboundResponseSender in project wso2-synapse by wso2.
the class Axis2Sender method sendBack.
/**
* Send a response back to a client of Synapse
*
* @param smc the Synapse message context sent as the response
*/
public static void sendBack(org.apache.synapse.MessageContext smc) {
if (preventMultipleResponses(smc)) {
return;
}
MessageContext messageContext = ((Axis2MessageContext) smc).getAxis2MessageContext();
// fault processing code
if (messageContext.isDoingREST() && messageContext.isFault() && isMessagePayloadHasASOAPFault(messageContext)) {
POXUtils.convertSOAPFaultToPOX(messageContext);
}
try {
messageContext.setProperty(SynapseConstants.ISRESPONSE_PROPERTY, Boolean.TRUE);
if (AddressingHelper.isReplyRedirected(messageContext) && !messageContext.getReplyTo().hasNoneAddress()) {
messageContext.setTo(messageContext.getReplyTo());
messageContext.setReplyTo(null);
messageContext.setWSAAction("");
messageContext.setSoapAction("");
messageContext.setProperty(NhttpConstants.IGNORE_SC_ACCEPTED, Constants.VALUE_TRUE);
messageContext.setProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES, Boolean.FALSE);
}
if (messageContext.getEnvelope().hasFault() && AddressingHelper.isFaultRedirected(messageContext) && (messageContext.getFaultTo() == null || !messageContext.getFaultTo().hasNoneAddress())) {
messageContext.setTo(messageContext.getFaultTo());
messageContext.setFaultTo(null);
messageContext.setWSAAction("");
messageContext.setSoapAction("");
messageContext.setProperty(NhttpConstants.IGNORE_SC_ACCEPTED, Constants.VALUE_TRUE);
messageContext.setProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES, Boolean.FALSE);
}
String preserveAddressingProperty = (String) smc.getProperty(SynapseConstants.PRESERVE_WS_ADDRESSING);
if (preserveAddressingProperty != null && Boolean.parseBoolean(preserveAddressingProperty)) {
/*Avoiding duplicate addressing headers*/
messageContext.setProperty(AddressingConstants.REPLACE_ADDRESSING_HEADERS, "true");
messageContext.setMessageID(smc.getMessageID());
} else {
MessageHelper.removeAddressingHeaders(messageContext);
messageContext.setMessageID(UIDGenerator.generateURNString());
}
// determine weather we need to preserve the processed headers
String preserveHeaderProperty = (String) smc.getProperty(SynapseConstants.PRESERVE_PROCESSED_HEADERS);
if (preserveHeaderProperty == null || !Boolean.parseBoolean(preserveHeaderProperty)) {
// remove the processed headers
MessageHelper.removeProcessedHeaders(messageContext, (preserveAddressingProperty != null && Boolean.parseBoolean(preserveAddressingProperty)));
}
// temporary workaround for https://issues.apache.org/jira/browse/WSCOMMONS-197
if (messageContext.isEngaged(SynapseConstants.SECURITY_MODULE_NAME) && messageContext.getEnvelope().getHeader() == null) {
SOAPFactory fac = messageContext.isSOAP11() ? OMAbstractFactory.getSOAP11Factory() : OMAbstractFactory.getSOAP12Factory();
fac.createSOAPHeader(messageContext.getEnvelope());
}
Axis2FlexibleMEPClient.clearSecurtityProperties(messageContext.getOptions());
// Invoke Synapse Handlers
Iterator<SynapseHandler> iterator = smc.getEnvironment().getSynapseHandlers().iterator();
while (iterator.hasNext()) {
SynapseHandler handler = iterator.next();
if (!handler.handleResponseOutFlow(smc)) {
return;
}
}
doSOAPFormatConversion(smc);
// isServerSide should always be true because we are sending the response back to the client
messageContext.setServerSide(true);
// handles concurrent throttling based on the messagecontext.
handleConcurrentThrottleCount(smc);
// If the request arrives through an inbound endpoint
if (smc.getProperty(SynapseConstants.IS_INBOUND) != null && (Boolean) smc.getProperty(SynapseConstants.IS_INBOUND)) {
if (smc.getProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER) != null) {
InboundResponseSender inboundResponseSender = (InboundResponseSender) smc.getProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER);
inboundResponseSender.sendBack(smc);
} else {
String msg = "Inbound Response Sender not found -" + " Inbound Endpoint may not support sending a response back";
log.error(msg);
throw new SynapseException(msg);
}
} else {
// If the request arrives through a conventional transport listener
AxisEngine.send(messageContext);
}
} catch (AxisFault e) {
handleException(getResponseMessage(messageContext), e, smc);
}
}
Aggregations