Example #1
0
  /** Set the connection timeout and socket timeout */
  public static void setTimeouts(long connectionTimeout, long socketTimeout) {
    Options.setOption(Option.CONNECTION_TIMEOUT, connectionTimeout);
    Options.setOption(Option.SOCKET_TIMEOUT, socketTimeout);

    // Reload the client implementations
    Options.refresh();
  }
Example #2
0
  public static void refresh() {
    // Load timeouts
    Object connectionTimeout = Options.getOption(Option.CONNECTION_TIMEOUT);
    if (connectionTimeout == null) connectionTimeout = CONNECTION_TIMEOUT;
    Object socketTimeout = Options.getOption(Option.SOCKET_TIMEOUT);
    if (socketTimeout == null) socketTimeout = SOCKET_TIMEOUT;

    // Create common default configuration
    RequestConfig clientConfig =
        RequestConfig.custom()
            .setConnectTimeout(((Long) connectionTimeout).intValue())
            .setSocketTimeout(((Long) socketTimeout).intValue())
            .build();

    // Create clients
    setOption(
        Option.HTTPCLIENT,
        HttpClientBuilder.create().setDefaultRequestConfig(clientConfig).build());

    CloseableHttpAsyncClient asyncClient =
        HttpAsyncClientBuilder.create().setDefaultRequestConfig(clientConfig).build();
    asyncClient.start();

    setOption(Option.ASYNCHTTPCLIENT, asyncClient);
  }
Example #3
0
  static {
    RequestConfig clientConfig =
        RequestConfig.custom()
            .setConnectTimeout(CONNECTION_TIMEOUT)
            .setSocketTimeout(SOCKET_TIMEOUT)
            .build();

    setOption(
        Option.HTTPCLIENT,
        HttpClientBuilder.create().setDefaultRequestConfig(clientConfig).build());

    CloseableHttpAsyncClient asyncClient =
        HttpAsyncClientBuilder.create().setDefaultRequestConfig(clientConfig).build();
    asyncClient.start();

    setOption(Option.ASYNCHTTPCLIENT, asyncClient);
  }
Example #4
0
 /** Set default header */
 @SuppressWarnings("unchecked")
 public static void setDefaultHeader(String name, String value) {
   Object headers = Options.getOption(Option.DEFAULT_HEADERS);
   if (headers == null) {
     headers = new HashMap<String, String>();
   }
   ((Map<String, String>) headers).put(name, value);
   Options.setOption(Option.DEFAULT_HEADERS, headers);
 }
Example #5
0
 /**
  * Set the asynchronous AbstractHttpAsyncClient implementation to use for every asynchronous
  * request
  */
 public static void setAsyncHttpClient(CloseableHttpAsyncClient asyncHttpClient) {
   Options.setOption(Option.ASYNCHTTPCLIENT, asyncHttpClient);
 }
Example #6
0
 /** Clear default headers */
 public static void clearDefaultHeaders() {
   Options.setOption(Option.DEFAULT_HEADERS, null);
 }
Example #7
0
 /** Set the HttpClient implementation to use for every synchronous request */
 public static void setHttpClient(HttpClient httpClient) {
   Options.setOption(Option.HTTPCLIENT, httpClient);
 }