List of usage examples for org.apache.http.impl.client HttpClientBuilder disableContentCompression
public final HttpClientBuilder disableContentCompression()
From source file:com.granita.icloudcalsync.webdav.DavHttpClient.java
@SuppressLint("LogTagMismatch") public static CloseableHttpClient create() { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager( socketFactoryRegistry);//w ww. j ava 2s . c o m // limits per DavHttpClient (= per DavSyncAdapter extends AbstractThreadedSyncAdapter) connectionManager.setMaxTotal(3); // max. 3 connections in total connectionManager.setDefaultMaxPerRoute(2); // max. 2 connections per host HttpClientBuilder builder = HttpClients.custom().useSystemProperties() .setConnectionManager(connectionManager).setDefaultRequestConfig(defaultRqConfig) .setRetryHandler(DavHttpRequestRetryHandler.INSTANCE) .setRedirectStrategy(DavRedirectStrategy.INSTANCE) .setUserAgent("DAVdroid/" + Constants.APP_VERSION); if (Log.isLoggable("Wire", Log.DEBUG)) { Log.i(TAG, "Wire logging active, disabling HTTP compression"); builder = builder.disableContentCompression(); } return builder.build(); }
From source file:org.jboss.pnc.client.ApacheHttpClient43EngineWithRetry.java
@Override protected HttpClient createDefaultHttpClient() { logger.info("Bootstrapping http engine with request retry handler..."); final HttpClientBuilder builder = HttpClientBuilder.create(); RequestConfig.Builder requestBuilder = RequestConfig.custom(); if (defaultProxy != null) { requestBuilder.setProxy(defaultProxy); }// w w w. j a va 2 s .c o m builder.disableContentCompression(); builder.setDefaultRequestConfig(requestBuilder.build()); HttpRequestRetryHandler retryHandler = new StandardHttpRequestRetryHandler(); builder.setRetryHandler(retryHandler); return builder.build(); }
From source file:org.fao.geonet.utils.GeonetHttpRequestFactory.java
public HttpClientBuilder getDefaultHttpClientBuilder() { final HttpClientBuilder builder = HttpClientBuilder.create(); builder.setRedirectStrategy(new LaxRedirectStrategy()); builder.disableContentCompression(); synchronized (this) { if (connectionManager == null) { connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(this.numberOfConcurrentRequests); nonShutdownableConnectionManager = new HttpClientConnectionManager() { public void closeExpiredConnections() { connectionManager.closeExpiredConnections(); }/* w w w. j a v a 2 s . c om*/ public ConnectionRequest requestConnection(HttpRoute route, Object state) { return connectionManager.requestConnection(route, state); } public void releaseConnection(HttpClientConnection managedConn, Object state, long keepalive, TimeUnit tunit) { connectionManager.releaseConnection(managedConn, state, keepalive, tunit); } public void connect(HttpClientConnection managedConn, HttpRoute route, int connectTimeout, HttpContext context) throws IOException { connectionManager.connect(managedConn, route, connectTimeout, context); } public void upgrade(HttpClientConnection managedConn, HttpRoute route, HttpContext context) throws IOException { connectionManager.upgrade(managedConn, route, context); } public void routeComplete(HttpClientConnection managedConn, HttpRoute route, HttpContext context) throws IOException { connectionManager.routeComplete(managedConn, route, context); } public void shutdown() { // don't shutdown pool } public void closeIdleConnections(long idleTimeout, TimeUnit tunit) { connectionManager.closeIdleConnections(idleTimeout, tunit); } }; } connectionManager.setDefaultSocketConfig( SocketConfig.custom().setSoTimeout((int) TimeUnit.MINUTES.toMillis(3)).build()); builder.setConnectionManager(nonShutdownableConnectionManager); } return builder; }
From source file:org.duracloud.common.web.RestHttpHelper.java
private CloseableHttpClient buildClient(HttpClientBuilder builder, Method method) { if (method.equals(Method.HEAD)) { builder.disableContentCompression(); }/*w ww. j ava 2 s. c o m*/ return builder.build(); }
From source file:org.apache.solr.client.solrj.impl.HttpClientUtil.java
private static HttpClientBuilder setupBuilder(HttpClientBuilder builder, SolrParams config) { Builder requestConfigBuilder = RequestConfig.custom() .setRedirectsEnabled(config.getBool(HttpClientUtil.PROP_FOLLOW_REDIRECTS, false)) .setDecompressionEnabled(false) .setConnectTimeout(config.getInt(HttpClientUtil.PROP_CONNECTION_TIMEOUT, DEFAULT_CONNECT_TIMEOUT)) .setSocketTimeout(config.getInt(HttpClientUtil.PROP_SO_TIMEOUT, DEFAULT_SO_TIMEOUT)); String cpolicy = cookiePolicy; if (cpolicy != null) { requestConfigBuilder.setCookieSpec(cpolicy); }//from w w w .jav a 2s . c o m RequestConfig requestConfig = requestConfigBuilder.build(); HttpClientBuilder retBuilder = builder.setDefaultRequestConfig(requestConfig); if (config.getBool(HttpClientUtil.PROP_USE_RETRY, true)) { retBuilder = retBuilder.setRetryHandler(new SolrHttpRequestRetryHandler(3)); } else { retBuilder = retBuilder.setRetryHandler(NO_RETRY); } final String basicAuthUser = config.get(HttpClientUtil.PROP_BASIC_AUTH_USER); final String basicAuthPass = config.get(HttpClientUtil.PROP_BASIC_AUTH_PASS); if (basicAuthUser != null && basicAuthPass != null) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(basicAuthUser, basicAuthPass)); retBuilder.setDefaultCredentialsProvider(credsProvider); } if (config.getBool(HttpClientUtil.PROP_ALLOW_COMPRESSION, false)) { retBuilder.addInterceptorFirst(new UseCompressionRequestInterceptor()); retBuilder.addInterceptorFirst(new UseCompressionResponseInterceptor()); } else { retBuilder.disableContentCompression(); } return retBuilder; }
From source file:ch.cyberduck.core.s3.RequestEntityRestStorageService.java
public RequestEntityRestStorageService(final S3Session session, final Jets3tProperties properties, final HttpClientBuilder configuration) { super(session.getHost().getCredentials().isAnonymousLogin() ? null : new AWSCredentials(null, null) { @Override//from ww w . j a v a 2 s.c om public String getAccessKey() { return session.getHost().getCredentials().getUsername(); } @Override public String getSecretKey() { return session.getHost().getCredentials().getPassword(); } }, new PreferencesUseragentProvider().get(), null, properties); this.session = session; configuration.disableContentCompression(); configuration.setRetryHandler( new S3HttpRequestRetryHandler(this, preferences.getInteger("http.connections.retry"))); configuration.setRedirectStrategy(new DefaultRedirectStrategy() { @Override public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException { if (response.containsHeader("x-amz-bucket-region")) { final String host = ((HttpUriRequest) request).getURI().getHost(); if (!StringUtils.equals(session.getHost().getHostname(), host)) { regionEndpointCache.putRegionForBucketName( StringUtils .split(StringUtils.removeEnd(((HttpUriRequest) request).getURI().getHost(), session.getHost().getHostname()), ".")[0], response.getFirstHeader("x-amz-bucket-region").getValue()); } } return super.getRedirect(request, response, context); } }); this.setHttpClient(configuration.build()); }
From source file:com.kolich.http.HttpClient4ClosureBuilder.java
public HttpClientBuilder getHttpClientBuilder() { final HttpClientBuilder builder = HttpClients.custom().setDefaultRequestConfig(getRequestConfig()) .setConnectionManager(getConnectionManager()).setUserAgent(userAgent_); // See http://stackoverflow.com/questions/21818242/with-httpclient-4-3-x-executing-a-httphead-for-a-specific-url-gives-nohttprespo // Also, see https://issues.apache.org/jira/browse/HTTPCLIENT-1464 // This disables the addition of the `Accept-Encoding: gzip,deflate` // header on outgoing requests which seems to confuse some servers. // This is off by default, but can be turned off if desired. if (disableContentCompression_) { builder.disableContentCompression(); }/*from w ww .java 2 s .c o m*/ if (disableAutomaticRetries_) { builder.disableAutomaticRetries(); } if (disableAuthCaching_) { builder.disableAuthCaching(); } if (useProxySelector_) { builder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault())); } return builder; }
From source file:com.ksc.http.apache.client.impl.ApacheHttpClientFactory.java
@Override public ConnectionManagerAwareHttpClient create(HttpClientSettings settings) { final HttpClientBuilder builder = HttpClients.custom(); // Note that it is important we register the original connection manager with the // IdleConnectionReaper as it's required for the successful deregistration of managers final HttpClientConnectionManager cm = cmFactory.create(settings); builder.setRequestExecutor(new SdkHttpRequestExecutor()) .setKeepAliveStrategy(buildKeepAliveStrategy(settings)).disableRedirectHandling() .disableAutomaticRetries().setConnectionManager(ClientConnectionManagerFactory.wrap(cm)); // By default http client enables Gzip compression. So we disable it // here./*from w ww. ja v a 2 s. co m*/ // Apache HTTP client removes Content-Length, Content-Encoding and // Content-MD5 headers when Gzip compression is enabled. Currently // this doesn't affect S3 or Glacier which exposes these headers. // if (!(settings.useGzip())) { builder.disableContentCompression(); } addProxyConfig(builder, settings); final ConnectionManagerAwareHttpClient httpClient = new SdkHttpClient(builder.build(), cm); if (settings.useReaper()) { IdleConnectionReaper.registerConnectionManager(cm); } return httpClient; }
From source file:org.ow2.proactive.http.CommonHttpClientBuilder.java
public CloseableHttpClient build() { org.apache.http.impl.client.HttpClientBuilder internalHttpClientBuilder = createInternalHttpClientBuilder(); if (useSystemProperties) { internalHttpClientBuilder.useSystemProperties(); }/*w w w.j a v a 2s.c om*/ if (overrideAllowAnyHostname != null) { if (overrideAllowAnyHostname) { acceptAnyHostname = true; } else { acceptAnyHostname = false; } } if (overrideAllowAnyCertificate != null) { if (overrideAllowAnyCertificate) { acceptAnyCertificate = true; } else { acceptAnyCertificate = false; } } if (acceptAnyCertificate) { internalHttpClientBuilder.setSslcontext(createSslContext()); } if (acceptAnyHostname) { internalHttpClientBuilder.setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } if (maxConnections > 0) { internalHttpClientBuilder.setMaxConnPerRoute(maxConnections); internalHttpClientBuilder.setMaxConnTotal(maxConnections); } if (requestConfig != null) { internalHttpClientBuilder.setDefaultRequestConfig(requestConfig); } if (!useContentCompression) { internalHttpClientBuilder.disableContentCompression(); } return internalHttpClientBuilder.build(); }