cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject git commit: [CXF-5679] Fix problems with trailing whitespace in the soap:body could be discarded. Tests from Aki Yoshida
Date Wed, 30 Apr 2014 21:13:55 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 8ee19a58d -> d7cb53720


[CXF-5679] Fix problems with trailing whitespace in the soap:body could be discarded.
Tests from Aki Yoshida


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/d7cb5372
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/d7cb5372
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/d7cb5372

Branch: refs/heads/master
Commit: d7cb537208095630d373336e973cf262b99d59f4
Parents: 8ee19a5
Author: Daniel Kulp <dkulp@apache.org>
Authored: Wed Apr 30 17:12:16 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Wed Apr 30 17:13:37 2014 -0400

----------------------------------------------------------------------
 .../staxutils/OverlayW3CDOMStreamWriter.java    |  14 ++-
 .../cxf/binding/soap/saaj/ParseBodyTest.java    | 116 +++++++++++++++++++
 2 files changed, 126 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/d7cb5372/core/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java b/core/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
index 204bfb4..74de7a3 100644
--- a/core/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
+++ b/core/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
@@ -41,7 +41,7 @@ public class OverlayW3CDOMStreamWriter extends W3CDOMStreamWriter {
 
     List<Boolean> isOverlaidStack = new LinkedList<Boolean>();
     boolean isOverlaid = true;
-    boolean textOverlay;
+    Boolean textOverlay;
     
     public OverlayW3CDOMStreamWriter(Document document) {
         super(document);
@@ -82,7 +82,7 @@ public class OverlayW3CDOMStreamWriter extends W3CDOMStreamWriter {
         }
         isOverlaid = isOverlaidStack.remove(0);
         super.writeEndElement();
-        textOverlay = false;
+        textOverlay = null;
     }
     public void writeStartElement(String local) throws XMLStreamException {
         isOverlaidStack.add(0, isOverlaid);
@@ -110,6 +110,7 @@ public class OverlayW3CDOMStreamWriter extends W3CDOMStreamWriter {
                     if (nd2.getFirstChild() == null) {
                         //optimize a case where we KNOW anything added cannot be an overlay
                         isOverlaid = false;
+                        textOverlay = null;
                     }
                     return;
                 }
@@ -118,6 +119,7 @@ public class OverlayW3CDOMStreamWriter extends W3CDOMStreamWriter {
         }
         super.writeStartElement(local);
         isOverlaid = false;
+        textOverlay = Boolean.FALSE;
     }
 
     protected void adjustOverlaidNode(Node nd2, String pfx) {
@@ -149,6 +151,7 @@ public class OverlayW3CDOMStreamWriter extends W3CDOMStreamWriter {
                     if (nd2.getFirstChild() == null) {
                         //optimize a case where we KNOW anything added cannot be an overlay
                         isOverlaid = false;
+                        textOverlay = null;
                     }
                     return;
                 }
@@ -157,6 +160,7 @@ public class OverlayW3CDOMStreamWriter extends W3CDOMStreamWriter {
         }
         super.writeStartElement(namespace, local);
         isOverlaid = false;
+        textOverlay = false;
     }
 
     public void writeStartElement(String prefix, String local, String namespace) throws XMLStreamException
{
@@ -190,6 +194,7 @@ public class OverlayW3CDOMStreamWriter extends W3CDOMStreamWriter {
                         if (nd2.getFirstChild() == null) {
                             //optimize a case where we KNOW anything added cannot be an overlay
                             isOverlaid = false;
+                            textOverlay = null;
                         }
                         return;
                     }
@@ -198,12 +203,13 @@ public class OverlayW3CDOMStreamWriter extends W3CDOMStreamWriter {
             }
             super.writeStartElement(prefix, local, namespace);
             isOverlaid = false;
+            textOverlay = false;
         }
     }
     
     public void writeCharacters(String text) throws XMLStreamException {
-        if (!isOverlaid) {
-            super.writeCharacters(text); 
+        if (!isOverlaid || textOverlay == null) {
+            super.writeCharacters(text);
         } else if (!textOverlay) {
             Element nd = getCurrentNode();
             Node txt = nd.getFirstChild();

http://git-wip-us.apache.org/repos/asf/cxf/blob/d7cb5372/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/ParseBodyTest.java
----------------------------------------------------------------------
diff --git a/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/ParseBodyTest.java
b/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/ParseBodyTest.java
new file mode 100644
index 0000000..b9d008a
--- /dev/null
+++ b/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/ParseBodyTest.java
@@ -0,0 +1,116 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.binding.soap.saaj;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.cxf.staxutils.StaxUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ParseBodyTest extends Assert {
+    static final String[] DATA = {
+        "<SOAP-ENV:Body xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
+            + "    <foo>\n        <bar/>\n    </foo>\n</SOAP-ENV:Body>",
+        "<SOAP-ENV:Body xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+            + "<foo>\n        <bar/>\n    </foo>\n</SOAP-ENV:Body>",
+        "<SOAP-ENV:Body xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+            + "<foo>\n        <bar/>\n    </foo></SOAP-ENV:Body>"};
+
+    private XMLStreamReader xmlReader;
+    private MessageFactory factory;
+    private SOAPMessage soapMessage;
+
+    private void prepare(int n) throws Exception {
+        String data = DATA[n];
+        //System.out.println("Original[" + n + "]: " + data);
+
+        xmlReader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(data.getBytes("utf-8")));
+        xmlReader.next();
+        xmlReader.next();
+
+        factory = MessageFactory.newInstance();
+        soapMessage = factory.createMessage();
+    }
+
+    @Test
+    public void testUsingReadDocElementsData0() throws Exception {
+        testUsingReadDocElements(0);
+    }
+
+    @Test
+    public void testUsingReadDocElementsData1() throws Exception {
+        testUsingReadDocElements(1);
+    }
+
+    @Test
+    public void testUsingReadDocElementsData2() throws Exception {
+        testUsingReadDocElements(2);
+    }
+
+    @Test
+    public void testUsingStaxUtilsCopyWithSAAJWriterData0() throws Exception {
+        testUsingStaxUtilsCopyWithSAAJWriter(0);
+    }
+
+    @Test
+    public void testUsingStaxUtilsCopyWithSAAJWriterData1() throws Exception {
+        testUsingStaxUtilsCopyWithSAAJWriter(1);
+    }
+
+    @Test
+    public void testUsingStaxUtilsCopyWithSAAJWriterData2() throws Exception {
+        testUsingStaxUtilsCopyWithSAAJWriter(2);
+    }
+
+    private void testUsingReadDocElements(int n) throws Exception {
+        prepare(n);
+        StaxUtils.readDocElements(soapMessage.getSOAPPart().getEnvelope().getBody(), xmlReader,
true, true);
+
+        DOMSource bodySource = new DOMSource(soapMessage.getSOAPPart().getEnvelope().getBody());
+        xmlReader = StaxUtils.createXMLStreamReader(bodySource);
+
+        ByteArrayOutputStream buf = new ByteArrayOutputStream();
+        StaxUtils.copy(xmlReader, buf);
+        String result = buf.toString();
+        //System.out.println("UsingReadDocElements: " + result);
+        assertEquals(DATA[n], result);
+    }
+
+    private void testUsingStaxUtilsCopyWithSAAJWriter(int n) throws Exception {
+        prepare(n);
+        StaxUtils.copy(xmlReader, new SAAJStreamWriter(soapMessage.getSOAPPart(), soapMessage.getSOAPPart()
+            .getEnvelope().getBody()), true, true);
+
+        DOMSource bodySource = new DOMSource(soapMessage.getSOAPPart().getEnvelope().getBody());
+        xmlReader = StaxUtils.createXMLStreamReader(bodySource);
+
+        ByteArrayOutputStream buf = new ByteArrayOutputStream();
+        StaxUtils.copy(xmlReader, buf);
+        String result = buf.toString();
+        //System.out.println("UsingStaxUtilsCopyWithSAAJWriter: " + result);
+        assertEquals(DATA[n], result);
+    }
+}


Mime
View raw message