cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6510] Updating LoggingOutInterceptor to use formatLoggingMessage, patch from CodeSmell(Mike) applied, This closes #135
Date Mon, 16 May 2016 09:10:45 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 44d015322 -> 735fb439f


[CXF-6510] Updating LoggingOutInterceptor to use formatLoggingMessage, patch from CodeSmell(Mike)
applied, This closes #135


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/735fb439
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/735fb439
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/735fb439

Branch: refs/heads/3.0.x-fixes
Commit: 735fb439f9d86c9ed5a85ffaad0aeecfb4ac1e8a
Parents: 44d0153
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon May 16 10:08:08 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon May 16 10:10:11 2016 +0100

----------------------------------------------------------------------
 .../cxf/interceptor/LoggingOutInterceptor.java  |  9 +--
 .../interceptor/LoggingOutInterceptorTest.java  | 72 ++++++++++++++++++++
 2 files changed, 75 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/735fb439/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 74c2788..edd4f8a 100644
--- a/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
+++ b/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
@@ -19,7 +19,6 @@
 
 package org.apache.cxf.interceptor;
 
-
 import java.io.FilterWriter;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -36,7 +35,6 @@ import org.apache.cxf.io.CachedOutputStreamCallback;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
 
-
 /**
  * 
  */
@@ -189,7 +187,7 @@ public class LoggingOutInterceptor extends AbstractLoggingInterceptor
{
             } catch (Exception ex) {
                 //ignore
             }
-            log(logger, buffer.toString());
+            log(logger, formatLoggingMessage(buffer));
             message.setContent(Writer.class, out);
             super.close();
         }
@@ -228,7 +226,7 @@ public class LoggingOutInterceptor extends AbstractLoggingInterceptor
{
             }
             if (!isShowMultipartContent() && isMultipartContent(ct)) {
                 buffer.getMessage().append(MULTIPART_CONTENT_MESSAGE).append('\n');
-                log(logger, buffer.toString());
+                log(logger, formatLoggingMessage(buffer));
                 return;
             }
             
@@ -259,8 +257,7 @@ public class LoggingOutInterceptor extends AbstractLoggingInterceptor
{
             } catch (Exception ex) {
                 //ignore
             }
-            message.setContent(OutputStream.class, 
-                               origStream);
+            message.setContent(OutputStream.class, origStream);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/735fb439/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
b/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
index 55c1aad..832f738 100644
--- a/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
+++ b/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
@@ -22,6 +22,8 @@ package org.apache.cxf.interceptor;
 import java.io.ByteArrayOutputStream;
 import java.io.OutputStream;
 import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
 import java.util.logging.Logger;
 
 import org.apache.cxf.common.logging.LogUtils;
@@ -76,6 +78,60 @@ public class LoggingOutInterceptorTest extends Assert {
         assertTrue(str.contains("<today>"));
 
     }
+    
+    @Test
+    public void testFormattingOverride() throws Exception {
+        control.replay();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        
+        // create a custom logging interceptor that overrides how formatting is done
+        LoggingOutInterceptor p = new CustomFormatLoggingOutInterceptor(new PrintWriter(baos));
+        CachedOutputStream cos = new CachedOutputStream();
+        String s = "<today><is><the><twenty> <second> <of>
<january> <two> <thousand> <and> <nine></nine> "
+            + "</and></thousand></two></january></of></second></twenty></the></is></today>";
+        cos.write(s.getBytes());
+        
+        Message message = new MessageImpl();
+        message.setExchange(new ExchangeImpl());
+        message.put(Message.CONTENT_TYPE, "application/xml");
+        Logger logger = LogUtils.getL7dLogger(this.getClass());
+        LoggingOutInterceptor.LoggingCallback l = p.new LoggingCallback(logger, message,
cos);
+        l.onClose(cos);
+        
+        String str = baos.toString();
+        assertTrue(str.contains("<tomorrow/>"));
+
+    }
+    
+    @Test
+    public void testFormattingOverrideLogWriter() throws Exception {
+        // create a custom logging interceptor that overrides how formatting is done
+        LoggingOutInterceptor p = new CustomFormatLoggingOutInterceptor();
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        p.setPrintWriter(new PrintWriter(baos));
+        
+        StringWriter sw = new StringWriter();
+        sw.append("<today/>");
+        
+        Endpoint endpoint = control.createMock(Endpoint.class);
+        EndpointInfo endpointInfo = control.createMock(EndpointInfo.class);
+        EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo).anyTimes();
+        control.replay();
+
+        Message message = new MessageImpl();
+        message.setExchange(new ExchangeImpl());
+        message.put(Message.CONTENT_TYPE, "application/xml");
+        message.setContent(Writer.class, sw);
+        
+        p.handleMessage(message);
+        
+        Writer w = message.getContent(Writer.class);
+        w.close();
+        
+        String str = baos.toString();
+        assertTrue(str.contains("<tomorrow/>"));
+    }
 
     @Test
     public void testCachedOutputStreamThreshold() throws Exception {
@@ -112,4 +168,20 @@ public class LoggingOutInterceptorTest extends Assert {
         return (CachedOutputStream)os;
     }
 
+    private class CustomFormatLoggingOutInterceptor extends LoggingOutInterceptor {
+        CustomFormatLoggingOutInterceptor() {
+            super();
+        }
+        
+        CustomFormatLoggingOutInterceptor(PrintWriter w) {
+            super(w);
+        }
+        
+        @Override
+        protected String formatLoggingMessage(LoggingMessage loggingMessage) {
+            loggingMessage.getPayload().append("<tomorrow/>");
+            return super.formatLoggingMessage(loggingMessage);
+        }
+
+    }
 }


Mime
View raw message