Kirill created CXF-8008:
---------------------------
Summary: org.apache.cxf.ext.logging.event.PrettyLoggingFilter
doesn't handle com.ctc.wstx.exc.WstxLazyException
Key: CXF-8008
URL: https://issues.apache.org/jira/browse/CXF-8008
Project: CXF
Issue Type: Bug
Reporter: Kirill
Hello everybody. I have problems using pretty logging with truncation
sometimes. I think that's because of the method in
org.apache.cxf.ext.logging.event.PrettyLoggingFilter:
{code:java}
private String getPrettyMessage(LogEvent event) {
String payload = event.getPayload();
StringWriter swriter = new StringWriter(estimatePrettySize(payload));
XMLStreamWriter xwriter = new
PrettyPrintXMLStreamWriter(StaxUtils.createXMLStreamWriter(swriter), 2);
XMLStreamReader xreader = StaxUtils.createXMLStreamReader(new
StringReader(payload));
try {
StaxUtils.copy(xreader, xwriter);
xwriter.flush();
} catch (XMLStreamException xse) {
if (!event.isTruncated()) {
LOG.debug("Error while pretty printing cxf message, returning raw
message.", xse);
return payload;
}
// Expected behavior for truncated payloads - keep what is already
written.
// This might effectively result in additional truncation,
// as the truncated XML document might result in partially parsed XML
nodes,
// for example an open start tag. As long as a truncated payload is not
// mistaken for a non-truncated payload, we're good.
flush(xwriter);
return swriter.toString();
} finally {
close(xwriter);
close(xreader);
}
return swriter.toString();
}
{code}
It catches only XMLStreamException and if other exceptions occur everything
just breaks, just because of the logging!
I came up with a very simple example that can illustrate the problem:
{code:java}
String badString = "<s>n&a";
XMLStreamWriter xwriter = new
PrettyPrintXMLStreamWriter(StaxUtils.createXMLStreamWriter(new StringWriter()),
2);
XMLStreamReader xreader = StaxUtils.createXMLStreamReader(new
StringReader(badString));
try {
StaxUtils.copy(xreader, xwriter);
} catch (XMLStreamException xse) {
//this is the exception that is handled
} catch (WstxLazyException e) {
//this is the exception that is not handled
}
{code}
Parsing this very simple line causes com.ctc.wstx.exc.WstxLazyException, not
javax.xml.stream.XMLStreamException. Maybe it would be better to catch all
possible exceptions?
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)