Top Description Constructors Methods
org.apache.http.client.utils

public Class HttpClientUtils

extends Object
Class Inheritance
Imports
java.io.Closeable, .IOException, org.apache.http.HttpEntity, .HttpResponse, org.apache.http.client.HttpClient, org.apache.http.client.methods.CloseableHttpResponse, org.apache.http.util.EntityUtils

Convenience methods for closing response and client objects.
Since
4.2

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
closeQuietly(final HttpResponse
the HttpResponse to release resources, may be null or already closed.
response
)

Unconditionally close a response.

public static void
closeQuietly(final CloseableHttpResponse
the HttpResponse to release resources, may be null or already closed.
response
)

Unconditionally close a response.

public static void
closeQuietly(final HttpClient
the HttpClient to close, may be null or already closed.
httpClient
)

Unconditionally close a httpClient.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

HttpClientUtilsback to summary
private HttpClientUtils()

Method Detail

closeQuietlyback to summary
public static void closeQuietly(final HttpResponse response)

Unconditionally close a response.

Example Code:

HttpResponse httpResponse = null;
try {
    httpResponse = httpClient.execute(httpGet);
} catch (Exception e) {
    // error handling
} finally {
    HttpClientUtils.closeQuietly(httpResponse);
}
Parameters
response:HttpResponse

the HttpResponse to release resources, may be null or already closed.

Since
4.2
closeQuietlyback to summary
public static void closeQuietly(final CloseableHttpResponse response)

Unconditionally close a response.

Example Code:

HttpResponse httpResponse = null;
try {
    httpResponse = httpClient.execute(httpGet);
} catch (Exception e) {
    // error handling
} finally {
    HttpClientUtils.closeQuietly(httpResponse);
}
Parameters
response:CloseableHttpResponse

the HttpResponse to release resources, may be null or already closed.

Since
4.3
closeQuietlyback to summary
public static void closeQuietly(final HttpClient httpClient)

Unconditionally close a httpClient. Shuts down the underlying connection manager and releases the resources.

Example Code:

HttpClient httpClient = HttpClients.createDefault();
try {
  httpClient.execute(request);
} catch (Exception e) {
  // error handling
} finally {
  HttpClientUtils.closeQuietly(httpClient);
}
Parameters
httpClient:HttpClient

the HttpClient to close, may be null or already closed.

Since
4.2