My application is leaking connections somehow, it runs fine for days
continually doing requests but then at some point timeout connections start
to occur continuously. I am using the ThreadSafeClientConnManager to do
requests. I execute http client to do a head request and to get a response.
The code is below. Are there any problems with it? What would be the best
logging options to enable to debug leaks? Thanks.
public Map<String, String> head(String publicUrl, int timeoutMillis) throws
IOException, HttpException
{
HttpHead method = new HttpHead(publicUrl);
configureMethod (method, timeoutMillis);
HttpResponse response = _httpClient.execute(method);
try
{
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200)
{
throw new HttpException(statusCode, publicUrl + " failed: " +
response.getStatusLine());
}
...
}
finally
{
method.abort();
}
}
@Override
public byte[] fetchBytes (String publicUrl, int timeoutMillis) throws
HttpException, IOException
{
HttpGet method = new HttpGet ( publicUrl );
configureMethod(method, timeoutMillis);
// Execute the method.
HttpResponse resp = _httpClient.execute(method);
int statusCode = resp.getStatusLine().getStatusCode();
if(statusCode != 200)
{
if(resp.getEntity() != null)
{
try
{
EntityUtils.consume(resp.getEntity());
}
catch(Exception ex) {} //dropped
}
throw new HttpException(statusCode, statusCode + " " + publicUrl + "
failed: " + resp.getStatusLine());
}
return EntityUtils.toByteArray(resp.getEntity());
}