private static SOAPEnvelope configureTerminateSequence()

in modules/core/src/main/java/org/apache/sandesha2/client/SandeshaClient.java [1126:1209]


	private static SOAPEnvelope configureTerminateSequence(Options options, ConfigurationContext configurationContext)
			throws SandeshaException {

		if (options == null)
			throw new SandeshaException(SandeshaMessageHelper.getMessage(
					SandeshaMessageKeys.optionsObjectNotSet));

		EndpointReference epr = options.getTo();
		if (epr == null)
			throw new SandeshaException(SandeshaMessageHelper.getMessage(
					SandeshaMessageKeys.toEPRNotValid, null));

		//first see if the cliet has told us which sequence to terminate
		String internalSequenceID = 
			(String)options.getProperty(SandeshaClientConstants.INTERNAL_SEQUENCE_ID);
		
		if(internalSequenceID==null){
			//lookup the internal seq id based on to EPR and sequenceKey
			String to = epr.getAddress();
			String sequenceKey = (String) options.getProperty(SandeshaClientConstants.SEQUENCE_KEY);
			internalSequenceID = SandeshaUtil.getInternalSequenceID(to, sequenceKey);
		}
		
		StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext,configurationContext.getAxisConfiguration());

		// Get a transaction to obtain sequence information
		Transaction transaction = null;
		String sequenceID = null;
		
		try
		{
			transaction = storageManager.getTransaction();
			sequenceID = SandeshaUtil.getSequenceIDFromInternalSequenceID(internalSequenceID, storageManager);
		}
		finally
		{
			// Commit the tran whatever happened
			if(transaction != null) transaction.commit();
		}
		
		if (sequenceID == null)
			sequenceID = Sandesha2Constants.TEMP_SEQUENCE_ID;	
		
		String rmSpecVersion = (String) options.getProperty(SandeshaClientConstants.RM_SPEC_VERSION);
		if (rmSpecVersion == null)
			rmSpecVersion = SpecSpecificConstants.getDefaultSpecVersion();

		options.setAction(SpecSpecificConstants.getTerminateSequenceAction(rmSpecVersion));
		SOAPEnvelope dummyEnvelope = null;
		SOAPFactory factory = null;
		String soapNamespaceURI = options.getSoapVersionURI();
		if (soapNamespaceURI == null) 
			soapNamespaceURI = getSOAPNamespaceURI(storageManager, internalSequenceID);
		if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapNamespaceURI)) {
			factory = OMAbstractFactory.getSOAP12Factory();
			dummyEnvelope = factory.getDefaultEnvelope();
		} else {
			factory = OMAbstractFactory.getSOAP11Factory();
			dummyEnvelope = factory.getDefaultEnvelope();
		}

		String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(rmSpecVersion);
		TerminateSequence terminateSequence = new TerminateSequence(rmNamespaceValue);
		Identifier identifier = new Identifier(rmNamespaceValue);
		identifier.setIndentifer(sequenceID);
		terminateSequence.setIdentifier(identifier);
		if(TerminateSequence.isLastMsgNumberRequired(rmNamespaceValue)){
			try
			{
				transaction = storageManager.getTransaction();
				LastMessageNumber lastMessageNumber = new LastMessageNumber(rmNamespaceValue);
				lastMessageNumber.setMessageNumber(SandeshaUtil.getLastMessageNumber(internalSequenceID, storageManager));
				terminateSequence.setLastMessageNumber(lastMessageNumber);
			}
			finally
			{
				// Commit the tran whatever happened
				if(transaction != null) transaction.commit();
			}
		}
		terminateSequence.toSOAPEnvelope(dummyEnvelope);

		return dummyEnvelope;
	}