Added a timeout to the client connection to prevent hanging.

Added some cleanup codes.

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@383814 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adrian T. Co 2006-03-07 07:39:39 +00:00
parent cd0fb615de
commit 4af9754653
1 changed files with 9 additions and 0 deletions

View File

@ -47,6 +47,8 @@ import java.net.URI;
public class HttpClientTransport extends HttpTransportSupport {
private static final Log log = LogFactory.getLog(HttpClientTransport.class);
public static final int MAX_CLIENT_TIMEOUT = 20000;
private HttpClient sendHttpClient;
private HttpClient receiveHttpClient;
private String clientID;
@ -69,6 +71,7 @@ public class HttpClientTransport extends HttpTransportSupport {
httpMethod.setRequestBody(getTextWireFormat().toString(command));
try {
HttpClient client = getSendHttpClient();
client.setTimeout(MAX_CLIENT_TIMEOUT);
int answer = client.executeMethod(httpMethod);
if (answer != HttpStatus.SC_OK) {
throw new IOException("Failed to post command: " + command + " as response was: " + answer);
@ -77,6 +80,9 @@ public class HttpClientTransport extends HttpTransportSupport {
}
catch (IOException e) {
throw IOExceptionSupport.create("Could not post command: " + command + " due to: " + e, e);
} finally {
httpMethod.getResponseBody();
httpMethod.releaseConnection();
}
}
@ -116,6 +122,9 @@ public class HttpClientTransport extends HttpTransportSupport {
}
catch (IOException e) {
log.warn("Failed to perform GET on: " + remoteUrl + " due to: " + e, e);
} finally {
httpMethod.getResponseBody();
httpMethod.releaseConnection();
}
}
}