Class HttpClientUtils

java.lang.Object
org.apache.http.client.utils.HttpClientUtils

public class HttpClientUtils extends Object
Convenience methods for closing response and client objects.
Since:
4.2
  • Method Details

    • closeQuietly

      public static void closeQuietly(org.apache.http.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 - the HttpResponse to release resources, may be null or already closed.
      Since:
      4.2
    • closeQuietly

      public static void closeQuietly(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 - the HttpResponse to release resources, may be null or already closed.
      Since:
      4.3
    • closeQuietly

      public static void closeQuietly(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 - the HttpClient to close, may be null or already closed.
      Since:
      4.2