handle WstxLazyException for pretty logging
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/PrettyLoggingFilter.java b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/PrettyLoggingFilter.java
index ccadc2f..1a49e86 100644
--- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/PrettyLoggingFilter.java
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/PrettyLoggingFilter.java
@@ -25,6 +25,7 @@
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import com.ctc.wstx.exc.WstxLazyException;
import org.apache.cxf.staxutils.PrettyPrintXMLStreamWriter;
import org.apache.cxf.staxutils.StaxUtils;
import org.slf4j.Logger;
@@ -77,9 +78,9 @@
try {
StaxUtils.copy(xreader, xwriter);
xwriter.flush();
- } catch (XMLStreamException xse) {
+ } catch (XMLStreamException | WstxLazyException e) {
if (!event.isTruncated()) {
- LOG.debug("Error while pretty printing cxf message, returning raw message.", xse);
+ LOG.debug("Error while pretty printing cxf message, returning raw message.", e);
return payload;
}
diff --git a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestPrettyLoggingFilter.java b/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestPrettyLoggingFilter.java
index 38222c4..83861a9 100644
--- a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestPrettyLoggingFilter.java
+++ b/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestPrettyLoggingFilter.java
@@ -70,6 +70,18 @@
filter(message, expected, true);
}
+ /**
+ * If truncation happens in the middle of an html entity, com.ctc.wstx.exc.WstxLazyException can be thrown.
+ * This test ensures that WstxLazyException is properly handled (ignored) just like the javax.xml.stream.XMLStreamException.
+ * See CXF-8008.
+ */
+ @Test
+ public void testHtmlEntityTruncated() {
+ String message = "<element>a&n";
+ String expected = "<element";
+ filter(message, expected, true);
+ }
+
private void filter(String payload, String expected, boolean truncated) {
LogEvent logEvent = new LogEvent();
logEvent.setPayload(payload);