From: Roger Meier Date: Sat, 22 Dec 2012 18:46:28 +0000 (+0100) Subject: THRIFT-1641 Thrift 0.8 not compatible with Android HttpClient X-Git-Tag: 0.9.1~217^2~3 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=8fa8aeac9a0f2ff4f11ac0ef73fc677bebd7a75f;p=common%2Fthrift.git THRIFT-1641 Thrift 0.8 not compatible with Android HttpClient Patch: Darin Tay --- diff --git a/lib/java/src/org/apache/thrift/transport/THttpClient.java b/lib/java/src/org/apache/thrift/transport/THttpClient.java index 30f59eee..5a5b37c7 100644 --- a/lib/java/src/org/apache/thrift/transport/THttpClient.java +++ b/lib/java/src/org/apache/thrift/transport/THttpClient.java @@ -29,6 +29,7 @@ import java.net.HttpURLConnection; import java.util.HashMap; import java.util.Map; +import org.apache.http.HttpEntity; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; @@ -36,7 +37,6 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.params.CoreConnectionPNames; -import org.apache.http.util.EntityUtils; /** * HTTP implementation of the TTransport interface. Used for working with a @@ -197,6 +197,22 @@ public class THttpClient extends TTransport { requestBuffer_.write(buf, off, len); } + /** + * copy from org.apache.http.util.EntityUtils#consume. Android has it's own httpcore + * that doesn't have a consume. + */ + private static void consume(final HttpEntity entity) throws IOException { + if (entity == null) { + return; + } + if (entity.isStreaming()) { + InputStream instream = entity.getContent(); + if (instream != null) { + instream.close(); + } + } + } + private void flushUsingHttpClient() throws TTransportException { if (null == this.client) { @@ -266,7 +282,7 @@ public class THttpClient extends TTransport { try { // Indicate we're done with the content. - EntityUtils.consume(response.getEntity()); + consume(response.getEntity()); } catch (IOException ioe) { // We ignore this exception, it might only mean the server has no // keep-alive capability.