Class HttpClientUtils


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

      • closeQuietly

        public static void closeQuietly​(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