summaryrefslogtreecommitdiff
path: root/lib/javame
diff options
context:
space:
mode:
authorjfarrell <jfarrell@apache.org>2013-09-06 13:07:56 -0400
committerjfarrell <jfarrell@apache.org>2013-09-06 13:07:56 -0400
commita6a32a56fb565d155fd9ae3826b6bbdede6688be (patch)
tree34809dbf0a6639af1f633ee4a201b43b66b93f9c /lib/javame
parentba6825583432194e20851824e03d06f4953874af (diff)
downloadthrift-a6a32a56fb565d155fd9ae3826b6bbdede6688be.tar.gz
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.
Diffstat (limited to 'lib/javame')
-rw-r--r--lib/javame/src/org/apache/thrift/transport/THttpClient.java108
1 files changed, 52 insertions, 56 deletions
diff --git a/lib/javame/src/org/apache/thrift/transport/THttpClient.java b/lib/javame/src/org/apache/thrift/transport/THttpClient.java
index 451a2e52b..e6ffba4e5 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);
}
+ }
}