spring-cloud-contract icon indicating copy to clipboard operation
spring-cloud-contract copied to clipboard

The problem with child node's XML namespaces

Open AliceBlue08 opened this issue 2 years ago • 3 comments

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.

AliceBlue08 avatar Aug 31 '21 12:08 AliceBlue08

Hi! Are you willing to file a fix for this issue?

marcingrzejszczak avatar Aug 31 '21 13:08 marcingrzejszczak

Hi! Are you willing to file a fix for this issue?

Hello, sorry, but I'm afraid I can't. Hope you will fix it when you have time

AliceBlue08 avatar Sep 01 '21 11:09 AliceBlue08

Any updates on this? If not Can I give it a try?

bensonbenny021 avatar Jul 26 '22 06:07 bensonbenny021