createSeqRMMessage.setFlow(MessageContext.OUT_FLOW);
CreateSequence createSequencePart = (CreateSequence) createSeqRMMessage
.getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);
SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropertyBeanMgr();
RMSBeanMgr rmsBeanMgr = storageManager.getRMSBeanMgr();
SenderBeanMgr senderBeanMgr = storageManager.getSenderBeanMgr();
SequenceOffer offer = createSequencePart.getSequenceOffer();
if (offer != null) {
String offeredSequenceId = offer.getIdentifer().getIdentifier();
SequencePropertyBean offeredSequenceBean = new SequencePropertyBean();
offeredSequenceBean.setName(Sandesha2Constants.SequenceProperties.OFFERED_SEQUENCE);
offeredSequenceBean.setSequencePropertyKey(sequencePropertyKey);
offeredSequenceBean.setValue(offeredSequenceId);
seqPropMgr.insert(offeredSequenceBean);
}
MessageContext createSeqMsg = createSeqRMMessage.getMessageContext();
createSeqMsg.setRelationships(null); // create seq msg does not
// relateTo anything
String createSequenceMessageStoreKey = SandeshaUtil.getUUID(); // the key taht will be used to store
//the create sequence message.
RMSBean rmsBean = new RMSBean();
rmsBean.setInternalSequenceID(internalSequenceId);
rmsBean.setCreateSeqMsgID(createSeqMsg.getMessageID());
rmsBean.setCreateSequenceMsgStoreKey(createSequenceMessageStoreKey);
//cloning the message and storing it as a reference.
MessageContext clonedMessage = SandeshaUtil.cloneMessageContext(createSeqMsg);
String clonedMsgStoreKey = SandeshaUtil.getUUID();
storageManager.storeMessageContext(clonedMsgStoreKey, clonedMessage);
rmsBean.setReferenceMessageStoreKey(clonedMsgStoreKey);
//TODO set the replyTo of CreateSeq (and others) to Anymomous if Application Msgs hv it as Anonymous.
// //checking weather the sequence is in polling mode.
// boolean pollingMode = false;
// EndpointReference replyTo = applicationRMMsg.getReplyTo();
// if (replyTo!=null && SandeshaUtil.isWSRMAnonymousReplyTo(replyTo.getAddress()))
// pollingMode = true;
// else if (replyTo!=null && offer!=null &&
// (AddressingConstants.Final.WSA_ANONYMOUS_URL.equals(replyTo.getAddress()) ||
// AddressingConstants.Submission.WSA_ANONYMOUS_URL.equals(replyTo.getAddress())))
// pollingMode = true;
//
// createSeqBean.setPollingMode(pollingMode);
// //if PollingMode is true, starting the pollingmanager.
// if (pollingMode)
// SandeshaUtil.startPollingManager(configCtx);
SecurityToken token = (SecurityToken) createSeqRMMessage.getProperty(Sandesha2Constants.SequenceProperties.SECURITY_TOKEN);
if(token != null) {
SecurityManager secManager = SandeshaUtil.getSecurityManager(configCtx);
rmsBean.setSecurityTokenData(secManager.getTokenRecoveryData(token));
// If we are using token based security, and the 1.1 spec level, then we
// should introduce a UsesSequenceSTR header into the message.
if(createSequencePart.getNamespaceValue().equals(Sandesha2Constants.SPEC_2006_08.NS_URI)) {
UsesSequenceSTR header = new UsesSequenceSTR(null, Sandesha2Constants.SPEC_2006_08.NS_URI);
header.toSOAPEnvelope(createSeqMsg.getEnvelope());
}
}
rmsBeanMgr.insert(rmsBean);
String addressingNamespaceURI = SandeshaUtil.getSequenceProperty(sequencePropertyKey,
Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE, storageManager);
String anonymousURI = SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespaceURI);