if (doc == null)
{
if (this.validator.isOneWayResponse(entryContext))
throw new AssertionNotApplicableException();
else
throw new AssertionFailException("The log message is empty or invalid.");
}
// SOAP 1.1 specifications, Section 4.
// http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383494
// The namespace identifier for the elements and attributes defined
// in this section is "http://schemas.xmlsoap.org/soap/envelope/".
// o The Envelope is the top element of the XML document representing the message.
// Rule 1. Envelope
// o The element name is "Envelope".
// o The element MUST be present in a SOAP message
// o The element MAY contain namespace declarations as well as additional attributes.
// If present, such additional attributes MUST be namespace-qualified. Similarly,
// the element MAY contain additional sub elements. If present these elements
// MUST be namespace-qualified and MUST follow the SOAP Body element.
// Getting the top element
Element element = doc.getDocumentElement();
// Assuming that the top element should be soap:Envelope
// If not, the assertion failed
if (!element.getLocalName().equals(XMLUtils.SOAP_ELEM_ENVELOPE)
|| !isSOAPNamespace(element.getNamespaceURI()))
throw new AssertionFailException("The top element is not soap:Envelope");
// Collecting all the namespace declarations
Collection envelopeNamespaces = collectNamespaces(element.getAttributes());
envelopeNamespaces.add(WSIConstants.NS_URI_XMLNS);
// Getting an attribute that is not in any of the namespaces
Attr notValidAttr = getNotValidAttr(
element.getAttributes(),
envelopeNamespaces);
// If found one, the assertion failed
if (notValidAttr != null)
throw new AssertionFailException("The attribute "
+ notValidAttr.getNodeName() + " is not namespace-qualified");
// Rule 2. Header
// o The element name is "Header".
// o The element MAY be present in a SOAP message. If present, the element
// MUST be the first immediate child element of a SOAP Envelope element.
// o The element MAY contain a set of header entries each being an immediate
// child element of the SOAP Header element. All immediate child elements
// of the SOAP Header element MUST be namespace-qualified.
// Getting the first sub element of the envelope
element = XMLUtils.getFirstChild(element);
Collection headerNamespaces = collectNamespaces(element.getAttributes());
// If the child is soap:Header
if (element != null
&& element.getLocalName().equals(XMLUtils.SOAP_ELEM_HEADER)
&& isSOAPNamespace(element.getNamespaceURI()))
{
// Going through all the Header entries
Element headerEntry = XMLUtils.getFirstChild(element);
while (headerEntry != null)
{
// Collecting all the namespaces for the current entry
Collection headerEntryNamespaces = collectNamespaces(
headerEntry.getAttributes());
// If the entry is not in the namespaces, the assertion failed
if (!envelopeNamespaces.contains(headerEntry.getNamespaceURI())
&& !headerNamespaces.contains(headerEntry.getNamespaceURI())
&& !headerEntryNamespaces.contains(headerEntry.getNamespaceURI()))
throw new AssertionFailException("The header entry "
+ headerEntry.getNodeName() + " is not namespace-qualified");
// Getting the next Header entry
headerEntry = XMLUtils.getNextSibling(headerEntry);
}
// Getting the next sub element of the envelope
element = XMLUtils.getNextSibling(element);
}
// Rule 3. Body
// o The element name is "Body".
// o The element MUST be present in a SOAP message and MUST be an immediate
// child element of a SOAP Envelope element. It MUST directly follow the
// SOAP Header element if present. Otherwise it MUST be the first immediate
// child element of the SOAP Envelope element.
// o The element MAY contain a set of body entries each being an immediate
// child element of the SOAP Body element. Immediate child elements of the
// SOAP Body element MAY be namespace-qualified. SOAP defines the SOAP Fault
// element, which is used to indicate error messages.
// if the SOAP Body element is not presented, the assertion failed
if (element == null
|| !element.getLocalName().equals(XMLUtils.SOAP_ELEM_BODY)
|| !isSOAPNamespace(element.getNamespaceURI()))
throw new AssertionFailException("The soap:Body element is not presented "
+ "or follows an additional sub element of soap:Envelope");
// Processing all other sub elements of the envelope
element = XMLUtils.getNextSibling(element);
while (element != null)
{
// Checking for the SOAP Header element
if (element.getLocalName().equals(XMLUtils.SOAP_ELEM_HEADER)
&& isSOAPNamespace(element.getNamespaceURI()))
throw new AssertionFailException(
"The soap:Header element cannot follow the soap:Body element");
// Collecting all the namespaces for the current element
Collection elementNamespaces = collectNamespaces(
element.getAttributes());
// If the element is not in the namespaces, the assertion failed
if (!envelopeNamespaces.contains(element.getNamespaceURI())
&& !elementNamespaces.contains(element.getNamespaceURI()))
throw new AssertionFailException("The sub envelope element "
+ element.getNodeName() + " is not namespace-qualified");
// Getting the next sub element of the envelope
element = XMLUtils.getNextSibling(element);
}