log.debug("Enter: SequenceManager::setupNewSequence");
String sequenceId = SandeshaUtil.getUUID();
// Generate the new RMD Bean
RMDBean rmdBean = new RMDBean();
EndpointReference to = createSequenceMsg.getTo();
if (to == null) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.toEPRNotValid, null);
log.debug(message);
throw new AxisFault(message);
}
EndpointReference replyTo = createSequenceMsg.getReplyTo();
CreateSequence createSequence = (CreateSequence) createSequenceMsg
.getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);
if (createSequence == null) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.createSeqEntryNotFound);
log.debug(message);
throw new AxisFault(message);
}
EndpointReference acksTo = createSequence.getAcksTo().getEPR();
if (acksTo == null) {
FaultManager.makeCreateSequenceRefusedFault(createSequenceMsg, SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noAcksToPartInCreateSequence), new Exception());
} else if (acksTo.getAddress().equals(AddressingConstants.Final.WSA_NONE_URI)){
FaultManager.makeCreateSequenceRefusedFault(createSequenceMsg, "AcksTo can not be " + AddressingConstants.Final.WSA_NONE_URI, new Exception());
}
MessageContext createSeqContext = createSequenceMsg.getMessageContext();
// If this create is the result of a MakeConnection, then we must have a related
// outbound sequence.
SequenceEntry entry = (SequenceEntry) createSeqContext.getProperty(Sandesha2Constants.MessageContextProperties.MAKECONNECTION_ENTRY);
if(log.isDebugEnabled()) log.debug("This message is associated with sequence entry: " + entry);
if(entry != null && entry.isRmSource()) {
rmdBean.setOutboundInternalSequence(entry.getSequenceId());
}
rmdBean.setServerCompletedMessages(new RangeString());
rmdBean.setReplyToEPR(to.getAddress());
rmdBean.setAcksToEPR(acksTo.getAddress());
// If no replyTo value. Send responses as sync.
if (replyTo != null)
rmdBean.setToEPR(replyTo.getAddress());
// Store the security token alongside the sequence
if(token != null) {
String tokenData = securityManager.getTokenRecoveryData(token);
rmdBean.setSecurityTokenData(tokenData);
}
rmdBean.setSequenceID(sequenceId);
rmdBean.setNextMsgNoToProcess(1);
rmdBean.setToAddress(to.getAddress());
// If this sequence has a 'To' address that is anonymous then we must have got the
// message as a response to a poll. We need to make sure that we keep polling until
// the sequence is closed.
if(to.hasAnonymousAddress()) {
String newKey = SandeshaUtil.getUUID();
rmdBean.setPollingMode(true);
rmdBean.setReferenceMessageKey(newKey);
storageManager.storeMessageContext(newKey, createSeqContext);
}
String messageRMNamespace = createSequence.getNamespaceValue();
String specVersion = null;
if (Sandesha2Constants.SPEC_2005_02.NS_URI.equals(messageRMNamespace)) {
specVersion = Sandesha2Constants.SPEC_VERSIONS.v1_0;
} else if (Sandesha2Constants.SPEC_2007_02.NS_URI.equals(messageRMNamespace)) {
specVersion = Sandesha2Constants.SPEC_VERSIONS.v1_1;
} else {
throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotDecideRMVersion));
}
rmdBean.setRMVersion(specVersion);
rmdBean.setLastActivatedTime(System.currentTimeMillis());
storageManager.getRMDBeanMgr().insert(rmdBean);
// TODO get the SOAP version from the create seq message.