StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configCtx, configCtx
.getAxisConfiguration());
// Processing the create sequence response.
CreateSequenceResponse createSeqResponsePart = (CreateSequenceResponse) createSeqResponseRMMsgCtx
.getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ_RESPONSE);
if (createSeqResponsePart == null) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noCreateSeqResponse);
log.debug(message);
throw new SandeshaException(message);
}
String newOutSequenceId = createSeqResponsePart.getIdentifier().getIdentifier();
if (newOutSequenceId == null) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.newSeqIdIsNull);
log.debug(message);
throw new SandeshaException(message);
}
RelatesTo relatesTo = createSeqResponseRMMsgCtx.getMessageContext().getRelatesTo();
if (relatesTo == null) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.relatesToNotAvailable);
log.error(message);
throw new SandeshaException(message);
}
String createSeqMsgId = relatesTo.getValue();
SenderBeanMgr senderBeanMgr = storageManager.getSenderBeanMgr();
RMSBeanMgr rmsBeanMgr = storageManager.getRMSBeanMgr();
RMSBean rmsBean = rmsBeanMgr.retrieve(createSeqMsgId);
if (rmsBean == null) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.createSeqEntryNotFound);
log.debug(message);
throw new SandeshaException(message);
}
// Check that the create sequence response message proves possession of the correct token
String tokenData = rmsBean.getSecurityTokenData();
if(tokenData != null) {
SecurityManager secManager = SandeshaUtil.getSecurityManager(configCtx);
MessageContext crtSeqResponseCtx = createSeqResponseRMMsgCtx.getMessageContext();
OMElement body = crtSeqResponseCtx.getEnvelope().getBody();
SecurityToken token = secManager.recoverSecurityToken(tokenData);
secManager.checkProofOfPossession(token, body, crtSeqResponseCtx);
}
String internalSequenceId = rmsBean.getInternalSequenceID();
if (internalSequenceId == null || "".equals(internalSequenceId)) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.tempSeqIdNotSet);
log.debug(message);
throw new SandeshaException(message);
}
createSeqResponseRMMsgCtx.setProperty(Sandesha2Constants.MessageContextProperties.INTERNAL_SEQUENCE_ID,internalSequenceId);
String sequencePropertyKey = SandeshaUtil.getSequencePropertyKey(createSeqResponseRMMsgCtx);
rmsBean.setSequenceID(newOutSequenceId);
rmsBeanMgr.update(rmsBean);
SenderBean createSequenceSenderBean = senderBeanMgr.retrieve(createSeqMsgId);
if (createSequenceSenderBean == null)
throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.createSeqEntryNotFound));
// deleting the create sequence entry.
senderBeanMgr.delete(createSeqMsgId);
// storing new out sequence id
SequencePropertyBeanMgr sequencePropMgr = storageManager.getSequencePropertyBeanMgr();
SequencePropertyBean outSequenceBean = new SequencePropertyBean(sequencePropertyKey,
Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID, newOutSequenceId);
SequencePropertyBean internalSequenceBean = new SequencePropertyBean(newOutSequenceId,
Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID, sequencePropertyKey);
sequencePropMgr.insert(outSequenceBean);
sequencePropMgr.insert(internalSequenceBean);
// Store the security token under the new sequence id
if(tokenData != null) {
SequencePropertyBean newToken = new SequencePropertyBean(newOutSequenceId,
Sandesha2Constants.SequenceProperties.SECURITY_TOKEN, tokenData);
sequencePropMgr.insert(newToken);
}
// processing for accept (offer has been sent)
Accept accept = createSeqResponsePart.getAccept();
if (accept != null) {
// Find offered sequence from internal sequence id.
SequencePropertyBean offeredSequenceBean = sequencePropMgr.retrieve(sequencePropertyKey,
Sandesha2Constants.SequenceProperties.OFFERED_SEQUENCE);