Details
Description
I am running a web service in Cxf PAYLOAD mode and in one of the use cases I need to convert the body into Node (Element) and I am doing that by cxfpayload.getBody().get(0)
This makes the namespaces from nsMap to be copied on to the element. While doing so, if the nsMap contains a namespace prefix that is also part of the element's attribute, it is being overwritten in the addNamespace(Element element, Map<String, String> nsMap) method.
But when same prefix in soap Envelope and body contains different namespace values, that makes the body (XML) invalid.
Here is a sample soap request that contains same namespace prefix ns1 in soap:Envelope and soap:Body but contains different namespace values.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.example.com/location/consumerfundbalances/1/" xmlns:ns1="http://www.example.com/consumerfundbalances/retrievefundbalances/bi/1/"> <soapenv:Body> <ns1:retrieveFundBalances xmlns="http://www.example.com/consumerfundbalances/retrievefundbalances/bi/1/" xmlns:ns1="http://www.example.com/location/consumerfundbalances/1/"> <retrieveFundBalances> <fundBalancesRequestIdentifier/> </retrieveFundBalances> </ns1:retrieveFundBalances> </soapenv:Body> </soapenv:Envelope>
Now when I convert the payload into DOM Node, here is output XML namespace value for prefix ns1 is being replaced with the envelope.
<ns1:retrieveFundBalances xmlns:ns1="http://www.example.com/consumerfundbalances/retrievefundbalances/bi/1/" xmlns="http://www.example.com/consumerfundbalances/retrievefundbalances/bi/1/" xmlns:ns="http://www.example.com/location/consumerfundbalances/1/"> <retrieveFundBalances> <fundBalancesRequestIdentifier/> </retrieveFundBalances> </ns1:retrieveFundBalances>