cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r982846 - in /cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor: AbstractLoggingInterceptor.java LoggingInInterceptor.java LoggingOutInterceptor.java PrettyLoggingOutInterceptor.java
Date Fri, 06 Aug 2010 01:30:05 GMT
Author: ningjiang
Date: Fri Aug  6 01:30:04 2010
New Revision: 982846

URL: http://svn.apache.org/viewvc?rev=982846&view=rev
Log:
CXF-2931 Polish the code as DanK suggested.

Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java?rev=982846&r1=982845&r2=982846&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
Fri Aug  6 01:30:04 2010
@@ -28,12 +28,12 @@ import java.util.logging.Logger;
 
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
@@ -98,18 +98,12 @@ public abstract class AbstractLoggingInt
     }
     
     
-    protected void writePayload(StringBuilder builder, CachedOutputStream cos, String encoding)

+    protected void writePayload(StringBuilder builder, CachedOutputStream cos,
+                                String encoding, String contentType) 
         throws Exception {
-        if (isPrettyLogging()) {
-
-            TransformerFactory tfactory = TransformerFactory.newInstance();
-            try {
-                tfactory.setAttribute("indent-number", "2");
-            } catch (Exception ex) {
-                // ignore
-            }
-            Transformer serializer;
-            serializer = tfactory.newTransformer();
+        // Just transform the XML message
+        if (isPrettyLogging() && (contentType != null && contentType.indexOf("xml")
>= 0)) {
+            Transformer serializer = XMLUtils.newTransformer(2);
             // Setup indenting to "pretty print"
             serializer.setOutputProperty(OutputKeys.INDENT, "yes");
             serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java?rev=982846&r1=982845&r2=982846&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java Fri
Aug  6 01:30:04 2010
@@ -115,7 +115,7 @@ public class LoggingInInterceptor extend
                 if (bos.size() > limit) {
                     buffer.getMessage().append("(message truncated to " + limit + " bytes)\n");
                 }
-                writePayload(buffer.getPayload(), bos, encoding); 
+                writePayload(buffer.getPayload(), bos, encoding, ct); 
                     
                 bos.close();
             } catch (Exception e) {

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java?rev=982846&r1=982845&r2=982846&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
Fri Aug  6 01:30:04 2010
@@ -133,7 +133,7 @@ public class LoggingOutInterceptor exten
                 }
             }
             try {
-                writePayload(buffer.getPayload(), cos, encoding); 
+                writePayload(buffer.getPayload(), cos, encoding, ct); 
             } catch (Exception ex) {
                 //ignore
             }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java?rev=982846&r1=982845&r2=982846&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java
Fri Aug  6 01:30:04 2010
@@ -28,11 +28,11 @@ import java.util.logging.Logger;
 
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.io.CacheAndWriteOutputStream;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.io.CachedOutputStreamCallback;
@@ -80,14 +80,7 @@ public class PrettyLoggingOutInterceptor
         public void onClose(CachedOutputStream cos) {
             
             try {
-                TransformerFactory tfactory = TransformerFactory.newInstance();
-                try { 
-                    tfactory.setAttribute("indent-number", "2");
-                } catch (Exception ex) {
-                    //ignore
-                }
-                Transformer serializer;
-                serializer = tfactory.newTransformer();
+                Transformer serializer = XMLUtils.newTransformer(2);
                 //Setup indenting to "pretty print"
                 serializer.setOutputProperty(OutputKeys.INDENT, "yes");
                 serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",
"2");



Mime
View raw message