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);
}
}
}
Aggregations