Mike Flynn
Mike Flynn

Reputation: 24325

Grab namespace prefix from request and find element with it in Spring Java

I want to get rid of the static "ims:" and use the prefix found in the SOAP request with the namespace xmlns:ims="http://www.imsglobal.org/services/lis/bdems1p0/wsdl11/sync/imsbdems_v1p0. How can I do this in a Spring interceptor?

protected String findProperty(SOAPHeader soapHeader, String propertyName) {

        NodeList list = soapHeader.getElementsByTagName("ims:" + propertyName);

The property I want is

<ims:imsx_syncRequestHeaderInfo>
         <ims:imsx_version>V1.0</ims:imsx_version>
         <ims:imsx_messageIdentifier>?</ims:imsx_messageIdentifier>
      </ims:imsx_syncRequestHeaderInfo>

Upvotes: 1

Views: 396

Answers (1)

Mike Flynn
Mike Flynn

Reputation: 24325

Fixed it with the following.

NodeList nodeList = soapHeader.getElementsByTagName("*");

for (int i = 0; i < nodeList.getLength(); i++) {
    Node node = nodeList.item(i);
    if (node.getNodeType() == Node.ELEMENT_NODE 
            && node.getLocalName().equalsIgnoreCase(propertyName)) {
            if (node.getTextContent().isEmpty()) {
                    return null;
            } else {
                    return node.getTextContent();
            }
    }
}

Upvotes: 1

Related Questions