in modules/core/src/main/java/org/apache/sandesha2/workers/SenderWorker.java [551:720]
private void checkForSyncResponses(MessageContext msgCtx) {
if (log.isDebugEnabled())
log.debug("Enter: SenderWorker::checkForSyncResponses, " + msgCtx.getEnvelope().getHeader());
try {
// create the responseMessageContext
MessageContext responseMessageContext = msgCtx.getOperationContext().getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
SOAPEnvelope resenvelope = null;
if (responseMessageContext!=null)
resenvelope = responseMessageContext.getEnvelope();
boolean transportInPresent = (msgCtx.getProperty(MessageContext.TRANSPORT_IN) != null);
if (!transportInPresent && (responseMessageContext==null || responseMessageContext.getEnvelope()==null)) {
if(log.isDebugEnabled()) log.debug("Exit: SenderWorker::checkForSyncResponses, no response present");
return;
}
//to find out weather the response was built by me.
boolean syncResponseBuilt = false;
if (responseMessageContext==null || responseMessageContext.getEnvelope()==null) {
if (responseMessageContext==null)
responseMessageContext = new MessageContext();
OperationContext requestMsgOpCtx = msgCtx.getOperationContext();
//copy any necessary properties
SandeshaUtil.copyConfiguredProperties(msgCtx, responseMessageContext);
// If the request operation context is Out-In then it's reasonable to assume
// that the response is related to the request.
//int mep = requestMsgOpCtx.getAxisOperation().getAxisSpecificMEPConstant();
//if(mep == WSDLConstants.MEP_CONSTANT_OUT_IN) {
//this line causes issues in addressing
//responseMessageContext.setOperationContext(requestMsgOpCtx);
//}
responseMessageContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, requestMsgOpCtx
.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING));
responseMessageContext.setProperty(Constants.Configuration.CONTENT_TYPE, requestMsgOpCtx
.getProperty(Constants.Configuration.CONTENT_TYPE));
responseMessageContext.setProperty(HTTPConstants.MTOM_RECEIVED_CONTENT_TYPE, requestMsgOpCtx
.getProperty(HTTPConstants.MTOM_RECEIVED_CONTENT_TYPE));
//If the response MsgCtx was not available Axis2 would hv put the transport info into a
//HashMap, getting the data from it.
HashMap transportInfoMap = (HashMap) msgCtx.getProperty(Constants.Configuration.TRANSPORT_INFO_MAP);
if (transportInfoMap != null) {
responseMessageContext.setProperty(Constants.Configuration.CONTENT_TYPE,
transportInfoMap.get(Constants.Configuration.CONTENT_TYPE));
responseMessageContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
transportInfoMap.get(Constants.Configuration.CHARACTER_SET_ENCODING));
}
responseMessageContext.setConfigurationContext(msgCtx.getConfigurationContext());
responseMessageContext.setTransportIn(msgCtx.getTransportIn());
responseMessageContext.setTransportOut(msgCtx.getTransportOut());
responseMessageContext.setProperty(MessageContext.TRANSPORT_IN, msgCtx
.getProperty(MessageContext.TRANSPORT_IN));
responseMessageContext.setServiceGroupContext(msgCtx.getServiceGroupContext());
responseMessageContext.setProperty(Sandesha2Constants.MessageContextProperties.MAKECONNECTION_ENTRY,
msgCtx.getProperty(Sandesha2Constants.MessageContextProperties.MAKECONNECTION_ENTRY));
// If request is REST we assume the responseMessageContext is REST,
// so set the variable
responseMessageContext.setDoingREST(msgCtx.isDoingREST());
resenvelope = responseMessageContext.getEnvelope();
try {
// MessageContext is modified in TransportUtils.createSOAPMessage(). It might be used by axis.engine or handler.
// To catch the modification and pass it to engine or handler, resenvelope is created by responseMessageContext.
if (resenvelope==null) {
//We try to build the response out of the transport stream.
resenvelope = TransportUtils.createSOAPMessage(responseMessageContext, true);
responseMessageContext.setEnvelope(resenvelope);
syncResponseBuilt = true;
}
} catch (AxisFault e) {
//Cannot find a valid SOAP envelope.
if (log.isDebugEnabled() ) {
log.debug (SandeshaMessageHelper
.getMessage(SandeshaMessageKeys.soapEnvNotSet));
log.debug ("Caught exception", e);
}
return;
}
//we will not be setting the operation context here since this msgs may not be an application reply.
//we let other dispatchers find it.
int messageType = MsgInitializer.initializeMessage(responseMessageContext).getMessageType();
RMMsgContext responseRMMessage = MsgInitializer.initializeMessage(responseMessageContext);
int responseMessageType = responseRMMessage.getMessageType();
if(log.isDebugEnabled()) log.debug("inboundMsgType" + responseMessageType + "outgoing message type " + messageType);
//Setting the AxisService object
responseMessageContext.setAxisService(msgCtx.getAxisService());
//If addressing is disabled we will be adding this message simply as the application response of the request message.
Boolean addressingDisabled = (Boolean) msgCtx.getProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES);
if (addressingDisabled!=null && Boolean.TRUE.equals(addressingDisabled)) {
// If the AxisOperation object doesn't have a message receiver, it means that this was
// an out only op where we have added an ACK to the response. Set the requestMsgOpCtx to
// be the RMIn
OperationContext responseMsgOpCtx = requestMsgOpCtx;
if (requestMsgOpCtx.getAxisOperation().getMessageReceiver() == null) {
// Generate a new RM In Only operation
ServiceContext serviceCtx = msgCtx.getServiceContext();
AxisOperation op = msgCtx.getAxisService().getOperation(Sandesha2Constants.RM_IN_ONLY_OPERATION);
responseMsgOpCtx = OperationContextFactory.createOperationContext (op.getAxisSpecificMEPConstant(), op, serviceCtx);
}
responseMessageContext.setOperationContext(responseMsgOpCtx);
}
AxisOperation operation = msgCtx.getAxisOperation();
if (operation!=null && responseMessageContext.getAxisMessage()==null
&& !(operation instanceof OutOnlyAxisOperation))
responseMessageContext.setAxisMessage(operation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
if (responseRMMessage.getMessageType()==Sandesha2Constants.MessageTypes.ACK) {
responseMessageContext.setAxisOperation(SpecSpecificConstants.getWSRMOperation
(Sandesha2Constants.MessageTypes.ACK, responseRMMessage.getRMSpecVersion(), responseMessageContext.getAxisService()));
responseMessageContext.setOperationContext(null);
}
}
//if the syncResponseWas not built here and the client was not expecting a sync response. We will not try to execute
//here. Doing so will cause a double invocation for a async message.
if (msgCtx.getOptions().isUseSeparateListener()==true && !syncResponseBuilt) {
// Since the client is not expecting a sync response, it will not (necessarily) call cleanup.
// If we discard the response, then we need to clean up here.
msgCtx.getTransportOut().getSender().cleanup(msgCtx);
return;
}
//setting the message as serverSide will let it go through the MessageReceiver (may be callback MR).
responseMessageContext.setServerSide(true);
if (responseMessageContext.getSoapAction()==null) {
//if there is no SOAP action in the response message, Axis2 will wrongly identify it as a REST message
//This happens because we set serverSide to True in a previous step.
//So we have to add a empty SOAPAction here.
responseMessageContext.setSoapAction("");
}
if (resenvelope!=null) {
//Drive the response msg through the engine
//disable addressing validation - this is an inbound response msg so we do not want addressing to validate replyTo
//etc in the same way as it would for inbound request messages
if (log.isDebugEnabled())
log.debug("SenderWorker::disable addressing inbound checks, driving response through axis engine " + responseMessageContext);
responseMessageContext.setProperty(AddressingConstants.ADDR_VALIDATE_INVOCATION_PATTERN, Boolean.FALSE);
InvocationResponse response = AxisEngine.receive(responseMessageContext);
}
} catch (Exception e) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noValidSyncResponse);
if (log.isDebugEnabled())
log.debug(message, e);
}
if (log.isDebugEnabled())
log.debug("Exit: SenderWorker::checkForSyncResponses");
}