Search in sources :

Example 1 with DefaultRoutePlanner

use of org.apache.http.impl.conn.DefaultRoutePlanner in project wikidata-query-rdf by wikimedia.

the class HttpClientUtils method configureHttpClient.

public static HttpClientBuilder configureHttpClient(HttpClientBuilder httpClientBuilder, HttpClientConnectionManager connectionManager, String proxy, String proxyMapString, int requestTimeout, String userAgent) {
    if (proxy != null && proxyMapString != null) {
        throw new IllegalArgumentException("Cannot set both proxy and proxy map property");
    }
    httpClientBuilder.setConnectionManager(connectionManager).setRetryHandler(getRetryHandler(RETRIES)).setServiceUnavailableRetryStrategy(getRetryStrategy(RETRIES, RETRY_INTERVAL)).disableCookieManagement().setUserAgent(userAgent).setDefaultRequestConfig(RequestConfig.custom().setSocketTimeout(requestTimeout).setConnectTimeout(requestTimeout).setConnectionRequestTimeout(requestTimeout).build());
    if (proxyMapString != null) {
        Map<String, HttpHost> proxyMap = createProxyMap(proxyMapString);
        httpClientBuilder.setRoutePlanner(new CustomRoutePlanner(proxyMap, new DefaultRoutePlanner(DefaultSchemePortResolver.INSTANCE)));
    }
    if (proxy != null) {
        HttpHost httpHost = HttpHost.create(proxy);
        httpClientBuilder.setProxy(httpHost);
    }
    return httpClientBuilder;
}
Also used : CustomRoutePlanner(org.wikimedia.utils.http.CustomRoutePlanner) HttpHost(org.apache.http.HttpHost) DefaultRoutePlanner(org.apache.http.impl.conn.DefaultRoutePlanner)

Aggregations

HttpHost (org.apache.http.HttpHost)1 DefaultRoutePlanner (org.apache.http.impl.conn.DefaultRoutePlanner)1 CustomRoutePlanner (org.wikimedia.utils.http.CustomRoutePlanner)1