try
{
SOAPHeader soapHeader = message.getSOAPHeader();
SOAPAddressingBuilder builder = new SOAPAddressingBuilderImpl();
AddressingConstants ADDR = builder.newAddressingConstants();
registerNamespaces(ADDR, soapHeader);
// wsa:To
// This OPTIONAL element provides the value for the [destination] property.
// If this element is NOT present then the value of the [destination]
// property is "http://www.w3.org/2005/08/addressing/anonymous".
String to = getOptionalHeaderContent(soapHeader, ADDR.getToQName());
if(to!=null)
setTo(builder.newURI(to));
// Read wsa:From
// This OPTIONAL element (of type wsa:EndpointReferenceType) provides the value for the [source endpoint] property.
Element wsaFrom = DOMUtils.getFirstChildElement(soapHeader, ADDR.getFromQName());
if (wsaFrom != null)
{
EndpointReferenceImpl ref = new EndpointReferenceImpl(wsaFrom);
setFrom(ref);
}
// Read wsa:ReplyTo
// This OPTIONAL element provides the value for the [reply endpoint] property.
// If this element is NOT present then the value of the [address] property of the [reply endpoint]
// EPR is "http://www.w3.org/2005/08/addressing/anonymous".
Element wsaReplyTo = DOMUtils.getFirstChildElement(soapHeader, ADDR.getReplyToQName());
if (wsaReplyTo != null)
{
EndpointReferenceImpl ref = new EndpointReferenceImpl(wsaReplyTo);
setReplyTo(ref);
}
// Read wsa:FaultTo
// This OPTIONAL element (of type wsa:EndpointReferenceType) provides the value for the [fault endpoint] property.
// If this element is present, wsa:MessageID MUST be present.
Element wsaFaultTo = DOMUtils.getFirstChildElement(soapHeader, ADDR.getFaultToQName());
if (wsaFaultTo != null)
{
EndpointReferenceImpl ref = new EndpointReferenceImpl(wsaFaultTo);
setFaultTo(ref);
}
// wsa:Action
// This REQUIRED element of type xs:anyURI conveys the [action] property.
// The [children] of this element convey the value of this property.
if (message.getProperty("isRequired") != null && (Boolean)message.getProperty("isRequired"))
{
//check the action header only if the required value is true
String action = getRequiredHeaderContent(soapHeader, ADDR.getActionQName());
setAction(builder.newURI(action));
}
else
{
String action = getOptionalHeaderContent(soapHeader, ADDR.getActionQName());
if (action != null) setAction(builder.newURI(action));
}
// Read wsa:MessageID
// This OPTIONAL element (whose content is of type xs:anyURI) conveys the [message id] property.
String messageID = getOptionalHeaderContent(soapHeader, ADDR.getMessageIDQName());
if(messageID!=null) setMessageID(builder.newURI(messageID));
// Read wsa:RelatesTo
// This OPTIONAL attribute conveys the relationship type as an IRI.
// When absent, the implied value of this attribute is "http://www.w3.org/2005/08/addressing/reply".
Iterator itRelatesTo = DOMUtils.getChildElements(soapHeader, ADDR.getRelatesToQName());
List<Relationship> relList = new ArrayList<Relationship>();
while (itRelatesTo.hasNext())
{
Element wsaRelatesTo = (Element)itRelatesTo.next();
QName type = DOMUtils.getAttributeValueAsQName(wsaRelatesTo, ADDR.getRelationshipTypeName());
String uri = DOMUtils.getTextContent(wsaRelatesTo);
Relationship rel = builder.newRelationship(new URI(uri));
rel.setType(type);
relList.add(rel);
}