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-7044] Logging as usual in case of the pretty-print exceptions
Date Fri, 09 Sep 2016 15:57:30 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes ea8ef138a -> c1200af1d


[CXF-7044] Logging as usual in case of the pretty-print exceptions


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

Branch: refs/heads/3.1.x-fixes
Commit: c1200af1dca03b37d336f8d4db13c598964c9c61
Parents: ea8ef13
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Sep 9 16:55:44 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Sep 9 16:57:14 2016 +0100

----------------------------------------------------------------------
 .../interceptor/AbstractLoggingInterceptor.java | 49 ++++++++++++--------
 1 file changed, 29 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c1200af1/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
----------------------------------------------------------------------
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 73912b7..ae994c4 100644
--- a/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
+++ b/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
@@ -207,32 +207,41 @@ public abstract class AbstractLoggingInterceptor extends AbstractPhaseIntercepto
                                 StringWriter stringWriter,
                                 String contentType) 
         throws Exception {
-        // Just transform the XML message when the cos has content
         if (isPrettyLogging() 
             && contentType != null 
             && contentType.indexOf("xml") >= 0 
             && stringWriter.getBuffer().length() > 0) {
-
-            StringWriter swriter = new StringWriter();
-            XMLStreamWriter xwriter = StaxUtils.createXMLStreamWriter(swriter);
-            xwriter = new PrettyPrintXMLStreamWriter(xwriter, 2);
-            StaxUtils.copy(new StreamSource(new StringReader(stringWriter.getBuffer().toString())),
xwriter);
-            xwriter.close();
-            
-            String result = swriter.toString();
-            if (result.length() < limit || limit == -1) {
-                builder.append(swriter.toString());
-            } else {
-                builder.append(swriter.toString().substring(0, limit));
+            try {
+                writePrettyPayload(builder, stringWriter, contentType);
+                return;
+            } catch (Exception ex) { 
+                // log it as is    
             }
-
+        }
+        StringBuffer buffer = stringWriter.getBuffer();
+        if (buffer.length() > limit) {
+            builder.append(buffer.subSequence(0, limit));
         } else {
-            StringBuffer buffer = stringWriter.getBuffer();
-            if (buffer.length() > limit) {
-                builder.append(buffer.subSequence(0, limit));
-            } else {
-                builder.append(buffer);
-            }
+            builder.append(buffer);
+        }
+    }
+    protected void writePrettyPayload(StringBuilder builder, 
+                                StringWriter stringWriter,
+                                String contentType) 
+        throws Exception {
+        // Just transform the XML message when the cos has content
+        
+        StringWriter swriter = new StringWriter();
+        XMLStreamWriter xwriter = StaxUtils.createXMLStreamWriter(swriter);
+        xwriter = new PrettyPrintXMLStreamWriter(xwriter, 2);
+        StaxUtils.copy(new StreamSource(new StringReader(stringWriter.getBuffer().toString())),
xwriter);
+        xwriter.close();
+        
+        String result = swriter.toString();
+        if (result.length() < limit || limit == -1) {
+            builder.append(swriter.toString());
+        } else {
+            builder.append(swriter.toString().substring(0, limit));
         }
     }
 


Mime
View raw message