String sequenceID = null;
CreateSequence createSequence = rmMsgContext.getCreateSequence();
CreateSequenceResponse createSequenceResponse = rmMsgContext.getCreateSequenceResponse();
TerminateSequence terminateSequence = rmMsgContext.getTerminateSequence();
TerminateSequenceResponse terminateSequenceResponse = rmMsgContext.getTerminateSequenceResponse();
Iterator<SequenceAcknowledgement> sequenceAcknowledgementsIter = rmMsgContext.getSequenceAcknowledgements();
Sequence sequence = rmMsgContext.getSequence();
Iterator<AckRequested> ackRequestedIter = rmMsgContext.getAckRequests();
CloseSequence closeSequence = rmMsgContext.getCloseSequence();
CloseSequenceResponse closeSequenceResponse = rmMsgContext.getCloseSequenceResponse();
MakeConnection makeConnection = rmMsgContext.getMakeConnection();
String rmNamespace = null;
if (createSequence != null) {
rmNamespace = createSequence.getNamespaceValue();
}
if (createSequenceResponse != null) {
rmNamespace = createSequenceResponse.getNamespaceValue();
}
if (sequence != null) {
rmNamespace = sequence.getNamespaceValue();
}
//In case of ack messages RM Namespace is decided based on the sequenceId of the last
//sequence Ack. In other words Sandesha2 does not expect to receive two SequenceAcknowledgements
//of different RM specifications in the same incoming message
while(sequenceAcknowledgementsIter.hasNext()){
SequenceAcknowledgement sequenceAck = (SequenceAcknowledgement) sequenceAcknowledgementsIter.next();
rmNamespace = sequenceAck.getNamespaceValue();
}
if (terminateSequence != null) {
rmNamespace = terminateSequence.getNamespaceValue();
}
if (terminateSequenceResponse != null) {
rmNamespace = terminateSequenceResponse.getNamespaceValue();
}
//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();