public static RMDBean setupNewSequence()

in modules/core/src/main/java/org/apache/sandesha2/util/SequenceManager.java [66:164]


	public static RMDBean setupNewSequence(RMMsgContext createSequenceMsg, StorageManager storageManager, SecurityManager securityManager, SecurityToken token)
			throws AxisFault {
		if (log.isDebugEnabled())
			log.debug("Enter: SequenceManager::setupNewSequence");
		
		
		// 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 = createSequenceMsg.getCreateSequence();
		if (createSequence == null) {
			String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.createSeqEntryNotFound);
			log.debug(message);
			throw new AxisFault(message);
		}

		EndpointReference acksTo = createSequence.getAcksTo().getEPR();

		if (acksTo == null) {
			log.error(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.acksToInvalid, ""));
			FaultManager.makeCreateSequenceRefusedFault(createSequenceMsg, SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noAcksToPartInCreateSequence), new Exception(), null);
			return null;
		} else if (acksTo.getAddress().equals(AddressingConstants.Final.WSA_NONE_URI)){
			log.error(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.acksToInvalid, acksTo.getAddress()));
			FaultManager.makeCreateSequenceRefusedFault(createSequenceMsg, "AcksTo can not be " + AddressingConstants.Final.WSA_NONE_URI, new Exception(), null);
			return null;
		}

		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.setReplyToEndpointReference(to);
		rmdBean.setAcksToEndpointReference(acksTo);

		// If no replyTo value. Send responses as sync.
		if (replyTo != null)
			rmdBean.setToEndpointReference(replyTo);

		// Store the security token alongside the sequence
		if(token != null) {
			String tokenData = securityManager.getTokenRecoveryData(token);
			rmdBean.setSecurityTokenData(tokenData);
		}		
		
		rmdBean.setSequenceID(SandeshaUtil.getUUID());
		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.

		if (log.isDebugEnabled())
			log.debug("Exit: SequenceManager::setupNewSequence, " + rmdBean);
		return rmdBean;
	}