Skip to content

The problem with child node's XML namespaces #1709

@AliceBlue08

Description

@AliceBlue08

Describe the bug
I want to write tests in Kotlin for an SOAP service and there is a problem with child namespaces. Child node's namespaces break the application during build.

Sample

response {
body = body ("""
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
        <soap:Body>
            <ns2:Res xmlns:ns2="http://*******/****/****/******/schema">
                <ns2:ID>1</ns2:ID>
            </ns2:Res>
        </soap:Body>
    </soap:Envelope>""")
}

Possible problem
Class:
org.springframework.cloud.contract.verifier.util.xml.DOMNamespaceContext

method:

private void addNamespaces (Node element) {
    if (element.getParentNode ()! = null) {
      addNamespaces (element.getParentNode ());
    }
    if (element instanceof Element) {
      Element el = (Element) element;
      NamedNodeMap map = el.getAttributes ();
      for (int x = 0; x <map.getLength (); x ++) {
        Attr attr = (Attr) map.item (x);
        if ("xmlns" .equals (attr.getPrefix ())) {
          namespaceMap.put (attr.getLocalName (), attr.getValue ());
        }
      }
    }
  }

As you can see, it only parses namespaces from the root (soap: Envelope) node. All namespaces declared in child nodes are ignored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions