Repository: cxf Updated Branches: refs/heads/master 976e6e6ed -> 43e74adbd
[CXF-5635] Optimize the LoggingOutInterceptor to only cache up to the limit... Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/43e74adb Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/43e74adb Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/43e74adb Branch: refs/heads/master Commit: 43e74adbdf313e245c88da3b786f8b379ec9a3f0 Parents: 976e6e6 Author: Daniel Kulp <[email protected]> Authored: Fri Mar 21 20:26:18 2014 -0400 Committer: Daniel Kulp <[email protected]> Committed: Fri Mar 21 20:26:18 2014 -0400 ---------------------------------------------------------------------- .../cxf/interceptor/LoggingOutInterceptor.java | 7 +++++-- .../cxf/io/CacheAndWriteOutputStream.java | 21 +++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/43e74adb/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java b/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java index 439295b..2b82cdc 100644 --- a/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java +++ b/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java @@ -80,6 +80,9 @@ public class LoggingOutInterceptor extends AbstractLoggingInterceptor { if (threshold > 0) { newOut.setThreshold(threshold); } + if (limit > 0) { + newOut.setCacheLimit(limit); + } message.setContent(OutputStream.class, newOut); newOut.registerCallback(new LoggingCallback(logger, message, os)); } else { @@ -222,13 +225,13 @@ public class LoggingOutInterceptor extends AbstractLoggingInterceptor { if (cos.getTempFile() == null) { //buffer.append("Outbound Message:\n"); - if (cos.size() > limit) { + if (cos.size() >= limit) { buffer.getMessage().append("(message truncated to " + limit + " bytes)\n"); } } else { buffer.getMessage().append("Outbound Message (saved to tmp file):\n"); buffer.getMessage().append("Filename: " + cos.getTempFile().getAbsolutePath() + "\n"); - if (cos.size() > limit) { + if (cos.size() >= limit) { buffer.getMessage().append("(message truncated to " + limit + " bytes)\n"); } } http://git-wip-us.apache.org/repos/asf/cxf/blob/43e74adb/core/src/main/java/org/apache/cxf/io/CacheAndWriteOutputStream.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/io/CacheAndWriteOutputStream.java b/core/src/main/java/org/apache/cxf/io/CacheAndWriteOutputStream.java index 8f5ac19..f34fcd9 100644 --- a/core/src/main/java/org/apache/cxf/io/CacheAndWriteOutputStream.java +++ b/core/src/main/java/org/apache/cxf/io/CacheAndWriteOutputStream.java @@ -31,6 +31,8 @@ import java.io.OutputStream; public class CacheAndWriteOutputStream extends CachedOutputStream { OutputStream flowThroughStream; + long count; + long limit = Long.MAX_VALUE; public CacheAndWriteOutputStream(OutputStream stream) { super(); @@ -39,6 +41,10 @@ public class CacheAndWriteOutputStream extends CachedOutputStream { } flowThroughStream = stream; } + + public void setCacheLimit(long l) { + limit = l; + } public void closeFlowthroughStream() throws IOException { flowThroughStream.flush(); @@ -63,18 +69,27 @@ public class CacheAndWriteOutputStream extends CachedOutputStream { @Override public void write(int b) throws IOException { flowThroughStream.write(b); - super.write(b); + if (count <= limit) { + super.write(b); + } + count++; } @Override public void write(byte[] b, int off, int len) throws IOException { flowThroughStream.write(b, off, len); - super.write(b, off, len); + if (count <= limit) { + super.write(b, off, len); + } + count += len; } @Override public void write(byte[] b) throws IOException { flowThroughStream.write(b); - super.write(b); + if (count <= limit) { + super.write(b); + } + count += b.length; } }
