public void addSOAPEnvelope()

in modules/core/src/main/java/org/apache/sandesha2/RMMsgContext.java [100:179]


	public void addSOAPEnvelope() throws AxisFault {
		int SOAPVersion = Sandesha2Constants.SOAPVersion.v1_1;

		if (!msgContext.isSOAP11())
			SOAPVersion = Sandesha2Constants.SOAPVersion.v1_2;

		if (msgContext.getEnvelope() == null) {
			try {
				msgContext.setEnvelope(SOAPAbstractFactory.getSOAPFactory(
						SOAPVersion).getDefaultEnvelope());
			} catch (AxisFault e) {
				throw new SandeshaException(e.getMessage());
			}
		}

		SOAPEnvelope envelope = msgContext.getEnvelope();
		
		boolean goingToAddHeader = (sequence != null) || (sequenceAcknowledgements.size()>0) || ackRequests.size()>0 || sequenceFault!=null || usesSequenceSTR!=null ||messagePending!=null;
		if(goingToAddHeader){
			// Clean up the SOAPHeader...
			SOAPHeader header = envelope.getHeader();
			if(header == null){
				header = ((SOAPFactory)envelope.getOMFactory()).createSOAPHeader(envelope);
			}else{
				Iterator existingHeaders = header.getChildElements();
				while(existingHeaders.hasNext()){
					OMElement oe = (OMElement)existingHeaders.next();
					if(rmNamespaceValue.equals(oe.getNamespace().getNamespaceURI())){
						existingHeaders.remove();
					}
				}
			}
			
			// Set up any header elements
			if(sequence != null){
				sequence.toHeader(header);
			}
			//there can be more than one sequence ack or ack request in a single message.
			for (Iterator<SequenceAcknowledgement> iter=sequenceAcknowledgements.iterator();iter.hasNext();) {
				SequenceAcknowledgement sequenceAck = (SequenceAcknowledgement) iter.next();
				sequenceAck.toHeader(header);
			}
			for (Iterator<AckRequested> iter=ackRequests.iterator();iter.hasNext();) {
				AckRequested ackReq = (AckRequested) iter.next();
				ackReq.toHeader(header);
			}
			if(sequenceFault != null){
				sequenceFault.toHeader(header);
			}
			if(usesSequenceSTR != null){
				usesSequenceSTR.toHeader(header);
			}
			if(messagePending != null){
				messagePending.toHeader(header);
			}
		}
		
		// Then set up the body element (if appropriate)
		if(createSequence != null){
			createSequence.toSOAPEnvelope(envelope);
		}
		if(createSequenceResponse != null){
			createSequenceResponse.toSOAPEnvelope(envelope);
		}
		if(terminateSequence != null){
			terminateSequence.toSOAPEnvelope(envelope);
		}
		if(terminateSequenceResponse != null){
			terminateSequenceResponse.toSOAPEnvelope(envelope);
		}
		if(closeSequence != null){
			closeSequence.toSOAPEnvelope(envelope);
		}
		if(closeSequenceResponse != null){
			closeSequenceResponse.toSOAPEnvelope(envelope);
		}
		if(makeConnection != null){
			makeConnection.toSOAPEnvelope(envelope);
		}
	}