log.debug(message);
throw new SandeshaException(message);
}
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) {
//
// As we have processed the input and prepared the response we can commit the
// transaction now.
if(transaction != null && transaction.isActive()) transaction.commit();
MessageContext outMessage = terminateSequenceResponse.getMessageContext();
EndpointReference toEPR = outMessage.getTo();
AxisEngine engine = new AxisEngine(terminateSeqMsg.getConfigurationContext());
outMessage.setServerSide(true);
try {
engine.send(outMessage);
} catch (AxisFault e) {
if (log.isDebugEnabled())
log.debug("Unable to send terminate sequence response", e);
throw new SandeshaException(
SandeshaMessageHelper.getMessage(SandeshaMessageKeys.couldNotSendTerminateResponse), e);
}
if (toEPR.hasAnonymousAddress()) {
terminateSeqMsg.getOperationContext().setProperty(
org.apache.axis2.Constants.RESPONSE_WRITTEN, "true");
} else {
terminateSeqMsg.getOperationContext().setProperty(
org.apache.axis2.Constants.RESPONSE_WRITTEN, "false");
}
} else {
//if RM 1.0 Anonymous scenario we will be trying to attache the TerminateSequence of the response side
//as the response message.
String outgoingSideInternalSeqId = SandeshaUtil.getOutgoingSideInternalSequenceID(sequenceId);
SenderBean senderFindBean = new SenderBean ();
senderFindBean.setInternalSequenceID(outgoingSideInternalSeqId);
senderFindBean.setMessageType(Sandesha2Constants.MessageTypes.TERMINATE_SEQ);
senderFindBean.setSend(true);
senderFindBean.setReSend(false);
SenderBean outgoingSideTerminateBean = storageManager.getSenderBeanMgr().findUnique(senderFindBean);
if (outgoingSideTerminateBean!=null) {
EndpointReference toEPR = new EndpointReference (outgoingSideTerminateBean.getToAddress());
if (toEPR.hasAnonymousAddress()) {
String messageKey = outgoingSideTerminateBean
.getMessageContextRefKey();
MessageContext message = storageManager
.retrieveMessageContext(messageKey, context);
RMMsgContext rmMessage = MsgInitializer.initializeMessage(message);
// attaching the this outgoing terminate message as the