You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by an...@apache.org on 2006/11/27 17:50:12 UTC

svn commit: r479685 - in /incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor: LoggingInInterceptor.java LoggingOutInterceptor.java

Author: andreasmyth
Date: Mon Nov 27 08:50:11 2006
New Revision: 479685

URL: http://svn.apache.org/viewvc?view=rev&rev=479685
Log:
[JIRA CXF-169] Replaced LoggingOutInterceptor by a version that can be used in JAX-WS frontend (previous implementation caused ClassCastException in SOAPHandlerInterceptor). Logs message as it is made available to the SOAPHandlerInteptor, but not changes made to the message by any installed JAX-WS protocol handlers.

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

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java?view=diff&rev=479685&r1=479684&r2=479685
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java Mon Nov 27 08:50:11 2006
@@ -58,7 +58,7 @@
             is.close();
             bos.close();
 
-            LOG.info("Message: " + bos.toString());
+            LOG.info("Inbound message: " + bos.toString());
 
             message.setContent(InputStream.class, new ByteArrayInputStream(bos.toByteArray()));
 

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java?view=diff&rev=479685&r1=479684&r2=479685
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java Mon Nov 27 08:50:11 2006
@@ -20,13 +20,15 @@
 package org.apache.cxf.interceptor;
 
 import java.io.ByteArrayOutputStream;
-import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Collections;
 import java.util.Set;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.io.AbstractCachedOutputStream;
+import org.apache.cxf.io.CachedOutputStreamCallback;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
@@ -48,9 +50,9 @@
         if (os == null) {
             return;
         }
-
-        ForkOutputStream fos = new ForkOutputStream(os);
-        message.setContent(OutputStream.class, fos);
+        if (os instanceof AbstractCachedOutputStream) {
+            ((AbstractCachedOutputStream)os).registerCallback(new LoggingCallback());
+        }
     }
 
     @Override
@@ -58,50 +60,27 @@
         return before;
     }
 
-    /**
-      * Output stream that multicasts its data to several underlying output streams.
-     */
-    public class ForkOutputStream extends OutputStream {
+    class LoggingCallback implements CachedOutputStreamCallback {
 
-        final OutputStream original;
-        final ByteArrayOutputStream bos;
-    
-        public ForkOutputStream(OutputStream o) {
-            original = o;
-            bos = new ByteArrayOutputStream();
-        }
-    
-        @Override
-        public void close() throws IOException {
-            bos.close();
-            LOG.info("Message: " + bos.toString());
-            original.close();
-        }
+        private boolean flushed;
 
-        @Override
-        public void flush() throws IOException {
-            bos.flush();
-            original.flush();
+        public void onFlush(AbstractCachedOutputStream cos) {  
+            if (!flushed) {
+                OutputStream os = cos.getOut();
+                if (os instanceof ByteArrayOutputStream) {
+                    ByteArrayOutputStream bos = (ByteArrayOutputStream)os;
+                    if (LOG.isLoggable(Level.INFO)) {
+                        LOG.info("Outbound message: " + bos.toString());
+                    }
+                }
+                flushed = true;
+                // any further changes will not be logged
+            }
         }
-
-        @Override
-        public void write(byte[] b, int off, int len) throws IOException {
-            bos.write(b, off, len);
-            original.write(b, off, len);
+        
+        public void onClose(AbstractCachedOutputStream cos) {
         }
-    
-        @Override
-        public void write(byte[] b) throws IOException {
-            bos.write(b);
-            original.write(b);
-        }
-    
-        @Override
-        public void write(int b) throws IOException {
-            bos.write(b);
-            original.write(b);
-        }
-    }
-    
+        
+    } 
     
 }