コード例 #1
0
  /**
   * @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());
  }