List of usage examples for org.apache.http.impl.client HttpClientBuilder setDefaultRequestConfig
public final HttpClientBuilder setDefaultRequestConfig(final RequestConfig config)
From source file:org.opennms.core.web.HttpClientWrapper.java
public CloseableHttpClient getClient() { if (m_httpClient == null) { final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom(); if (!m_reuseConnections) { httpClientBuilder.setConnectionReuseStrategy(new NoConnectionReuseStrategy()); }//from w w w .j av a 2 s.c om if (m_usePreemptiveAuth) { enablePreemptiveAuth(httpClientBuilder); } if (m_useSystemProxySettings) { httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault())); } if (!isEmpty(m_cookieSpec)) { requestConfigBuilder.setCookieSpec(m_cookieSpec); } if (m_cookieStore != null) { httpClientBuilder.setDefaultCookieStore(m_cookieStore); } if (m_username != null) { setCredentials(httpClientBuilder, m_username, m_password); } if (m_socketTimeout != null) { requestConfigBuilder.setSocketTimeout(m_socketTimeout); } if (m_connectionTimeout != null) { requestConfigBuilder.setConnectTimeout(m_connectionTimeout); } if (m_retries != null) { httpClientBuilder.setRetryHandler(new HttpRequestRetryOnExceptionHandler(m_retries, false)); } if (m_sslContext.size() != 0) { configureSSLContext(httpClientBuilder); } for (final HttpRequestInterceptor interceptor : m_requestInterceptors) { httpClientBuilder.addInterceptorLast(interceptor); } for (final HttpResponseInterceptor interceptor : m_responseInterceptors) { httpClientBuilder.addInterceptorLast(interceptor); } if (m_useLaxRedirect) { httpClientBuilder.setRedirectStrategy(new LaxRedirectStrategy()); } httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build()); m_httpClient = httpClientBuilder.build(); } return m_httpClient; }
From source file:org.opensextant.xtext.collectors.web.WebClient.java
/** * TODO: Update to use HTTP client "HttpClients....build()" method of creating and tailoring HttpClient * using the proxy and cookie settings, as well as any other tuning. * * Override if your context requires a different style of HTTP client. * /*from w w w .j a v a 2 s . c o m*/ * @return HttpClient 4.x object */ public HttpClient getClient() { HttpClientBuilder clientHelper = null; if (this.useSystemProperties) { clientHelper = HttpClientBuilder.create().useSystemProperties(); } else { clientHelper = HttpClientBuilder.create(); if (proxyHost != null) { clientHelper.setProxy(proxyHost); } } RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY) .build(); HttpClient httpClient = clientHelper.setDefaultRequestConfig(globalConfig).build(); return httpClient; }
From source file:org.tanaguru.util.http.HttpRequestHandler.java
private CloseableHttpClient getHttpClient(String url) { RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(socketTimeout) .setConnectTimeout(connectionTimeout).build(); HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); httpClientBuilder.setDefaultRequestConfig(requestConfig); httpClientBuilder.setConnectionManager(new PoolingHttpClientConnectionManager()); httpClientBuilder.setUserAgent(TANAGURU_USER_AGENT); if (isProxySet(url)) { LOGGER.debug(("Set proxy with " + proxyHost + " and " + proxyPort)); httpClientBuilder.setProxy(new HttpHost(proxyHost, Integer.valueOf(proxyPort))); if (isProxyCredentialSet()) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(proxyHost, Integer.valueOf(proxyPort)), new UsernamePasswordCredentials(proxyUser, proxyPassword)); httpClientBuilder.setDefaultCredentialsProvider(credsProvider); LOGGER.debug(("Set proxy credentials " + proxyHost + " and " + proxyPort + " and " + proxyUser + " and " + proxyPassword)); }//from www.j a v a 2 s . c o m } return httpClientBuilder.build(); }
From source file:org.xwiki.extension.repository.http.internal.DefaultHttpClientFactory.java
@Override public HttpClientBuilder createHttpClientBuilder(Map<String, String> properties) { HttpClientBuilder httpClientBuilder = createHttpClientBuilder(properties.get("auth.user"), properties.get("auth.password")); // Set socket timeouts BasicHttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager(); SocketConfig.Builder socketConfigBuilder = SocketConfig.custom(); socketConfigBuilder.setSoTimeout(getIntProperty(properties, SOCKET_TIMEOUT, 30000)); connectionManager.setSocketConfig(socketConfigBuilder.build()); httpClientBuilder.setConnectionManager(connectionManager); // Set request timeouts RequestConfig.Builder requestBuilder = RequestConfig.custom(); requestBuilder = requestBuilder.setConnectTimeout(getIntProperty(properties, CONNECTION_TIMEOUT, 30000)); httpClientBuilder.setDefaultRequestConfig(requestBuilder.build()); return httpClientBuilder; }