cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1243991 - in /cxf/branches/2.5.x-fixes: ./ api/src/main/java/org/apache/cxf/annotations/ rt/core/src/main/java/org/apache/cxf/feature/ rt/core/src/main/java/org/apache/cxf/interceptor/
Date Tue, 14 Feb 2012 15:27:18 GMT
Author: sergeyb
Date: Tue Feb 14 15:27:17 2012
New Revision: 1243991

URL: http://svn.apache.org/viewvc?rev=1243991&view=rev
Log:
Merged revisions 1243727 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1243727 | sergeyb | 2012-02-13 22:57:19 +0000 (Mon, 13 Feb 2012) | 1 line
  
  [CXF-4102] Updating Logging interceptors to ignore the binary content by default
........

Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/annotations/Logging.java
    cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/feature/LoggingFeature.java
    cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
    cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
    cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Feb 14 15:27:17 2012
@@ -1 +1 @@
-/cxf/trunk:1236720,1241934,1242263,1242359,1242729,1242739,1242840-1242842,1242847,1242948,1243432,1243620,1243926
+/cxf/trunk:1236720,1241934,1242263,1242359,1242729,1242739,1242840-1242842,1242847,1242948,1243432,1243620,1243727,1243926

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/annotations/Logging.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/annotations/Logging.java?rev=1243991&r1=1243990&r2=1243991&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/annotations/Logging.java (original)
+++ cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/annotations/Logging.java Tue
Feb 14 15:27:17 2012
@@ -50,5 +50,10 @@ public @interface Logging {
      * For XML content, turn on pretty printing in the logs
      */
     boolean pretty() default false;
+    
+    /**
+     * Ignore binary payloads by default 
+     */
+    boolean showBinary() default false;
 }
 

Modified: cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/feature/LoggingFeature.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/feature/LoggingFeature.java?rev=1243991&r1=1243990&r2=1243991&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/feature/LoggingFeature.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/feature/LoggingFeature.java
Tue Feb 14 15:27:17 2012
@@ -50,6 +50,7 @@ public class LoggingFeature extends Abst
     String inLocation;
     String outLocation;
     boolean prettyLogging;
+    boolean showBinary;
     
     int limit = DEFAULT_LIMIT;
 
@@ -75,12 +76,18 @@ public class LoggingFeature extends Abst
         limit = lim;
         prettyLogging = p;
     }
+    
+    public LoggingFeature(String in, String out, int lim, boolean p, boolean showBinary)
{
+        this(in, out, lim, p);
+        this.showBinary = showBinary;
+    }
 
     public LoggingFeature(Logging annotation) {
         inLocation = annotation.inLocation();
         outLocation = annotation.outLocation();
         limit = annotation.limit();
         prettyLogging = annotation.pretty();
+        showBinary = annotation.showBinary();
     }
 
     @Override
@@ -95,9 +102,11 @@ public class LoggingFeature extends Abst
             LoggingInInterceptor in = new LoggingInInterceptor(limit);
             in.setOutputLocation(inLocation);
             in.setPrettyLogging(prettyLogging);
+            in.setShowBinaryContent(showBinary);
             LoggingOutInterceptor out = new LoggingOutInterceptor(limit);
             out.setOutputLocation(outLocation);
             out.setPrettyLogging(prettyLogging);
+            out.setShowBinaryContent(showBinary);
             
             provider.getInInterceptors().add(in);
             provider.getInFaultInterceptors().add(in);

Modified: cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java?rev=1243991&r1=1243990&r2=1243991&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
Tue Feb 14 15:27:17 2012
@@ -23,6 +23,8 @@ import java.io.FileWriter;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
 import java.util.logging.Logger;
@@ -46,10 +48,22 @@ import org.apache.cxf.service.model.Inte
  * Logger.
  */
 public abstract class AbstractLoggingInterceptor extends AbstractPhaseInterceptor<Message>
{
-
+    
+    protected static final String BINARY_CONTENT_MESSAGE = "--- Binary Content ---";
+    private static final List<String> BINARY_CONTENT_MEDIA_TYPES;
+    static {
+        BINARY_CONTENT_MEDIA_TYPES = new ArrayList<String>();
+        BINARY_CONTENT_MEDIA_TYPES.add("application/octet-stream");
+        BINARY_CONTENT_MEDIA_TYPES.add("image/png");
+        BINARY_CONTENT_MEDIA_TYPES.add("image/jpeg");
+        BINARY_CONTENT_MEDIA_TYPES.add("image/gif");
+    }
+    
     protected int limit = 100 * 1024;
+    protected long threshold = -1;
     protected PrintWriter writer;
     protected boolean prettyLogging;
+    private boolean showBinaryContent;
     
     public AbstractLoggingInterceptor(String phase) {
         super(phase);
@@ -120,8 +134,15 @@ public abstract class AbstractLoggingInt
     public boolean isPrettyLogging() {
         return prettyLogging;
     }
-    
-    
+
+    public void setInMemThreshold(long t) {
+        threshold = t;
+    }
+
+    public long getInMemThreshold() {
+        return threshold;
+    }
+
     protected void writePayload(StringBuilder builder, CachedOutputStream cos,
                                 String encoding, String contentType) 
         throws Exception {
@@ -178,5 +199,13 @@ public abstract class AbstractLoggingInt
             logger.log(lr);
         }
     }
-    
+    public void setShowBinaryContent(boolean showBinaryContent) {
+        this.showBinaryContent = showBinaryContent;
+    }
+    public boolean isShowBinaryContent() {
+        return showBinaryContent;
+    }
+    public boolean isBinaryContent(String contentType) {
+        return contentType != null && BINARY_CONTENT_MEDIA_TYPES.contains(contentType);
+    }
 }

Modified: cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java?rev=1243991&r1=1243990&r2=1243991&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
Tue Feb 14 15:27:17 2012
@@ -119,10 +119,19 @@ public class LoggingInInterceptor extend
                 buffer.getAddress().append("?").append(query);
             }
         }
-            
+        
+        if (!isShowBinaryContent() && isBinaryContent(ct)) {
+            buffer.getMessage().append(BINARY_CONTENT_MESSAGE).append('\n');
+            log(logger, buffer.toString());
+            return;
+        }
+        
         InputStream is = message.getContent(InputStream.class);
         if (is != null) {
             CachedOutputStream bos = new CachedOutputStream();
+            if (threshold > 0) {
+                bos.setThreshold(threshold);
+            }
             try {
                 IOUtils.copy(is, bos);
 

Modified: cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java?rev=1243991&r1=1243990&r2=1243991&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
Tue Feb 14 15:27:17 2012
@@ -70,6 +70,9 @@ public class LoggingOutInterceptor exten
             if (!hasLogged) {
                 message.put(LOG_SETUP, Boolean.TRUE);
                 final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(os);
+                if (threshold > 0) {
+                    newOut.setThreshold(threshold);
+                }
                 message.setContent(OutputStream.class, newOut);
                 newOut.registerCallback(new LoggingCallback(logger, message, os));
             }
@@ -129,6 +132,12 @@ public class LoggingOutInterceptor exten
                 buffer.getHeader().append(headers);
             }
 
+            if (!isShowBinaryContent() && isBinaryContent(ct)) {
+                buffer.getMessage().append(BINARY_CONTENT_MESSAGE).append('\n');
+                log(logger, buffer.toString());
+                return;
+            }
+            
             if (cos.getTempFile() == null) {
                 //buffer.append("Outbound Message:\n");
                 if (cos.size() > limit) {



Mime
View raw message