cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [6/7] git commit: [CXF-5679, CXF-5724] Fix some usage of the "fragment" flag to staxutils.copy and make it properly handle a fragment.
Date Fri, 02 May 2014 13:42:33 GMT
[CXF-5679, CXF-5724] Fix some usage of the "fragment" flag to staxutils.copy and make it properly
handle a fragment.


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

Branch: refs/heads/2.7.x-fixes
Commit: 23e78dcb87ebfa4ed1e6fa2a9d2e53d4f42093ba
Parents: b9f305a
Author: Daniel Kulp <dkulp@apache.org>
Authored: Thu May 1 19:24:31 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Thu May 1 20:06:22 2014 -0400

----------------------------------------------------------------------
 .../org/apache/cxf/staxutils/StaxUtils.java     |  2 +-
 .../org/apache/cxf/staxutils/StaxUtilsTest.java | 36 +++++++++++++++++++
 .../cxf/binding/soap/saaj/ParseBodyTest.java    | 37 +++-----------------
 .../org/apache/cxf/xmlbeans/DataWriterImpl.java |  4 +--
 .../handler/logical/LogicalMessageImpl.java     |  2 +-
 5 files changed, 45 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/23e78dcb/api/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/cxf/staxutils/StaxUtils.java b/api/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
index 3511139..dba4db1 100644
--- a/api/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
+++ b/api/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
@@ -736,7 +736,7 @@ public final class StaxUtils {
                     writer.writeEndElement();
                 }
                 read--;
-                if (read <= 0 && !fragment) {
+                if (read <= 0 && fragment) {
                     return;
                 }
                 if (isThreshold && !countStack.isEmpty()) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/23e78dcb/api/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java b/api/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
index 8b02be7..3851f63 100644
--- a/api/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
+++ b/api/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
@@ -364,4 +364,40 @@ public class StaxUtilsTest extends Assert {
             // ignore
         }
     }
+    
+    @Test
+    public void testCopyFromTheMiddle() throws Exception {
+        String innerXml =
+                "<inner>\n"
+                + "<body>body text here</body>\n"
+                + "</inner>";
+        String xml =
+                "<outer>\n"
+                + innerXml + "\n"
+                + "</outer>";
+
+        StringReader reader = new StringReader(xml);
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        dbf.setValidating(false);
+
+        Document doc = dbf.newDocumentBuilder().parse(new InputSource(reader));
+        Source source = new DOMSource(doc);
+
+        // Skip <outer>
+        XMLStreamReader sreader = StaxUtils.createXMLStreamReader(source);
+        while (!"inner".equals(sreader.getLocalName())) {
+            sreader.next();
+        }
+
+        StringWriter sw = new StringWriter();
+        XMLStreamWriter swriter = StaxUtils.createXMLStreamWriter(sw);
+
+        StaxUtils.copy(sreader, swriter, true, true);
+        swriter.flush();
+        swriter.close();
+
+        System.out.println(sw.toString());
+        assertEquals(innerXml, sw.toString());
+    }    
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/23e78dcb/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
index b9d008a..4e8d5bc 100644
--- 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
@@ -48,29 +48,16 @@ public class ParseBodyTest extends Assert {
         //System.out.println("Original[" + n + "]: " + data);
 
         xmlReader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(data.getBytes("utf-8")));
-        xmlReader.next();
-        xmlReader.next();
-
+        
+        //reader should be on the start element for the 
+        assertEquals(XMLStreamReader.START_ELEMENT, xmlReader.next());
+        assertEquals("Body", xmlReader.getLocalName());
+        
         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);
     }
@@ -85,20 +72,6 @@ public class ParseBodyTest extends Assert {
         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()

http://git-wip-us.apache.org/repos/asf/cxf/blob/23e78dcb/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
----------------------------------------------------------------------
diff --git a/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
b/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
index e3c7862..fdf2ed4 100755
--- a/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
+++ b/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
@@ -189,10 +189,10 @@ public class DataWriterImpl implements DataWriter<XMLStreamWriter>
{
                                                      elementName.getNamespaceURI());
                         }
                     }
-                    StaxUtils.copy(reader, output, true);
+                    StaxUtils.copy(reader, output, false);
                     output.writeEndElement();
                 } else {
-                    StaxUtils.copy(reader, output, true);
+                    StaxUtils.copy(reader, output, false);
                 }
             } else if (needToRender(part)) {
                 output.writeStartElement(part.getConcreteName().getNamespaceURI(),

http://git-wip-us.apache.org/repos/asf/cxf/blob/23e78dcb/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java
b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java
index 1fb05f7..299c32d 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java
@@ -102,7 +102,7 @@ public class LogicalMessageImpl implements LogicalMessage {
                         reader = message.getContent(XMLStreamReader.class);
                         //content must be an element thing, skip over any whitespace
                         StaxUtils.toNextTag(reader);
-                        StaxUtils.copy(reader, writer);
+                        StaxUtils.copy(reader, writer, true);
                         source = new DOMSource(writer.getDocument().getDocumentElement());
                         reader = StaxUtils.createXMLStreamReader(writer.getDocument());
                     } catch (ParserConfigurationException e) {


Mime
View raw message