ConfigurationContext context = terminateSeqMsg.getConfigurationContext();
StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(context,context.getAxisConfiguration());
// Check that the sender of this TerminateSequence holds the correct token
RMDBean rmdBean = SandeshaUtil.getRMDBeanFromSequenceId(storageManager, sequenceId);
if(rmdBean != null && rmdBean.getSecurityTokenData() != null) {
SecurityManager secManager = SandeshaUtil.getSecurityManager(context);
OMElement body = terminateSeqRMMsg.getSOAPEnvelope().getBody();
SecurityToken token = secManager.recoverSecurityToken(rmdBean.getSecurityTokenData());
secManager.checkProofOfPossession(token, body, terminateSeqRMMsg.getMessageContext());
}
if (FaultManager.checkForUnknownSequence(terminateSeqRMMsg, sequenceId, storageManager, false)) {
if (log.isDebugEnabled())
log.debug("Exit: TerminateSeqMsgProcessor::processInMessage, unknown sequence");
return false;
}
// add the terminate sequence response if required.
RMMsgContext terminateSequenceResponse = null;
if (SpecSpecificConstants.isTerminateSequenceResponseRequired(terminateSeqRMMsg.getRMSpecVersion()))
terminateSequenceResponse = getTerminateSequenceResponse(terminateSeqRMMsg, rmdBean, sequenceId, storageManager);
setUpHighestMsgNumbers(context, storageManager, sequenceId, terminateSeqRMMsg);
boolean inOrderInvocation = SandeshaUtil.getDefaultPropertyBean(context.getAxisConfiguration()).isInOrder();
//if the invocation is inOrder and if this is RM 1.1 there is a posibility of all the messages having eleady being invoked.
//In this case we should do the full termination.
boolean doFullTermination = false;
if (inOrderInvocation) {
long highestMsgNo = rmdBean.getHighestInMessageNumber();
long nextMsgToProcess = rmdBean.getNextMsgNoToProcess();
if (nextMsgToProcess>highestMsgNo) {
//all the messages have been invoked, u can do the full termination
doFullTermination = true;
}
} else {
//for not-inorder case, always do the full termination.
doFullTermination = true;
}
if (doFullTermination) {
TerminateManager.cleanReceivingSideAfterInvocation(sequenceId, storageManager);
TerminateManager.cleanReceivingSideOnTerminateMessage(context, sequenceId, storageManager);
} else
TerminateManager.cleanReceivingSideOnTerminateMessage(context, sequenceId, storageManager);
rmdBean.setTerminated(true);
rmdBean.setLastActivatedTime(System.currentTimeMillis());
storageManager.getRMDBeanMgr().update(rmdBean);
//sending the terminate sequence response
if (terminateSequenceResponse != null) {