Search in sources :

Example 6 with PrettyPrintXMLStreamWriter

use of org.apache.cxf.staxutils.PrettyPrintXMLStreamWriter in project cxf by apache.

the class AbstractLoggingInterceptor method writePayload.

protected void writePayload(StringBuilder builder, CachedOutputStream cos, String encoding, String contentType, boolean truncated) throws Exception {
    // Just transform the XML message when the cos has content
    if (!truncated && isPrettyLogging() && contentType != null && contentType.contains("xml") && !contentType.toLowerCase().contains("multipart/related") && cos.size() > 0) {
        StringWriter swriter = new StringWriter();
        XMLStreamWriter xwriter = StaxUtils.createXMLStreamWriter(swriter);
        xwriter = new PrettyPrintXMLStreamWriter(xwriter, 2);
        InputStream in = cos.getInputStream();
        try {
            StaxUtils.copy(new StreamSource(new InputStreamReader(in, encoding)), xwriter);
        } catch (XMLStreamException xse) {
        // ignore
        } finally {
            try {
                xwriter.flush();
                xwriter.close();
            } catch (XMLStreamException xse2) {
            // ignore
            }
            in.close();
        }
        String result = swriter.toString();
        if (result.length() < limit || limit == -1) {
            builder.append(result);
        } else {
            builder.append(result.substring(0, limit));
        }
    } else {
        if (StringUtils.isEmpty(encoding)) {
            cos.writeCacheTo(builder, limit);
        } else {
            cos.writeCacheTo(builder, encoding, limit);
        }
    }
}
Also used : PrettyPrintXMLStreamWriter(org.apache.cxf.staxutils.PrettyPrintXMLStreamWriter) StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) PrettyPrintXMLStreamWriter(org.apache.cxf.staxutils.PrettyPrintXMLStreamWriter) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource)

Aggregations

XMLStreamWriter (javax.xml.stream.XMLStreamWriter)6 PrettyPrintXMLStreamWriter (org.apache.cxf.staxutils.PrettyPrintXMLStreamWriter)6 StringWriter (java.io.StringWriter)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 StringReader (java.io.StringReader)2 DOMSource (javax.xml.transform.dom.DOMSource)2 StreamSource (javax.xml.transform.stream.StreamSource)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 WSDLException (javax.wsdl.WSDLException)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 OutTransformWriter (org.apache.cxf.staxutils.transform.OutTransformWriter)1