You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Colm O hEigeartaigh (JIRA)" <ji...@apache.org> on 2019/04/01 10:31:00 UTC

[jira] [Commented] (CXF-8008) org.apache.cxf.ext.logging.event.PrettyLoggingFilter doesn't handle com.ctc.wstx.exc.WstxLazyException

    [ https://issues.apache.org/jira/browse/CXF-8008?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16806630#comment-16806630 ] 

Colm O hEigeartaigh commented on CXF-8008:
------------------------------------------

I think just handling the woodstox exception as well should be fine. Could you submit a PR for the fix + include a unit test?

> 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
>            Priority: Minor
>
> 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 string 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)