You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by as...@apache.org on 2018/04/07 18:38:30 UTC
[cxf] branch 3.1.x-fixes updated: [CXF-7700]: added check on empty
encoding
This is an automated email from the ASF dual-hosted git repository.
ashakirin pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.1.x-fixes by this push:
new 4d3b0a2 [CXF-7700]: added check on empty encoding
4d3b0a2 is described below
commit 4d3b0a2774f7b558d891391c3a517ef460ba56e8
Author: Andrei Shakirin <an...@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 5e90ea3..d0a8ddb 100644
--- a/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
+++ b/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
@@ -178,7 +178,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 1b85b41..d8f26fd 100644
--- a/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
+++ b/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
@@ -79,10 +79,59 @@ 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>"));
+
+ }
+
+ @Test
public void testFormattingOverride() throws Exception {
control.replay();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
--
To stop receiving notification emails like this one, please contact
ashakirin@apache.org.