// Check if this is a duplicate message
Sequence sequence = (Sequence) rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
String sequenceId = sequence.getIdentifier().getIdentifier();
long msgNo = sequence.getMessageNumber().getMessageNumber();
StorageManager storageManager =
SandeshaUtil.getSandeshaStorageManager(rmMsgCtx.getConfigurationContext(),
rmMsgCtx.getConfigurationContext().getAxisConfiguration());
Transaction transaction = null;
try {
transaction = storageManager.getTransaction();
// Check that both the Sequence header and message body have been secured properly
RMDBeanMgr mgr = storageManager.getRMDBeanMgr();
RMDBean bean = mgr.retrieve(sequenceId);
if(bean != null && bean.getSecurityTokenData() != null) {
SecurityManager secManager = SandeshaUtil.getSecurityManager(rmMsgCtx.getConfigurationContext());
QName seqName = new QName(rmMsgCtx.getRMNamespaceValue(), Sandesha2Constants.WSRM_COMMON.SEQUENCE);
SOAPEnvelope envelope = rmMsgCtx.getSOAPEnvelope();
OMElement body = envelope.getBody();
OMElement seqHeader = envelope.getHeader().getFirstChildWithName(seqName);
SecurityToken token = secManager.recoverSecurityToken(bean.getSecurityTokenData());
secManager.checkProofOfPossession(token, seqHeader, rmMsgCtx.getMessageContext());
secManager.checkProofOfPossession(token, body, rmMsgCtx.getMessageContext());
}
MessageContext messageContext = rmMsgCtx.getMessageContext();
if (bean != null) {
if (msgNo == 0) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.invalidMsgNumber, Long
.toString(msgNo));
log.debug(message);
throw new SandeshaException(message);
}
// Get the server completed message ranges list
RangeString serverCompletedMessageRanges = bean.getServerCompletedMessages();
// See if the message is in the list of completed ranges
boolean msgNoPresentInList =
serverCompletedMessageRanges.isMessageNumberInRanges(msgNo);
if (!msgNoPresentInList) {
serverCompletedMessageRanges.addRange(new Range(msgNo));
storageManager.getRMDBeanMgr().update(bean);
}
else {
if (log.isDebugEnabled())
log.debug("Detected duplicate message " + msgNo);
boolean isDuplicate = true;
//still allow this msg if we have no corresponding invoker bean for it and we are inOrder
boolean isInOrder =
SandeshaUtil.getDefaultPropertyBean(rmMsgCtx.getConfigurationContext().getAxisConfiguration()).isInOrder();
if(isInOrder)
{
InvokerBean finderBean = new InvokerBean();
finderBean.setMsgNo(msgNo);
finderBean.setSequenceID(sequenceId);
List invokerBeanList = storageManager.getInvokerBeanMgr().find(finderBean);
if((invokerBeanList==null || invokerBeanList.size()==0)
&& bean.getNextMsgNoToProcess()<=msgNo){
isDuplicate = false;
if (log.isDebugEnabled())
log.debug("Allowing completed message on sequence " + sequenceId + ", msgNo " + msgNo);