This is an automated email from the ASF dual-hosted git repository.

ashakirin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 2965ebc  [CXF-7700]: added check on empty encoding
2965ebc is described below

commit 2965ebc53006d77b9feb9850af7ee65af3a5de2c
Author: Andrei Shakirin <andrei.shaki...@gmail.com>
AuthorDate: Sat Apr 7 20:38:49 2018 +0200

    [CXF-7700]: added check on empty encoding
---
 .../interceptor/AbstractLoggingInterceptor.java    |  4 +-
 .../cxf/interceptor/LoggingOutInterceptorTest.java | 49 ++++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java 
b/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
index 965d09d..2a1395b 100644
--- 
a/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
+++ 
b/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
@@ -179,7 +179,9 @@ public abstract class AbstractLoggingInterceptor extends 
AbstractPhaseIntercepto
             xwriter = new PrettyPrintXMLStreamWriter(xwriter, 2);
             InputStream in = cos.getInputStream();
             try {
-                StaxUtils.copy(new StreamSource(new InputStreamReader(in, 
encoding)), xwriter);
+                InputStreamReader inputStreamReader = 
StringUtils.isEmpty(encoding)
+                    ? new InputStreamReader(in) : new InputStreamReader(in, 
encoding);
+                StaxUtils.copy(new StreamSource(inputStreamReader), xwriter);
             } catch (XMLStreamException xse) {
                 //ignore
             } finally {
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 e9c3212..916a4e7 100644
--- 
a/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
+++ 
b/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
@@ -80,6 +80,55 @@ public class LoggingOutInterceptorTest extends Assert {
         //format has changed
         assertFalse(str.matches(s));
         assertTrue(str.contains("<today>"));
+    }
+
+    @Test
+    public void testPrettyLoggingWithoutEncoding() throws Exception {
+        control.replay();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        PrintWriter pw = new PrintWriter(baos);
+        
+        LoggingOutInterceptor p = new LoggingOutInterceptor(pw);
+        p.setPrettyLogging(true);
+        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();
+        //format has changed
+        assertFalse(str.matches(s));
+        assertTrue(str.contains("<today>"));
+    }
+
+    @Test
+    public void testPrettyLoggingWithEncoding() throws Exception {
+        control.replay();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        PrintWriter pw = new PrintWriter(baos);
+        
+        LoggingOutInterceptor p = new LoggingOutInterceptor(pw);
+        p.setPrettyLogging(true);
+        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");
+        message.put(Message.ENCODING, "UTF-8");
+        Logger logger = LogUtils.getL7dLogger(this.getClass());
+        LoggingOutInterceptor.LoggingCallback l = p.new 
LoggingCallback(logger, message, cos);
+        l.onClose(cos);
+        String str = baos.toString();
+        //format has changed
+        assertFalse(str.matches(s));
+        assertTrue(str.contains("<today>"));
 
     }
 

-- 
To stop receiving notification emails like this one, please contact
ashaki...@apache.org.

Reply via email to