diff --git a/src/java/org/apache/httpclient/impl/DefaultResponseConsumedWatcher.java b/src/java/org/apache/httpclient/impl/DefaultResponseConsumedWatcher.java index b24ff8788..f4aa56ead 100644 --- a/src/java/org/apache/httpclient/impl/DefaultResponseConsumedWatcher.java +++ b/src/java/org/apache/httpclient/impl/DefaultResponseConsumedWatcher.java @@ -35,6 +35,7 @@ import org.apache.http.ConnectionReuseStrategy; import org.apache.http.HttpConnection; import org.apache.http.HttpResponse; import org.apache.http.impl.DefaultConnectionReuseStrategy; +import org.apache.http.protocol.HttpContext; /** *

@@ -50,9 +51,12 @@ public class DefaultResponseConsumedWatcher private final HttpConnection conn; private final HttpResponse response; + private final HttpContext context; public DefaultResponseConsumedWatcher( - final HttpConnection conn, final HttpResponse response) { + final HttpConnection conn, + final HttpResponse response, + final HttpContext context) { super(); if (conn == null) { throw new IllegalArgumentException("HTTP connection may not be null"); @@ -62,11 +66,12 @@ public class DefaultResponseConsumedWatcher } this.conn = conn; this.response = response; + this.context = context; } public void responseConsumed() { ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy(); - if (!s.keepAlive(this.conn, this.response)) { + if (!s.keepAlive(this.response, this.context)) { try { this.conn.close(); } catch (IOException ex) { diff --git a/src/test/org/apache/httpclient/impl/TestDefaultResponseConsumedWatcher.java b/src/test/org/apache/httpclient/impl/TestDefaultResponseConsumedWatcher.java index 97be7bf8c..f123b11b3 100644 --- a/src/test/org/apache/httpclient/impl/TestDefaultResponseConsumedWatcher.java +++ b/src/test/org/apache/httpclient/impl/TestDefaultResponseConsumedWatcher.java @@ -38,6 +38,8 @@ import org.apache.http.entity.BasicHttpEntity; import org.apache.http.impl.DefaultHttpParams; import org.apache.http.message.BasicHttpResponse; import org.apache.http.mockup.HttpConnectionMockup; +import org.apache.http.protocol.HttpContext; +import org.apache.http.protocol.HttpExecutionContext; import junit.framework.Test; import junit.framework.TestCase; @@ -63,14 +65,14 @@ public class TestDefaultResponseConsumedWatcher extends TestCase { public void testIllegalResponseArg() throws Exception { try { - new DefaultResponseConsumedWatcher(null, null); + new DefaultResponseConsumedWatcher(null, null, null); fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException ex) { // expected } try { new DefaultResponseConsumedWatcher( - new HttpConnectionMockup(), null); + new HttpConnectionMockup(), null, null); fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException ex) { // expected @@ -78,6 +80,7 @@ public class TestDefaultResponseConsumedWatcher extends TestCase { } public void testConnectionAutoClose() throws Exception { + HttpContext context = new HttpExecutionContext(null); byte[] data = new byte[] {'1', '2', '3'}; HttpConnection conn = new HttpConnectionMockup(); BasicHttpEntity entity = new BasicHttpEntity(); @@ -91,7 +94,8 @@ public class TestDefaultResponseConsumedWatcher extends TestCase { response.setEntity(entity); // Wrap the entity input stream - ResponseConsumedWatcher watcher = new DefaultResponseConsumedWatcher(conn, response); + ResponseConsumedWatcher watcher = new DefaultResponseConsumedWatcher( + conn, response, context); InputStream content = new AutoCloseInputStream(entity.getContent(), watcher); assertTrue(conn.isOpen()); while (content.read() != -1) {} @@ -99,6 +103,7 @@ public class TestDefaultResponseConsumedWatcher extends TestCase { } public void testConnectionKeepAlive() throws Exception { + HttpContext context = new HttpExecutionContext(null); byte[] data = new byte[] {'1', '2', '3'}; HttpConnection conn = new HttpConnectionMockup(); BasicHttpEntity entity = new BasicHttpEntity(); @@ -112,7 +117,8 @@ public class TestDefaultResponseConsumedWatcher extends TestCase { response.setEntity(entity); // Wrap the entity input stream - ResponseConsumedWatcher watcher = new DefaultResponseConsumedWatcher(conn, response); + ResponseConsumedWatcher watcher = new DefaultResponseConsumedWatcher( + conn, response, context); InputStream content = new AutoCloseInputStream(entity.getContent(), watcher); assertTrue(conn.isOpen());