Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of default namespace into the element when there is already a namespace declared #242

Open
BerksanAtes opened this issue Nov 26, 2024 · 0 comments

Comments

@BerksanAtes
Copy link

BerksanAtes commented Nov 26, 2024

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

        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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant