Author: bryanduxbury
Date: Mon Jun 20 21:42:17 2011
New Revision: 1137794

URL: http://svn.apache.org/viewvc?rev=1137794&view=rev
Log:
THRIFT-1211. java: When using THttpClient, non 200 responses leave the 
connection open

This patch reorders the code so that we can close the connection in the case of 
an error.

Patch: Mathias Herberts

Modified:
    thrift/trunk/lib/java/src/org/apache/thrift/transport/THttpClient.java

Modified: thrift/trunk/lib/java/src/org/apache/thrift/transport/THttpClient.java
URL: 
http://svn.apache.org/viewvc/thrift/trunk/lib/java/src/org/apache/thrift/transport/THttpClient.java?rev=1137794&r1=1137793&r2=1137794&view=diff
==============================================================================
--- thrift/trunk/lib/java/src/org/apache/thrift/transport/THttpClient.java 
(original)
+++ thrift/trunk/lib/java/src/org/apache/thrift/transport/THttpClient.java Mon 
Jun 20 21:42:17 2011
@@ -233,6 +233,13 @@ public class THttpClient extends TTransp
       
       HttpResponse response = this.client.execute(this.host, post);
       int responseCode = response.getStatusLine().getStatusCode();
+
+      //      
+      // Retrieve the inputstream BEFORE checking the status code so
+      // resources get freed in the finally clause.
+      //
+
+      is = response.getEntity().getContent();
       
       if (responseCode != HttpStatus.SC_OK) {
         throw new TTransportException("HTTP Response code: " + responseCode);
@@ -245,8 +252,6 @@ public class THttpClient extends TTransp
       // Proceeding differently might lead to exhaustion of connections and 
thus
       // to app failure.
       
-      is = response.getEntity().getContent();
-      
       byte[] buf = new byte[1024];
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       


Reply via email to