cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r596558 - in /incubator/cxf/trunk: rt/core/src/main/java/org/apache/cxf/interceptor/ systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/
Date Tue, 20 Nov 2007 07:33:00 GMT
Author: mmao
Date: Mon Nov 19 23:33:00 2007
New Revision: 596558

URL: http://svn.apache.org/viewvc?rev=596558&view=rev
Log:
* Add the printWriter into the logging in/out interceptors, if it's not null, log to the writer
passed in
* Re-Enable the tests


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
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/WSAClientServerTest.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?rev=596558&r1=596557&r2=596558&view=diff
==============================================================================
--- 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 19 23:33:00 2007
@@ -20,6 +20,7 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintWriter;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -39,7 +40,7 @@
     private static final Logger LOG = LogUtils.getL7dLogger(LoggingInInterceptor.class);
 
     private int limit = 100 * 1024;
-    private boolean enabled;
+    private PrintWriter writer;
     
     
     public LoggingInInterceptor() {
@@ -50,9 +51,9 @@
         limit = lim;
     }
 
-    public LoggingInInterceptor(boolean b) {
+    public LoggingInInterceptor(PrintWriter w) {
         this();
-        this.enabled = b;
+        this.writer = w;
     }
     
     public void setLimit(int lim) {
@@ -64,7 +65,7 @@
     }    
 
     public void handleMessage(Message message) throws Fault {
-        if (enabled || LOG.isLoggable(Level.INFO)) {
+        if (writer != null || LOG.isLoggable(Level.INFO)) {
             logging(message);
         }
     }
@@ -112,7 +113,9 @@
             }
         }
 
-        if (LOG.isLoggable(Level.INFO)) {
+        if (writer != null) {
+            writer.write(buffer.toString());
+        } else if (LOG.isLoggable(Level.INFO)) {
             LOG.info(buffer.toString());
         }
     }

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?rev=596558&r1=596557&r2=596558&view=diff
==============================================================================
--- 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 19 23:33:00 2007
@@ -20,6 +20,7 @@
 package org.apache.cxf.interceptor;
 
 import java.io.OutputStream;
+import java.io.PrintWriter;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -39,7 +40,7 @@
     private static final Logger LOG = LogUtils.getL7dLogger(LoggingOutInterceptor.class);

 
     private int limit = 100 * 1024;
-    private boolean enabled;
+    private PrintWriter writer;
     
     public LoggingOutInterceptor() {
         super(Phase.PRE_STREAM);
@@ -50,9 +51,9 @@
         limit = lim;
     }
 
-    public LoggingOutInterceptor(boolean b) {
+    public LoggingOutInterceptor(PrintWriter w) {
         this();
-        this.enabled = b;
+        this.writer = w;
     }
     
     public void setLimit(int lim) {
@@ -69,7 +70,7 @@
             return;
         }
 
-        if (LOG.isLoggable(Level.INFO) || enabled) {
+        if (LOG.isLoggable(Level.INFO) || writer != null) {
             // Write the output while caching it for the log message
             final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(os);
             message.setContent(OutputStream.class, newOut);
@@ -104,7 +105,9 @@
                 //ignore
             }
 
-            if (LOG.isLoggable(Level.INFO)) {
+            if (writer != null) {
+                writer.write(buffer.toString());
+            } else if (LOG.isLoggable(Level.INFO)) {
                 LOG.info(buffer.toString());
             }
         }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/WSAClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/WSAClientServerTest.java?rev=596558&r1=596557&r2=596558&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/WSAClientServerTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/WSAClientServerTest.java
Mon Nov 19 23:33:00 2007
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.systest.ws.addr_feature;
 
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
 import java.net.URL;
 import javax.xml.namespace.QName;
 import javax.xml.ws.soap.AddressingFeature;
@@ -37,17 +39,9 @@
     private final QName serviceName = new QName("http://apache.org/cxf/systest/ws/addr_feature/",
                                                 "AddNumbersService");
 
-    private LoggingInInterceptor in;
-    private LoggingOutInterceptor out;
-
     @Before
     public void setUp() throws Exception {
         createBus();
-
-        in = new LoggingInInterceptor(true);
-        this.bus.getInInterceptors().add(in);
-        out = new LoggingOutInterceptor(true);
-        this.bus.getOutInterceptors().add(out);
     }
 
     @BeforeClass
@@ -55,8 +49,29 @@
         assertTrue("server did not launch correctly", launchServer(Server.class));
     }
 
+    private ByteArrayOutputStream setupInLogging() {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        PrintWriter writer = new PrintWriter(bos);
+        LoggingInInterceptor in = new LoggingInInterceptor(writer);
+        this.bus.getInInterceptors().add(in);
+        return bos;
+    }
+
+    private ByteArrayOutputStream setupOutLogging() {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        PrintWriter writer = new PrintWriter(bos);
+
+        LoggingOutInterceptor out = new LoggingOutInterceptor(writer);
+        this.bus.getOutInterceptors().add(out);
+
+        return bos;
+    }
+
     @Test
     public void testNoWsaFeature() throws Exception {
+        ByteArrayOutputStream input = setupInLogging();
+        ByteArrayOutputStream output = setupOutLogging();
+
         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
         factory.setServiceClass(AddNumbersPortType.class);
         factory.setAddress("http://localhost:9091/jaxws/add");
@@ -64,17 +79,18 @@
 
         assertEquals(3, port.addNumbers(1, 2));
         
-        /*
         String expectedOut = "<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>";
         String expectedIn = "<RelatesTo xmlns=\"http://www.w3.org/2005/08/addressing\">";
 
-        assertTrue(out.getBuffer().getPayload().toString().indexOf(expectedOut) == -1);
-        assertTrue(in.getBuffer().getPayload().toString().indexOf(expectedIn) == -1);
-        */
+        assertTrue(output.toString().indexOf(expectedOut) == -1);
+        assertTrue(input.toString().indexOf(expectedIn) == -1);
     }
 
     @Test
     public void testCxfWsaFeature() throws Exception {
+        ByteArrayOutputStream input = setupInLogging();
+        ByteArrayOutputStream output = setupOutLogging();
+
         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
         factory.setServiceClass(AddNumbersPortType.class);
         factory.setAddress("http://localhost:9091/jaxws/add");
@@ -82,29 +98,28 @@
         AddNumbersPortType port = (AddNumbersPortType) factory.create();
 
         assertEquals(3, port.addNumbers(1, 2));
-        
-        /*
+
         String expectedOut = "<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>";
         String expectedIn = "<RelatesTo xmlns=\"http://www.w3.org/2005/08/addressing\">";
 
-        assertTrue(out.getBuffer().getPayload().toString().indexOf(expectedOut) != -1);
-        assertTrue(in.getBuffer().getPayload().toString().indexOf(expectedIn) != -1);
-        */
+        assertTrue(output.toString().indexOf(expectedOut) == -1);
+        assertTrue(input.toString().indexOf(expectedIn) == -1);
     }
 
     @Test
     public void testJaxwsWsaFeature() throws Exception {
+        ByteArrayOutputStream input = setupInLogging();
+        ByteArrayOutputStream output = setupOutLogging();
+
         AddNumbersPortType port = getPort();
 
         assertEquals(3, port.addNumbers(1, 2));
 
-        /*
         String expectedOut = "<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>";
         String expectedIn = "<RelatesTo xmlns=\"http://www.w3.org/2005/08/addressing\">";
 
-        assertTrue(out.getBuffer().getPayload().toString().indexOf(expectedOut) != -1);
-        assertTrue(in.getBuffer().getPayload().toString().indexOf(expectedIn) != -1);
-        */
+        assertTrue(output.toString().indexOf(expectedOut) == -1);
+        assertTrue(input.toString().indexOf(expectedIn) == -1);
     }
 
     private AddNumbersPortType getPort() {



Mime
View raw message