class ExternalServiceHealthCheck extends HealthCheck {

  @Override
  public Result check() throws Exception {
    LOGGER.debug("Check if Endpoint is available (URL: {})", this.url);

    int statusCode;

    try {
      HttpURLConnection connection = openConnection.call(url);

      try (AutoCloseable ignored = connection::disconnect) {
        connection.setConnectTimeout(timeout);
        connection.setReadTimeout(timeout);
        connection.setRequestMethod(requestMethod);
        statusCode = connection.getResponseCode();
        if (HttpStatus.isSuccess(statusCode)) {
          LOGGER.debug("Endpoint is available (URL: {})", this.url);
          return Result.healthy();
        }
      }
    } catch (IOException exception) {
      LOGGER.warn(
          "IOException (Details in Logs) - Endpoint not available (URL: {})", this.url, exception);
      return Result.unhealthy(
          "IOException (Details in Logs) - Endpoint not available (URL: %s)", this.url);
    }

    LOGGER.warn("Endpoint not available (URL: {})", this.url);
    return Result.unhealthy(
        "Endpoint not available (URL: %s, StatusCode: %s)", this.url, statusCode);
  }

  public  ExternalServiceHealthCheck(String url, int timeoutMillis);
  public  ExternalServiceHealthCheck(String requestMethod, String url, int timeoutMillis);
  @SuppressWarnings("WeakerAccess") public  ExternalServiceHealthCheck(
      String url, int timeoutMillis, OpenConnectionFunction openConnection);
  public  ExternalServiceHealthCheck(
      String requestMethod, String url, int timeoutMillis, OpenConnectionFunction openConnection);

}