/**
   * Create an {@link AsyncHttpClientConfig} instance based on the values from {@link
   * RepositorySystemSession}
   *
   * @param session {link RepositorySystemSession}
   * @return a configured instance of
   */
  private AsyncHttpClientConfig createConfig(
      RepositorySystemSession session, RemoteRepository repository, boolean useCompression) {
    AsyncHttpClientConfig.Builder configBuilder = new AsyncHttpClientConfig.Builder();

    String userAgent =
        ConfigUtils.getString(
            session,
            ConfigurationProperties.DEFAULT_USER_AGENT,
            ConfigurationProperties.USER_AGENT);
    if (!StringUtils.isEmpty(userAgent)) {
      configBuilder.setUserAgent(userAgent);
    }
    int connectTimeout =
        ConfigUtils.getInteger(
            session,
            ConfigurationProperties.DEFAULT_CONNECT_TIMEOUT,
            ConfigurationProperties.CONNECT_TIMEOUT);

    configBuilder.setConnectionTimeoutInMs(connectTimeout);
    configBuilder.setCompressionEnabled(useCompression);
    configBuilder.setFollowRedirects(true);
    configBuilder.setRequestTimeoutInMs(
        ConfigUtils.getInteger(
            session,
            ConfigurationProperties.DEFAULT_REQUEST_TIMEOUT,
            ConfigurationProperties.REQUEST_TIMEOUT));

    configBuilder.setProxyServer(getProxy(repository));
    configBuilder.setRealm(getRealm(repository));

    return configBuilder.build();
  }
  /**
   * @param kbServerUrl Kill Bill url
   * @param username Kill Bill username
   * @param password Kill Bill password
   * @param apiKey Kill Bill api key
   * @param apiSecret Kill Bill api secret
   * @param proxyHost hostname of a proxy server that the client should use
   * @param proxyPort port number of a proxy server that the client should use
   * @param connectTimeOut connect timeout in milliseconds
   * @param readTimeOut read timeout in milliseconds
   * @param requestTimeout request timeout in milliseconds
   */
  public KillBillHttpClient(
      final String kbServerUrl,
      final String username,
      final String password,
      final String apiKey,
      final String apiSecret,
      final String proxyHost,
      final Integer proxyPort,
      final Integer connectTimeOut,
      final Integer readTimeOut,
      final Integer requestTimeout) {
    this.kbServerUrl = kbServerUrl;
    this.username = username;
    this.password = password;
    this.apiKey = apiKey;
    this.apiSecret = apiSecret;

    final AsyncHttpClientConfig.Builder cfg = new AsyncHttpClientConfig.Builder();

    cfg.setConnectTimeout(
        MoreObjects.firstNonNull(connectTimeOut, DEFAULT_HTTP_TIMEOUT_SEC * 1000));
    cfg.setReadTimeout(MoreObjects.firstNonNull(readTimeOut, DEFAULT_HTTP_TIMEOUT_SEC * 1000));
    cfg.setRequestTimeout(
        MoreObjects.firstNonNull(requestTimeout, DEFAULT_HTTP_TIMEOUT_SEC * 1000));
    cfg.setUserAgent(USER_AGENT);

    if (proxyHost != null && proxyPort != null) {
      final ProxyServer proxyServer = new ProxyServer(proxyHost, proxyPort);
      cfg.setProxyServer(proxyServer);
    }

    this.httpClient = new AsyncHttpClient(cfg.build());

    mapper = new ObjectMapper();
    mapper.registerModule(new JodaModule());
  }