You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2014/05/02 15:42:31 UTC
[4/7] git commit: [CXF-5679] Fix problems with trailing whitespace in
the soap:body could be discarded. Tests from Aki Yoshida
[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/e899fd98
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e899fd98
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e899fd98
Branch: refs/heads/2.7.x-fixes
Commit: e899fd9815fb67d4da0fa7e0e9fdae07e490edaf
Parents: 7a26178
Author: Daniel Kulp <dk...@apache.org>
Authored: Wed Apr 30 17:12:16 2014 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Thu May 1 20:06:06 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/e899fd98/api/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java b/api/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
index 204bfb4..74de7a3 100644
--- a/api/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
+++ b/api/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/e899fd98/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);
+ }
+}