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/08 01:07:33 UTC

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

Author: veithen
Date: Sun Jun  7 23:07:33 2009
New Revision: 782477

URL: http://svn.apache.org/viewvc?rev=782477&view=rev
Log:
Fixed bug in chunked encoding.

Modified:
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/ChunkedEncoder.java
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpFilter.java
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/engine/InterceptorTest.java
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/engine/TestUtil.java

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/ChunkedEncoder.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/http/ChunkedEncoder.java?rev=782477&r1=782476&r2=782477&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/ChunkedEncoder.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/ChunkedEncoder.java Sun Jun  7 23:07:33 2009
@@ -28,12 +28,13 @@
     public void invoke(Stream stream) {
         int av = stream.available();
         if (av > 0 || stream.isEndOfStream()) {
-            stream.skipAll();
             StreamUtil.insertAsciiString(stream, "\r\n");
             StreamUtil.insertAsciiString(stream, Integer.toString(av, 16));
             StreamUtil.insertAsciiString(stream, "\r\n");
             if (av == 0) {
                 StreamUtil.insertAsciiString(stream, "\r\n");
+            } else {
+                stream.skipAll();
             }
         }
     }

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpFilter.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/http/HttpFilter.java?rev=782477&r1=782476&r2=782477&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpFilter.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpFilter.java Sun Jun  7 23:07:33 2009
@@ -100,9 +100,7 @@
                 }
                 case STATE_CONTENT: {
                     if (transferDecoder != null) {
-                        Stream decoderStream =
-                                decode ? stream : new ReadOnlyStream(stream);
-                        if (transferDecoder.process(decoderStream)) {
+                        if (transferDecoder.process(stream)) {
                             state = STATE_COMPLETE;
                             if (contentFilterChain != null) {
                                 for (int i=0; i<contentFilterChain.length; i++) {

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/engine/InterceptorTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/engine/InterceptorTest.java?rev=782477&r1=782476&r2=782477&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/engine/InterceptorTest.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/engine/InterceptorTest.java Sun Jun  7 23:07:33 2009
@@ -25,14 +25,13 @@
 import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.StringEntity;
 import org.apache.ws.commons.tcpmon.core.filter.ReplaceFilter;
 import org.apache.ws.commons.tcpmon.core.filter.StreamFilter;
 import org.apache.ws.commons.tcpmon.core.filter.mime.ContentFilterFactory;
 import org.mortbay.jetty.Server;
 
 public class InterceptorTest extends TestCase {
-    public void testWithContentFilter() throws Exception {
+    private void testWithContentFilter(boolean chunked) throws Exception {
         Server server = TestUtil.createServer(5555);
         server.start();
         
@@ -56,7 +55,7 @@
         
         HttpClient client = TestUtil.createClient(config);
         HttpPost request = new HttpPost(TestUtil.getBaseUri(config, server) + "/echo");
-        request.setEntity(new StringEntity("test-pattern-test"));
+        request.setEntity(TestUtil.createStringEntity("test-pattern-test", "utf-8", chunked));
         HttpResponse response = client.execute(request);
         assertEquals("test-replacement-test", TestUtil.getResponseAsString(response));
         
@@ -64,4 +63,12 @@
         
         server.stop();
     }
+
+    public void testWithContentFilterNotChunked() throws Exception {
+        testWithContentFilter(false);
+    }
+
+    public void testWithContentFilterChunked() throws Exception {
+        testWithContentFilter(true);
+    }
 }

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/engine/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/engine/TestUtil.java?rev=782477&r1=782476&r2=782477&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/engine/TestUtil.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/test/java/org/apache/ws/commons/tcpmon/core/engine/TestUtil.java Sun Jun  7 23:07:33 2009
@@ -16,15 +16,22 @@
 
 package org.apache.ws.commons.tcpmon.core.engine;
 
+import java.io.ByteArrayInputStream;
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpEntity;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
 import org.apache.http.conn.params.ConnRoutePNames;
+import org.apache.http.entity.AbstractHttpEntity;
+import org.apache.http.entity.InputStreamEntity;
+import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.protocol.HTTP;
 import org.mortbay.http.HttpContext;
 import org.mortbay.http.SocketListener;
 import org.mortbay.jetty.Server;
@@ -72,4 +79,14 @@
             in.close();
         }
     }
+    
+    public static HttpEntity createStringEntity(String s, String charset, boolean chunked) throws UnsupportedEncodingException {
+        if (chunked) {
+            AbstractHttpEntity entity = new InputStreamEntity(new ByteArrayInputStream(s.getBytes(charset)), -1);
+            entity.setContentType(HTTP.PLAIN_TEXT_TYPE + HTTP.CHARSET_PARAM + charset);
+            return entity;
+        } else {
+            return new StringEntity(s, charset);
+        }
+    }
 }