Source:
private boolean ping() throws IOException { RequestConfig requestConfig = RequestConfig.custom() .setSocketTimeout(HTTP_PING_TIMEOUT) .setConnectTimeout(HTTP_PING_TIMEOUT) .setConnectionRequestTimeout(HTTP_PING_TIMEOUT) .setRedirectsEnabled(false) .build(); CloseableHttpClient httpClient; if (allowAllHosts) { SSLContextBuilder builder = new SSLContextBuilder(); try { builder.loadTrustMaterial(new TrustAllStrategy()); SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE); httpClient = HttpClientBuilder.create() .setDefaultRequestConfig(requestConfig) .setRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_CLIENT_RETRIES, false)) .setSSLSocketFactory(socketFactory) .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) .build(); } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { throw new IOException("Unable to set self signed strategy on http wait: " + e, e); } } else { httpClient = HttpClientBuilder.create() .setDefaultRequestConfig(requestConfig) .setRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_CLIENT_RETRIES, false)) .build(); } try (CloseableHttpResponse response = httpClient.execute(RequestBuilder.create(method.toUpperCase()).setUri(url).build())) { int responseCode = response.getStatusLine().getStatusCode(); if (responseCode == 501) { throw new IllegalArgumentException("Invalid or not supported HTTP method '" + method.toUpperCase() + "' for checking " + url); } return responseCode >= statusMin && responseCode <= statusMax; } finally { httpClient.close(); } }

Target:
private boolean ping() throws IOException { RequestConfig requestConfig = RequestConfig.custom() .setSocketTimeout(HTTP_PING_TIMEOUT) .setConnectTimeout(HTTP_PING_TIMEOUT) .setConnectionRequestTimeout(HTTP_PING_TIMEOUT) .setRedirectsEnabled(false) .build(); CloseableHttpClient httpClient; if (allowAllHosts) { SSLContextBuilder builder = new SSLContextBuilder(); try { builder.loadTrustMaterial(new TrustAllStrategy()); SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE); httpClient = HttpClientBuilder.create() .setDefaultRequestConfig(requestConfig) .setRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_CLIENT_RETRIES, false)) .setSSLSocketFactory(socketFactory) .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) .build(); } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { throw new IOException("Unable to set self signed strategy on http wait: " + e, e); } } else { httpClient = HttpClientBuilder.create() .setDefaultRequestConfig(requestConfig) .setRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_CLIENT_RETRIES, false)) .build(); } try (CloseableHttpResponse response = httpClient.execute(RequestBuilder.create(method.toUpperCase()).setUri(url).build())) { int responseCode = response.getStatusLine().getStatusCode(); if (responseCode == HttpURLConnection.HTTP_NOT_IMPLEMENTED) { throw new IllegalArgumentException("Invalid or not supported HTTP method '" + method.toUpperCase() + "' for checking " + url); } return responseCode >= statusMin && responseCode <= statusMax; } finally { httpClient.close(); } }