# HG changeset patch # User aefimov # Date 1512065261 0 # Node ID b8a119027122c52b5d753621c453bc66c16f1628 # Parent e9dab2492924a3b8201a250f195ec9e285b9fb38 8186441: Change of behavior in the getMessage () method of the SOAPMessageContextImpl class Reviewed-by: lancea diff -r e9dab2492924 -r b8a119027122 src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/util/stax/SaajStaxWriter.java --- a/src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/util/stax/SaajStaxWriter.java Thu Nov 30 06:14:25 2017 -0800 +++ b/src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/util/stax/SaajStaxWriter.java Thu Nov 30 18:07:41 2017 +0000 @@ -505,7 +505,7 @@ } // add namespace declarations for (NamespaceDeclaration namespace : this.namespaceDeclarations) { - target.addNamespaceDeclaration(namespace.prefix, namespace.namespaceUri); + newElement.addNamespaceDeclaration(namespace.prefix, namespace.namespaceUri); } // add attribute declarations for (AttributeDeclaration attribute : this.attributeDeclarations) { diff -r e9dab2492924 -r b8a119027122 src/java.xml.ws/share/classes/com/sun/xml/internal/ws/api/message/saaj/SaajStaxWriter.java --- a/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/api/message/saaj/SaajStaxWriter.java Thu Nov 30 06:14:25 2017 -0800 +++ b/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/api/message/saaj/SaajStaxWriter.java Thu Nov 30 18:07:41 2017 +0000 @@ -499,7 +499,7 @@ } // add namespace declarations for (NamespaceDeclaration namespace : this.namespaceDeclarations) { - target.addNamespaceDeclaration(namespace.prefix, namespace.namespaceUri); + newElement.addNamespaceDeclaration(namespace.prefix, namespace.namespaceUri); } // add attribute declarations for (AttributeDeclaration attribute : this.attributeDeclarations) { diff -r e9dab2492924 -r b8a119027122 test/jdk/javax/xml/ws/8159058/SaajEmptyNamespaceTest.java --- a/test/jdk/javax/xml/ws/8159058/SaajEmptyNamespaceTest.java Thu Nov 30 06:14:25 2017 -0800 +++ b/test/jdk/javax/xml/ws/8159058/SaajEmptyNamespaceTest.java Thu Nov 30 18:07:41 2017 +0000 @@ -23,7 +23,7 @@ /* * @test - * @bug 8159058 + * @bug 8159058 8186441 * @summary Test that empty default namespace declaration clears the * default namespace value * @modules java.xml.ws/com.sun.xml.internal.ws.api @@ -61,6 +61,26 @@ public class SaajEmptyNamespaceTest { /* + * Test that SOAP reader doesn't move namespaces declarations to SOAP body element + * as reported in JDK-8186441 + */ + @Test + public void testPreserveNamespacesPosition() throws Exception { + // Create SOAP message from XML string and process it with SAAJ reader + XMLStreamReader envelope = XMLInputFactory.newFactory().createXMLStreamReader( + new StringReader(INPUT_SOAP_MESSAGE_2)); + StreamMessage streamMessage = new StreamMessage(SOAPVersion.SOAP_11, + envelope, null); + SAAJFactory saajFact = new SAAJFactory(); + SOAPMessage soapMessage = saajFact.readAsSOAPMessage(SOAPVersion.SOAP_11, streamMessage); + + //Get SOAP body and convert it to string representation + SOAPBody body = soapMessage.getSOAPBody(); + String bodyAsString = nodeToText(body); + Assert.assertEquals(bodyAsString, PRESERVE_NAMESPACES_EXPECTED_RESULT); + } + + /* * Test that SOAP message with default namespace declaration that contains empty * string is properly processed by SAAJ reader. */ @@ -275,10 +295,28 @@ // Expected body content after SAAJ processing private static String EXPECTED_RESULT = "" + + " xmlns=\"http://example.org/test\"" + + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "" + "hogehoge" + "fugafuga" + "" + ""; + + private static String PRESERVE_NAMESPACES_EXPECTED_RESULT = + "" + +"" + +"Test_Contact" + +""; + + private static String INPUT_SOAP_MESSAGE_2 = "" + + "" + + "" + + "" + + "" + + "Test_Contact" + + "" + + "" + + "" + + ""; }