You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an element created with a given prefix is added to the SOAPBody default namespace is added beside the namespace including the prefix. This happens only with Java 9+. For Java 8, it works without a problem. Same behavior is observed from SAAJ version 1.4.0 to SAAJ 3.0.
In com.sun.xml.messaging.saaj.soap.impl.ElementImpl class addNode method, after Node is casted to ElementImpl to perform getElementQName() call, QName is created without prefix. This behavior leads to addition of default namespace since search for alreadyDeclaredUri in getNamespaceURI(prefix) return null in ensureNamespaceIsDeclared method.
Reproducing the issue
Running this code with java 9+ and SAAJ 1.4.0+ should create the issue.
System.setProperty("javax.xml.soap.SAAJMetaFactory", "com.sun.xml.messaging.saaj.soap.SAAJMetaFactoryImpl");
MessageFactory mf = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPMessage request = mf.createMessage();
SOAPPart part = request.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPFactory SOAP_FACTORY = SOAPFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPElement testElement = SOAP_FACTORY.createElement("testNamespace", "ns0", "http://objects.get.echo.io"); // <- A soap element is created with namespace prefix ns0
SOAPElement inElement = SOAP_FACTORY.createElement("in", null, "");
testElement.addChildElement(inElement);
body.addChildElement(testElement); // <- default namespace is added beside namespace with ns0 prefix
The text was updated successfully, but these errors were encountered:
Context
When an element created with a given prefix is added to the SOAPBody default namespace is added beside the namespace including the prefix. This happens only with Java 9+. For Java 8, it works without a problem. Same behavior is observed from SAAJ version 1.4.0 to SAAJ 3.0.
output sample when run with java 8:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">SOAP-ENV:Header/SOAP-ENV:Body<ns0:testNamespace xmlns:ns0="http://objects.get.echo.io"></ns0:testNamespace></SOAP-ENV:Body></SOAP-ENV:Envelope>
output sample when run with java 9+:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">SOAP-ENV:Header/SOAP-ENV:Body<ns0:testNamespace xmlns="http://objects.get.echo.io" xmlns:ns0="http://objects.get.echo.io"></ns0:testNamespace></SOAP-ENV:Body></SOAP-ENV:Envelope>
Analysis
In com.sun.xml.messaging.saaj.soap.impl.ElementImpl class addNode method, after Node is casted to ElementImpl to perform getElementQName() call, QName is created without prefix. This behavior leads to addition of default namespace since search for alreadyDeclaredUri in getNamespaceURI(prefix) return null in ensureNamespaceIsDeclared method.
Reproducing the issue
The text was updated successfully, but these errors were encountered: