You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2009/06/05 21:17:36 UTC

svn commit: r782107 - in /webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src: main/java/org/apache/ws/commons/tcpmon/core/filter/ test/java/org/apache/ws/commons/tcpmon/core/filter/

Author: veithen
Date: Fri Jun  5 19:17:36 2009
New Revision: 782107

URL: http://svn.apache.org/viewvc?rev=782107&view=rev
Log:
Fixed build break.

Added:
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/ErrorListener.java   (with props)
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/TestErrorListener.java   (with props)
Modified:
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/Pipeline.java
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilterTest.java
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/TestUtil.java

Added: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/ErrorListener.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/ErrorListener.java?rev=782107&view=auto
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/ErrorListener.java (added)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/ErrorListener.java Fri Jun  5 19:17:36 2009
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ws.commons.tcpmon.core.filter;
+
+public interface ErrorListener {
+    ErrorListener DEFAULT = new ErrorListener() {
+        public void error(StreamFilter filter, String description) {
+            System.out.println("Non fatal error in filter " + filter.getClass().getName() + ": " + description);
+        }
+    };
+    
+    void error(StreamFilter filter, String description);
+}

Propchange: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/ErrorListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/Pipeline.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/Pipeline.java?rev=782107&r1=782106&r2=782107&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/Pipeline.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/Pipeline.java Fri Jun  5 19:17:36 2009
@@ -317,8 +317,7 @@
         }
 
         public void error(String description) {
-            // TODO: for the moment, just to a System.out.println; we should report errors in the UI
-            System.out.println("Non fatal error in filter " + filter.getClass().getName() + ": " + description);
+            errorListener.error(filter, description);
         }
     }
     
@@ -344,6 +343,7 @@
     
     private final int bufferSize;
     private final LinkedList buffers = new LinkedList();
+    private ErrorListener errorListener = ErrorListener.DEFAULT;
     private StreamImpl first;
     private StreamImpl last;
     
@@ -366,6 +366,10 @@
         buffers.add(buffer);
     }
     
+    public void setErrorListener(ErrorListener errorListener) {
+        this.errorListener = errorListener == null ? ErrorListener.DEFAULT : errorListener;
+    }
+
     public void addFilter(StreamFilter filter) {
         StreamImpl node = new StreamImpl(filter);
         if (first == null) {

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilterTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilterTest.java?rev=782107&r1=782106&r2=782107&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilterTest.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/CharsetDecoderFilterTest.java Fri Jun  5 19:17:36 2009
@@ -22,12 +22,9 @@
 
 public class CharsetDecoderFilterTest extends TestCase {
     public void testMalformed() {
-        try {
-            TestUtil.filter(new CharsetDecoderFilter(new StringWriter(), "UTF-8"),
-                            new byte[] { (byte)255, 0 });
-            fail("Expected exception");
-        } catch (StreamException ex) {
-            // OK
-        }
+        TestErrorListener listener = new TestErrorListener();
+        TestUtil.filter(new CharsetDecoderFilter(new StringWriter(), "UTF-8"),
+                        new byte[] { (byte)255, 0 }, listener);
+        assertEquals(1, listener.getCount());
     }
 }

Added: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/TestErrorListener.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/TestErrorListener.java?rev=782107&view=auto
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/TestErrorListener.java (added)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/TestErrorListener.java Fri Jun  5 19:17:36 2009
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ws.commons.tcpmon.core.filter;
+
+public class TestErrorListener implements ErrorListener {
+    private int count;
+    
+    public void error(StreamFilter filter, String description) {
+        count++;
+    }
+
+    public int getCount() {
+        return count;
+    }
+}

Propchange: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/TestErrorListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/TestUtil.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/TestUtil.java?rev=782107&r1=782106&r2=782107&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/TestUtil.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/filter/TestUtil.java Fri Jun  5 19:17:36 2009
@@ -24,8 +24,11 @@
 public class TestUtil {
     private TestUtil() {}
     
-    public static byte[] filter(StreamFilter filter, byte[] in) {
+    public static byte[] filter(StreamFilter filter, byte[] in, ErrorListener errorListener) {
         Pipeline pipeline = new Pipeline();
+        if (errorListener != null) {
+            pipeline.setErrorListener(errorListener);
+        }
         pipeline.addFilter(filter);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         pipeline.addFilter(new Tee(baos));
@@ -40,6 +43,10 @@
         return baos.toByteArray();
     }
     
+    public static byte[] filter(StreamFilter filter, byte[] in) {
+        return filter(filter, in, null);
+    }
+    
     public static String filter(StreamFilter filter, String in, String charsetName) throws UnsupportedEncodingException {
         return new String(filter(filter, in.getBytes(charsetName)), charsetName);
     }