List of usage examples for org.apache.http.impl.client HttpClientBuilder setDefaultRequestConfig
public final HttpClientBuilder setDefaultRequestConfig(final RequestConfig config)
From source file:com.intellij.translation.translator.TranslatorUtil.java
public static CloseableHttpClient createClient() { HttpClientBuilder builder = HttpClients.custom(); return builder .setDefaultRequestConfig(RequestConfig.custom().setSocketTimeout(REQUEST_TIMEOUT) .setConnectTimeout(REQUEST_TIMEOUT).setConnectionRequestTimeout(REQUEST_TIMEOUT).build()) .build();/*from ww w . j ava 2 s .c o m*/ }
From source file:com.gogh.plugin.translator.TranslatorUtil.java
public static CloseableHttpClient createClient() { HttpClientBuilder builder = HttpClients.custom(); return builder.setDefaultRequestConfig(RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000) .setConnectionRequestTimeout(5000).build()).build(); }
From source file:ee.ria.xroad.proxy.clientproxy.FastestConnectionSelectingSSLSocketFactoryIntegrationTest.java
private static void createClient() throws Exception { RegistryBuilder<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder .<ConnectionSocketFactory>create(); socketFactoryRegistry.register("http", PlainConnectionSocketFactory.INSTANCE); socketFactoryRegistry.register("https", createSSLSocketFactory()); PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager( socketFactoryRegistry.build()); connMgr.setMaxTotal(CLIENT_MAX_TOTAL_CONNECTIONS); connMgr.setDefaultMaxPerRoute(CLIENT_MAX_CONNECTIONS_PER_ROUTE); int timeout = SystemProperties.getClientProxyTimeout(); RequestConfig.Builder rb = RequestConfig.custom(); rb.setConnectTimeout(timeout);/*from ww w .j a v a 2s . c o m*/ rb.setConnectionRequestTimeout(timeout); rb.setSocketTimeout(timeout); HttpClientBuilder cb = HttpClients.custom(); cb.setConnectionManager(connMgr); cb.setDefaultRequestConfig(rb.build()); // Disable request retry cb.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); client = cb.build(); }
From source file:org.sakaiproject.contentreview.urkund.util.UrkundAPIUtil.java
public static String getFileInfo(String baseUrl, String externalId, String receiverAddress, String urkundUsername, String urkundPassword, int timeout) { String ret = null;/*w ww . j a v a 2 s .c o m*/ RequestConfig.Builder requestBuilder = RequestConfig.custom(); requestBuilder = requestBuilder.setConnectTimeout(timeout); requestBuilder = requestBuilder.setConnectionRequestTimeout(timeout); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setDefaultRequestConfig(requestBuilder.build()); try (CloseableHttpClient httpClient = builder.build()) { HttpGet httpget = new HttpGet(baseUrl + "submissions/" + receiverAddress + "/" + externalId); //------------------------------------------------------------ if (StringUtils.isNotBlank(urkundUsername) && StringUtils.isNotBlank(urkundPassword)) { addAuthorization(httpget, urkundUsername, urkundPassword); } //------------------------------------------------------------ httpget.addHeader("Accept", "application/json"); //------------------------------------------------------------ HttpResponse response = httpClient.execute(httpget); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { ret = EntityUtils.toString(resEntity); EntityUtils.consume(resEntity); } } catch (IOException e) { log.error("ERROR getting File Info : ", e); } return ret; }
From source file:org.sakaiproject.contentreview.urkund.util.UrkundAPIUtil.java
public static String postDocument(String baseUrl, String receiverAddress, String externalId, UrkundSubmission submission, String urkundUsername, String urkundPassword, int timeout) { String ret = null;/*from w ww . ja v a 2s . c om*/ RequestConfig.Builder requestBuilder = RequestConfig.custom(); requestBuilder = requestBuilder.setConnectTimeout(timeout); requestBuilder = requestBuilder.setConnectionRequestTimeout(timeout); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setDefaultRequestConfig(requestBuilder.build()); try (CloseableHttpClient httpClient = builder.build()) { HttpPost httppost = new HttpPost(baseUrl + "submissions/" + receiverAddress + "/" + externalId); //------------------------------------------------------------ EntityBuilder eBuilder = EntityBuilder.create(); eBuilder.setBinary(submission.getContent()); httppost.setEntity(eBuilder.build()); //------------------------------------------------------------ if (StringUtils.isNotBlank(urkundUsername) && StringUtils.isNotBlank(urkundPassword)) { addAuthorization(httppost, urkundUsername, urkundPassword); } //------------------------------------------------------------ httppost.addHeader("Accept", "application/json"); httppost.addHeader("Content-Type", submission.getMimeType()); httppost.addHeader("Accept-Language", submission.getLanguage()); httppost.addHeader("x-urkund-filename", submission.getFilenameEncoded()); httppost.addHeader("x-urkund-submitter", submission.getSubmitterEmail()); httppost.addHeader("x-urkund-anonymous", Boolean.toString(submission.isAnon())); httppost.addHeader("x-urkund-subject", submission.getSubject()); httppost.addHeader("x-urkund-message", submission.getMessage()); //------------------------------------------------------------ HttpResponse response = httpClient.execute(httppost); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { ret = EntityUtils.toString(resEntity); EntityUtils.consume(resEntity); } } catch (IOException e) { log.error("ERROR uploading File : ", e); } return ret; }
From source file:com.srotya.tau.ui.alerts.Utils.java
public static CloseableHttpClient buildClient(String baseURL, int connectTimeout, int requestTimeout) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { HttpClientBuilder clientBuilder = HttpClients.custom(); RequestConfig config = RequestConfig.custom().setConnectTimeout(connectTimeout) .setConnectionRequestTimeout(requestTimeout).build(); return clientBuilder.setDefaultRequestConfig(config).build(); }
From source file:com.srotya.sidewinder.cluster.Utils.java
/** * Build a {@link CloseableHttpClient}/*from ww w . j ava 2s .c om*/ * * @param baseURL * @param connectTimeout * @param requestTimeout * @return http client * @throws NoSuchAlgorithmException * @throws KeyStoreException * @throws KeyManagementException */ public static CloseableHttpClient buildClient(String baseURL, int connectTimeout, int requestTimeout) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { HttpClientBuilder clientBuilder = HttpClients.custom(); RequestConfig config = RequestConfig.custom().setConnectTimeout(connectTimeout) .setConnectionRequestTimeout(requestTimeout).build(); return clientBuilder.setDefaultRequestConfig(config).build(); }
From source file:io.wcm.caravan.commons.httpclient.impl.HttpClientItem.java
private static CloseableHttpClient buildHttpClient(HttpClientConfig config, PoolingHttpClientConnectionManager connectionManager, CredentialsProvider credentialsProvider) { // prepare HTTPClient builder HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().setConnectionManager(connectionManager); // timeout settings httpClientBuilder.setDefaultRequestConfig(RequestConfig.custom() .setConnectTimeout(config.getConnectTimeout()).setSocketTimeout(config.getSocketTimeout()).build()); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); // optional proxy support if (StringUtils.isNotEmpty(config.getProxyHost())) { httpClientBuilder.setProxy(new HttpHost(config.getProxyHost(), config.getProxyPort())); // optional proxy authentication if (StringUtils.isNotEmpty(config.getProxyUser())) { httpClientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); }/*from www .j a v a 2 s . c om*/ } return httpClientBuilder.build(); }
From source file:com.twinsoft.convertigo.engine.util.HttpUtils.java
@SuppressWarnings("deprecation") public static CloseableHttpClient makeHttpClient4(boolean usePool) { HttpClientBuilder httpClientBuilder = HttpClients.custom(); httpClientBuilder.setDefaultRequestConfig( RequestConfig.custom().setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY).build()); if (usePool) { PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(); int maxTotalConnections = 100; try {//from w w w . ja va2s . c om maxTotalConnections = new Integer( EnginePropertiesManager.getProperty(PropertyName.HTTP_CLIENT_MAX_TOTAL_CONNECTIONS)) .intValue(); } catch (NumberFormatException e) { Engine.logEngine.warn("Unable to retrieve the max number of connections; defaults to 100."); } int maxConnectionsPerHost = 50; try { maxConnectionsPerHost = new Integer( EnginePropertiesManager.getProperty(PropertyName.HTTP_CLIENT_MAX_CONNECTIONS_PER_HOST)) .intValue(); } catch (NumberFormatException e) { Engine.logEngine .warn("Unable to retrieve the max number of connections per host; defaults to 100."); } connManager.setDefaultMaxPerRoute(maxConnectionsPerHost); connManager.setMaxTotal(maxTotalConnections); httpClientBuilder.setConnectionManager(connManager); } return httpClientBuilder.build(); }
From source file:org.nuxeo.connect.connector.http.ProxyHelper.java
public static void configureProxyIfNeeded(HttpClientBuilder httpClientBuilder, String url) { RequestConfig.Builder requestConfigBuilder = RequestConfig.custom(); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); ProxyHelper.configureProxyIfNeeded(requestConfigBuilder, credentialsProvider, url); httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build()); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); }