/** 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(); }
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); }
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); }
/** 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); }
/** * Set the asynchronous AbstractHttpAsyncClient implementation to use for every asynchronous * request */ public static void setAsyncHttpClient(CloseableHttpAsyncClient asyncHttpClient) { Options.setOption(Option.ASYNCHTTPCLIENT, asyncHttpClient); }
/** Clear default headers */ public static void clearDefaultHeaders() { Options.setOption(Option.DEFAULT_HEADERS, null); }
/** Set the HttpClient implementation to use for every synchronous request */ public static void setHttpClient(HttpClient httpClient) { Options.setOption(Option.HTTPCLIENT, httpClient); }