log.debug("Enter: ApplicationMsgProcessor::processResponseMessage, " + internalSequenceId);
MessageContext msg = rmMsg.getMessageContext();
SequencePropertyBeanMgr sequencePropertyMgr = storageManager.getSequencePropertyBeanMgr();
SenderBeanMgr senderBeanMgr = storageManager.getSenderBeanMgr();
// again - looks weird in the client side - but consistent
SequencePropertyBean outSequenceBean = sequencePropertyMgr.retrieve(internalSequenceId,
Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID);
String rmVersion = SandeshaUtil.getRMVersion(internalSequenceId, storageManager);
if (rmVersion == null)
throw new SandeshaException(SandeshaMessageHelper.getMessage(
SandeshaMessageKeys.specVersionPropertyNotAvailable, internalSequenceId));
String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(rmVersion);
Sequence sequence = new Sequence(rmNamespaceValue);
MessageNumber msgNumber = new MessageNumber(rmNamespaceValue);
msgNumber.setMessageNumber(messageNumber);
sequence.setMessageNumber(msgNumber);
// setting last message
if (msg.isServerSide()) {
MessageContext requestMsg = null;
requestMsg = msg.getOperationContext()
.getMessageContext(OperationContextFactory.MESSAGE_LABEL_IN_VALUE);
RMMsgContext reqRMMsgCtx = MsgInitializer.initializeMessage(requestMsg);
Sequence requestSequence = (Sequence) reqRMMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
if (requestSequence == null) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.requestSeqIsNull);
log.debug(message);
throw new SandeshaException(message);
}
if (requestSequence.getLastMessage() != null) {
sequence.setLastMessage(new LastMessage(rmNamespaceValue));
}
} else {
// client side
OperationContext operationContext = msg.getOperationContext();
if (operationContext != null) {
Object obj = msg.getProperty(SandeshaClientConstants.LAST_MESSAGE);
if (obj != null && "true".equals(obj)) {
SequencePropertyBean specVersionBean = sequencePropertyMgr.retrieve(internalSequenceId,
Sandesha2Constants.SequenceProperties.RM_SPEC_VERSION);
if (specVersionBean == null)
throw new SandeshaException(SandeshaMessageHelper
.getMessage(SandeshaMessageKeys.specVersionNotSet));
String specVersion = specVersionBean.getValue();
if (SpecSpecificConstants.isLastMessageIndicatorRequired(specVersion))
sequence.setLastMessage(new LastMessage(rmNamespaceValue));
}
}
}
AckRequested ackRequested = null;
boolean addAckRequested = false;
// if (!lastMessage)
// addAckRequested = true; //TODO decide the policy to add the
// ackRequested tag
// setting the Sequnece id.
// Set send = true/false depending on the availability of the out
// sequence id.
String identifierStr = null;
if (outSequenceBean == null || outSequenceBean.getValue() == null) {
identifierStr = Sandesha2Constants.TEMP_SEQUENCE_ID;
} else {
identifierStr = outSequenceBean.getValue();
}
Identifier id1 = new Identifier(rmNamespaceValue);
id1.setIndentifer(identifierStr);
sequence.setIdentifier(id1);
rmMsg.setMessagePart(Sandesha2Constants.MessageParts.SEQUENCE, sequence);
if (addAckRequested) {
ackRequested = new AckRequested(rmNamespaceValue);
Identifier id2 = new Identifier(rmNamespaceValue);
id2.setIndentifer(identifierStr);
ackRequested.setIdentifier(id2);
rmMsg.setMessagePart(Sandesha2Constants.MessageParts.ACK_REQUEST, ackRequested);
}
rmMsg.addSOAPEnvelope();
// Retransmitter bean entry for the application message
SenderBean appMsgEntry = new SenderBean();
appMsgEntry.setMessageContextRefKey(storageKey);
appMsgEntry.setTimeToSend(System.currentTimeMillis());
appMsgEntry.setMessageID(rmMsg.getMessageId());
appMsgEntry.setMessageNumber(messageNumber);
appMsgEntry.setMessageType(Sandesha2Constants.MessageTypes.APPLICATION);
if (outSequenceBean == null || outSequenceBean.getValue() == null) {
appMsgEntry.setSend(false);
} else {
appMsgEntry.setSend(true);
// Send will be set to true at the sender.
msg.setProperty(Sandesha2Constants.SET_SEND_TO_TRUE, Sandesha2Constants.VALUE_TRUE);
}
EndpointReference to = rmMsg.getTo();
if (to!=null)
appMsgEntry.setToAddress(to.getAddress());
appMsgEntry.setInternalSequenceID(internalSequenceId);
storageManager.storeMessageContext(storageKey, msg);
msg.setProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING, Sandesha2Constants.VALUE_FALSE);
senderBeanMgr.insert(appMsgEntry);
// increasing the current handler index, so that the message will not be
// going throught the SandeshaOutHandler again.
msg.setCurrentHandlerIndex(msg.getCurrentHandlerIndex() + 1);