You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2006/12/06 09:05:53 UTC
svn commit: r482956 - in /incubator/cxf/trunk/common/common/src:
main/java/org/apache/cxf/staxutils/StaxUtils.java
test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
test/java/org/apache/cxf/staxutils/resources/headerSoapReq.xml
Author: ningjiang
Date: Wed Dec 6 00:05:52 2006
New Revision: 482956
URL: http://svn.apache.org/viewvc?view=rev&rev=482956
Log:
[JIRA CXF-236] Applied the William's patch for StaxUtils.copy()
Added:
incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/resources/headerSoapReq.xml (with props)
Modified:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?view=diff&rev=482956&r1=482955&r2=482956
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Wed Dec 6 00:05:52 2006
@@ -224,10 +224,12 @@
prefix = "";
}
- String boundPrefix = writer.getPrefix(uri);
boolean writeElementNS = false;
- if (boundPrefix == null || !prefix.equals(boundPrefix)) {
- writeElementNS = true;
+ if (uri != null) {
+ String boundPrefix = writer.getPrefix(uri);
+ if (boundPrefix == null || !prefix.equals(boundPrefix)) {
+ writeElementNS = true;
+ }
}
// Write out the element name
Modified: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java?view=diff&rev=482956&r1=482955&r2=482956
==============================================================================
--- incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java (original)
+++ incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java Wed Dec 6 00:05:52 2006
@@ -22,6 +22,8 @@
import java.io.*;
import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
import junit.framework.TestCase;
public class StaxUtilsTest extends TestCase {
@@ -46,5 +48,33 @@
assertTrue(StaxUtils.toNextElement(reader));
assertEquals("Body", reader.getLocalName());
+ }
+
+ public void testCopy() throws Exception {
+
+ // do the stream copying
+ String soapMessage = "./resources/headerSoapReq.xml";
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ XMLStreamReader reader = StaxUtils.createXMLStreamReader(getTestStream(soapMessage));
+ XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(baos);
+ StaxUtils.copy(reader, writer);
+ writer.flush();
+ baos.flush();
+
+ // write output to a string
+ String output = baos.toString();
+
+ // re-read the input xml doc to a string
+ InputStreamReader inputStreamReader = new InputStreamReader(getTestStream(soapMessage));
+ StringWriter stringWriter = new StringWriter();
+ char[] buffer = new char[4096];
+ int n = 0;
+ while (-1 != (n = inputStreamReader.read(buffer))) {
+ stringWriter.write(buffer, 0 , n);
+ }
+ String input = stringWriter.toString();
+
+ // compare the input and output string
+ assertEquals(input, output);
}
}
Added: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/resources/headerSoapReq.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/resources/headerSoapReq.xml?view=auto&rev=482956
==============================================================================
--- incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/resources/headerSoapReq.xml (added)
+++ incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/resources/headerSoapReq.xml Wed Dec 6 00:05:52 2006
@@ -0,0 +1,13 @@
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Header>
+ <ns3:SOAPHeaderInfo xmlns:ns3="http://apache.org/headers/types" xmlns:ns2="http://www.w3.org/2005/08/addressing/wsdl">
+ <originator>in originator</originator>
+ <message>in message</message>
+ </ns3:SOAPHeaderInfo>
+ </soap:Header>
+ <soap:Body>
+ <ns3:inHeader xmlns:ns3="http://apache.org/headers/types" xmlns:ns2="http://www.w3.org/2005/08/addressing/wsdl">
+ <requestType>in request type</requestType>
+ </ns3:inHeader>
+ </soap:Body>
+</soap:Envelope>
\ No newline at end of file
Propchange: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/resources/headerSoapReq.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/resources/headerSoapReq.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/resources/headerSoapReq.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml