You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by jf...@apache.org on 2013/09/06 19:09:55 UTC

git commit: THRIFT-2169: JavaME Library causes "java.io.IOException: No Response Entries Available" after using client for some time Client: javame Patch: Omkar Aradhya K S

Updated Branches:
  refs/heads/master ba6825583 -> a6a32a56f


THRIFT-2169: JavaME Library causes "java.io.IOException: No Response Entries Available" after using client for some time
Client: javame
Patch: Omkar Aradhya K S

Ensures the connection is closed. Also added spacing cleanup.


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/a6a32a56
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/a6a32a56
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/a6a32a56

Branch: refs/heads/master
Commit: a6a32a56fb565d155fd9ae3826b6bbdede6688be
Parents: ba68255
Author: jfarrell <jf...@apache.org>
Authored: Fri Sep 6 13:07:56 2013 -0400
Committer: jfarrell <jf...@apache.org>
Committed: Fri Sep 6 13:07:56 2013 -0400

----------------------------------------------------------------------
 .../apache/thrift/transport/THttpClient.java    | 108 +++++++++----------
 1 file changed, 52 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/a6a32a56/lib/javame/src/org/apache/thrift/transport/THttpClient.java
----------------------------------------------------------------------
diff --git a/lib/javame/src/org/apache/thrift/transport/THttpClient.java b/lib/javame/src/org/apache/thrift/transport/THttpClient.java
index 451a2e5..e6ffba4 100644
--- a/lib/javame/src/org/apache/thrift/transport/THttpClient.java
+++ b/lib/javame/src/org/apache/thrift/transport/THttpClient.java
@@ -42,6 +42,8 @@ public class THttpClient extends TTransport {
 
   private InputStream inputStream_ = null;
 
+  private HttpConnection connection = null;
+
   private int connectTimeout_ = 0;
 
   private int readTimeout_ = 0;
@@ -49,7 +51,7 @@ public class THttpClient extends TTransport {
   private Hashtable customHeaders_ = null;
 
   public THttpClient(String url) throws TTransportException {
-                url_ = url;
+    url_ = url;
   }
 
   public void setConnectTimeout(int timeout) {
@@ -81,6 +83,14 @@ public class THttpClient extends TTransport {
       }
       inputStream_ = null;
     }
+
+    if (connection != null) {
+      try {
+        connection.close();
+      } catch (IOException ioe) {
+      }
+      connection = null;
+    }
   }
 
   public boolean isOpen() {
@@ -106,62 +116,48 @@ public class THttpClient extends TTransport {
     requestBuffer_.write(buf, off, len);
   }
   
-    public void flush() throws TTransportException {
+  public void flush() throws TTransportException {
     // Extract request and reset buffer
-        byte[] data = requestBuffer_.toByteArray();
-        requestBuffer_.reset();
-
-        try {
-            // Create connection object
-            HttpConnection connection = (HttpConnection)Connector.open(url_);
-    
-            // Timeouts, only if explicitly set
-            if (connectTimeout_ > 0) {
-            //  XXX: not available
-            //  connection.setConnectTimeout(connectTimeout_);
-            }   
-            if (readTimeout_ > 0) {
-            //  XXX: not available
-            //  connection.setReadTimeout(readTimeout_);
-            }
-    
-            // Make the request
-            connection.setRequestMethod("POST");
-            connection.setRequestProperty("Content-Type", "application/x-thrift");
-            connection.setRequestProperty("Accept", "application/x-thrift");
-            connection.setRequestProperty("User-Agent", "JavaME/THttpClient");
-
-            connection.setRequestProperty("Connection", "Keep-Alive");
-            connection.setRequestProperty("Keep-Alive", "5000");
-            connection.setRequestProperty("Http-version", "HTTP/1.1");
-            connection.setRequestProperty("Cache-Control", "no-transform");
-
-
-            if (customHeaders_ != null) {
-                for (Enumeration e = customHeaders_.keys() ; e.hasMoreElements() ;) {
-                    String key = (String)e.nextElement();
-                    String value = (String)customHeaders_.get(key);
-                    connection.setRequestProperty(key, value);
-                }
-            }
-            // connection.setDoOutput(true);
-            //  connection.connect();
-    
-            OutputStream os = connection.openOutputStream();
-            os.write(data);
-            os.close();
-
-            int responseCode = connection.getResponseCode();
-            if (responseCode != HttpConnection.HTTP_OK) {
-                throw new TTransportException("HTTP Response code: " + responseCode);
-            }
-
-            // Read the responses
-            inputStream_ = connection.openInputStream();
-
-        } catch (IOException iox) {
-            System.out.println(iox.toString());
-            throw new TTransportException(iox);
+    byte[] data = requestBuffer_.toByteArray();
+    requestBuffer_.reset();
+
+    try {
+      // Create connection object
+      connection = (HttpConnection)Connector.open(url_);
+  
+      // Make the request
+      connection.setRequestMethod("POST");
+      connection.setRequestProperty("Content-Type", "application/x-thrift");
+      connection.setRequestProperty("Accept", "application/x-thrift");
+      connection.setRequestProperty("User-Agent", "JavaME/THttpClient");
+
+      connection.setRequestProperty("Connection", "Keep-Alive");
+      connection.setRequestProperty("Keep-Alive", "5000");
+      connection.setRequestProperty("Http-version", "HTTP/1.1");
+      connection.setRequestProperty("Cache-Control", "no-transform");
+
+      if (customHeaders_ != null) {
+        for (Enumeration e = customHeaders_.keys() ; e.hasMoreElements() ;) {
+          String key = (String)e.nextElement();
+          String value = (String)customHeaders_.get(key);
+          connection.setRequestProperty(key, value);
         }
+      }
+  
+      OutputStream os = connection.openOutputStream();
+      os.write(data);
+      os.close();
+
+      int responseCode = connection.getResponseCode();
+      if (responseCode != HttpConnection.HTTP_OK) {
+        throw new TTransportException("HTTP Response code: " + responseCode);
+      }
+
+      // Read the responses
+      inputStream_ = connection.openInputStream();
+    } catch (IOException iox) {
+      System.out.println(iox.toString());
+      throw new TTransportException(iox);
     }
+  }
 }