soapHeader.addNamespaceDeclaration(ADDR.getNamespacePrefix(), ADDR.getNamespaceURI());
// Write wsa:To
if (getTo() != null)
{
SOAPElement element = soapHeader.addChildElement(new NameImpl(ADDR.getToQName()));
element.addTextNode(getTo().getURI().toString());
}
// Write wsa:From
if (getFrom() != null)
{
EndpointReferenceImpl epr = (EndpointReferenceImpl)getFrom();
epr.setRootQName(ADDR.getFromQName());
SOAPElement soapElement = factory.createElement(epr.toElement());
soapElement.removeNamespaceDeclaration(ADDR.getNamespacePrefix());
soapHeader.addChildElement(soapElement);
}
// Write wsa:ReplyTo
if (getReplyTo() != null)
{
EndpointReferenceImpl epr = (EndpointReferenceImpl)getReplyTo();
epr.setRootQName(ADDR.getReplyToQName());
SOAPElement soapElement = factory.createElement(epr.toElement());
soapElement.removeNamespaceDeclaration(ADDR.getNamespacePrefix());
soapHeader.addChildElement(soapElement);
}
// Write wsa:FaultTo
if (getFaultTo() != null)
{
EndpointReferenceImpl epr = (EndpointReferenceImpl)getFaultTo();
epr.setRootQName(ADDR.getFaultToQName());
SOAPElement soapElement = factory.createElement(epr.toElement());
soapElement.removeNamespaceDeclaration(ADDR.getNamespacePrefix());
soapHeader.addChildElement(soapElement);
}
appendRequiredHeader(soapHeader, ADDR.getActionQName(), getAction());
// Write wsa:MessageID
if( (getReplyTo()!=null || getFaultTo()!=null) && null==getMessageID())
{
throw new AddressingException("Required addressing header missing:" + ADDR.getMessageIDQName());
}
else if (getMessageID() != null)
{
SOAPElement wsaMessageId = soapHeader.addChildElement(new NameImpl(ADDR.getMessageIDQName()));
wsaMessageId.addTextNode(getMessageID().getURI().toString());
}
// Write wsa:RelatesTo
if (getRelatesTo() != null)
{
for (Relationship rel : getRelatesTo())
{
SOAPElement wsaRelatesTo = soapHeader.addChildElement(new NameImpl(ADDR.getRelatesToQName()));
if (rel.getType() != null)
{
wsaRelatesTo.setAttribute(ADDR.getRelationshipTypeName(), getPrefixedName(rel.getType()));
}
wsaRelatesTo.addTextNode(rel.getID().toString());
}
}
// Write wsa:ReferenceParameters
ReferenceParameters refParams = getReferenceParameters();
if (refParams.getElements().size() > 0 || refParams.getAttributes().size() > 0)
{
SOAPElement wsaRefParams = soapHeader.addChildElement(new NameImpl(ADDR.getReferenceParametersQName()));
appendAttributes(wsaRefParams, refParams.getAttributes());
appendElements(wsaRefParams, refParams.getElements());
}
appendElements(soapHeader, getElements());