You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2022/01/27 16:43:33 UTC
[cxf] branch 3.4.x-fixes updated: CXF-8646 - Don't return exception class name when parsing XML
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch 3.4.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.4.x-fixes by this push:
new a56e51b CXF-8646 - Don't return exception class name when parsing XML
a56e51b is described below
commit a56e51b4eef5d417ac29a14af1e7acfe797b9c21
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Thu Jan 27 16:41:03 2022 +0000
CXF-8646 - Don't return exception class name when parsing XML
(cherry picked from commit 69cf83dfcedfd4c496459dc03433776703d60222)
(cherry picked from commit 023a6edfa2bdfca28126a52a71c2b9677126eacf)
---
.../cxf/databinding/source/Messages.properties | 2 +-
.../cxf/databinding/source/NodeDataReader.java | 2 +-
.../databinding/source/XMLStreamDataReader.java | 4 +--
.../source/XMLStreamDataReaderTest.java | 31 +++++++++++++++++++++-
4 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties b/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties
index 5dc12a4..039a199 100644
--- a/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties
+++ b/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties
@@ -20,6 +20,6 @@
#
COULD_NOT_READ_XML_STREAM = Could not parse the XML stream.
COULD_NOT_WRITE_XML_STREAM = Could not generate the XML stream.
-COULD_NOT_READ_XML_STREAM_CAUSED_BY = Could not parse the XML stream caused by: {0}: {1}.
+COULD_NOT_READ_XML_STREAM_CAUSED_BY = Could not parse the XML stream caused by: {0}.
COULD_NOT_WRITE_XML_STREAM_CAUSED_BY = Could not generate the XML stream caused by: {0}: {1}.
NO_MSV_AVAILABLE = Failed to initialize MSV validator, using slower validation routing.
diff --git a/core/src/main/java/org/apache/cxf/databinding/source/NodeDataReader.java b/core/src/main/java/org/apache/cxf/databinding/source/NodeDataReader.java
index c55f79e..85456e8 100644
--- a/core/src/main/java/org/apache/cxf/databinding/source/NodeDataReader.java
+++ b/core/src/main/java/org/apache/cxf/databinding/source/NodeDataReader.java
@@ -64,7 +64,7 @@ public class NodeDataReader implements DataReader<Node> {
throw new Fault("COULD_NOT_READ_XML_STREAM", LOG, e);
} catch (XMLStreamException e) {
throw new Fault("COULD_NOT_READ_XML_STREAM_CAUSED_BY", LOG, e,
- e.getClass().getCanonicalName(), e.getMessage());
+ e.getMessage());
}
}
return read(input);
diff --git a/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java b/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
index 307b46c..c9dcf15 100644
--- a/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
+++ b/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
@@ -160,7 +160,7 @@ public class XMLStreamDataReader implements DataReader<XMLStreamReader> {
throw new Fault("COULD_NOT_READ_XML_STREAM", LOG, e);
} catch (XMLStreamException e) {
throw new Fault("COULD_NOT_READ_XML_STREAM_CAUSED_BY", LOG, e,
- e.getClass().getCanonicalName(), e.getMessage());
+ e.getMessage());
}
}
@@ -298,7 +298,7 @@ public class XMLStreamDataReader implements DataReader<XMLStreamReader> {
return new DOMSource(document);
} catch (XMLStreamException e) {
throw new Fault("COULD_NOT_READ_XML_STREAM_CAUSED_BY", LOG, e,
- e.getClass().getCanonicalName(), e.getMessage());
+ e.getMessage());
}
}
diff --git a/core/src/test/java/org/apache/cxf/databinding/source/XMLStreamDataReaderTest.java b/core/src/test/java/org/apache/cxf/databinding/source/XMLStreamDataReaderTest.java
index b35956f..8d6684f 100755
--- a/core/src/test/java/org/apache/cxf/databinding/source/XMLStreamDataReaderTest.java
+++ b/core/src/test/java/org/apache/cxf/databinding/source/XMLStreamDataReaderTest.java
@@ -26,6 +26,7 @@ import java.io.InputStream;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamReader;
+import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
import org.apache.cxf.staxutils.StaxUtils;
@@ -40,6 +41,8 @@ import static org.junit.Assert.assertTrue;
*/
public class XMLStreamDataReaderTest {
private static final byte[] DUMMY_DATA = "<ns:dummy xmlns:ns='http://www.apache.org/cxf'/>".getBytes();
+ private static final byte[] DUMMY_DATA_NULL_BYTE =
+ "<ns:dummy xmlns:ns='http://www.apache.org/cxf�'/>".getBytes();
@Test
public void testCloseOriginalInputStream() throws Exception {
@@ -63,6 +66,32 @@ public class XMLStreamDataReaderTest {
assertTrue(in1.isClosed());
}
+ // Parse some XML with a null byte and check we don't return internal Woodstox package names in the error message
+ @Test
+ public void testParseNullByte() throws Exception {
+ XMLStreamDataReader reader = new XMLStreamDataReader();
+ Message msg = new MessageImpl();
+
+ TestInputStream in1 = new TestInputStream(DUMMY_DATA_NULL_BYTE);
+
+ msg.setContent(InputStream.class, in1);
+
+ reader.setProperty(Message.class.getName(), msg);
+
+ Object obj = reader.read(new QName("http://www.apache.org/cxf", "dummy"),
+ StaxUtils.createXMLStreamReader(in1), XMLStreamReader.class);
+
+ assertTrue(obj instanceof XMLStreamReader);
+
+ try {
+ reader.read((XMLStreamReader) obj);
+ } catch (Fault f) {
+ assertFalse(f.getMessage().contains("com.ctc.wstx"));
+ }
+
+ ((XMLStreamReader)obj).close();
+ }
+
private static class TestInputStream extends ByteArrayInputStream {
private boolean closed;
@@ -80,4 +109,4 @@ public class XMLStreamDataReaderTest {
return closed;
}
}
-}
\ No newline at end of file
+}