cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [1/5] git commit: [CXF-5635] Optimize the LoggingOutInterceptor to only cache up to the limit...
Date Sat, 22 Mar 2014 00:49:46 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes 4399f9286 -> 3198290d2


[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/96470318
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/96470318
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/96470318

Branch: refs/heads/2.7.x-fixes
Commit: 96470318598d3361ce70469a69310a95f7123582
Parents: 4399f92
Author: Daniel Kulp <dkulp@apache.org>
Authored: Fri Mar 21 20:26:18 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Fri Mar 21 20:46:12 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/96470318/api/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java b/api/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
index 439295b..2b82cdc 100644
--- a/api/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
+++ b/api/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/96470318/api/src/main/java/org/apache/cxf/io/CacheAndWriteOutputStream.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/cxf/io/CacheAndWriteOutputStream.java b/api/src/main/java/org/apache/cxf/io/CacheAndWriteOutputStream.java
index 8f5ac19..f34fcd9 100644
--- a/api/src/main/java/org/apache/cxf/io/CacheAndWriteOutputStream.java
+++ b/api/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;
     }
 }


Mime
View raw message