}
//In case of ack request messages RM Namespace is decided based on the sequenceId of the last
//ack request.
while(ackRequestedIter.hasNext()){
AckRequested ackRequest = (AckRequested) ackRequestedIter.next();
rmNamespace = ackRequest.getNamespaceValue();
}
if (closeSequence != null) {
rmNamespace = closeSequence.getNamespaceValue();
}
if (closeSequenceResponse != null) {
rmNamespace = closeSequenceResponse.getNamespaceValue();
}
if (makeConnection != null) {
if (Sandesha2Constants.SPEC_2007_02.MC_NS_URI.equals(makeConnection.getNamespaceValue()))
rmNamespace = Sandesha2Constants.SPEC_2007_02.NS_URI;
}
if (rmMsgContext.getMessagePending() != null) {
//MessagePending only supported in 1.1 namespace... no need to check the namespace value
rmNamespace = Sandesha2Constants.SPEC_2007_02.NS_URI;
}
if (rmNamespace!=null)
rmMsgContext.setRMNamespaceValue(rmNamespace);
sequenceAcknowledgementsIter = rmMsgContext.getSequenceAcknowledgements();
ackRequestedIter = rmMsgContext.getAckRequests();
// Setting message type.
if (createSequence != null) {
rmMsgContext.setMessageType(Sandesha2Constants.MessageTypes.CREATE_SEQ);
} else if (createSequenceResponse != null) {
rmMsgContext.setMessageType(Sandesha2Constants.MessageTypes.CREATE_SEQ_RESPONSE);
sequenceID = createSequenceResponse.getIdentifier().getIdentifier();
} else if (terminateSequence != null) {
rmMsgContext.setMessageType(Sandesha2Constants.MessageTypes.TERMINATE_SEQ);
sequenceID = terminateSequence.getIdentifier().getIdentifier();
} else if (terminateSequenceResponse != null) {
rmMsgContext.setMessageType(Sandesha2Constants.MessageTypes.TERMINATE_SEQ_RESPONSE);
sequenceID = terminateSequenceResponse.getIdentifier().getIdentifier();
} else if (sequence != null) {
Sequence seq = rmMsgContext.getSequence();
boolean lastMessage = seq.getLastMessage();
SOAPEnvelope envelope = rmMsgContext.getSOAPEnvelope();
if (lastMessage && envelope.getBody().getFirstOMChild()==null) {
//the message is an empty body last message
rmMsgContext.setMessageType(Sandesha2Constants.MessageTypes.LAST_MESSAGE);
}else
rmMsgContext.setMessageType(Sandesha2Constants.MessageTypes.APPLICATION);
sequenceID = sequence.getIdentifier().getIdentifier();
} else if (makeConnection != null){
rmMsgContext.setMessageType(Sandesha2Constants.MessageTypes.MAKE_CONNECTION_MSG);
if (makeConnection.getIdentifier()!=null) {
sequenceID = makeConnection.getIdentifier().getIdentifier();
} else if (makeConnection.getAddress()!=null){
//TODO get sequenceId based on the anonymous address.
}
} else if (ackRequestedIter.hasNext()) {
rmMsgContext.setMessageType(Sandesha2Constants.MessageTypes.ACK_REQUEST);
AckRequested ackRequest = (AckRequested) ackRequestedIter.next();
//if there is only on sequenceAck, sequenceId will be set. Otherwise it will not be.
if (!ackRequestedIter.hasNext())
sequenceID = ackRequest.getIdentifier().getIdentifier();
} else if (closeSequence != null) {
rmMsgContext.setMessageType(Sandesha2Constants.MessageTypes.CLOSE_SEQUENCE);
sequenceID = closeSequence.getIdentifier().getIdentifier();
} else if (closeSequenceResponse != null) {
rmMsgContext.setMessageType(Sandesha2Constants.MessageTypes.CLOSE_SEQUENCE_RESPONSE);