/** * Creates builder object for construction of custom * {@link CloseableHttpClient} instances. */ public static CachingHttpClientBuilder custom() { return CachingHttpClientBuilder.create(); }
/** * Creates {@link CloseableHttpClient} instance that uses a memory bound * response cache. */ public static CloseableHttpClient createMemoryBound() { return CachingHttpClientBuilder.create().build(); }
/** * Creates {@link CloseableHttpClient} instance that uses a file system * bound response cache. * * @param cacheDir location of response cache. */ public static CloseableHttpClient createFileBound(final File cacheDir) { return CachingHttpClientBuilder.create().setCacheDir(cacheDir).build(); }
/** * Create an HttpClient that performs client-side caching and connection pooling. * This can be used with {@link #setDefaultHttpClient} or provided in the HttpOp calls. * Beware that content is cached in this process, including across remote server restart. */ public static CloseableHttpClient createCachingHttpClient() { String s = System.getProperty("http.maxConnections", "5"); int max = Integer.parseInt(s); return CachingHttpClientBuilder.create() .useSystemProperties() .setRedirectStrategy(laxRedirectStrategy) .setMaxConnPerRoute(max) .setMaxConnTotal(2*max) .build() ; }
manager.setMaxTotal(SettingsManager.settings().maxConnections()); client = clientBuilderHelper(HttpClientBuilder.create(), manager); cachingClient = clientBuilderHelper(CachingHttpClientBuilder.create() .setCacheConfig(cacheConfig) .setHttpCacheStorage(httpCache),
/** * Constructs a default HttpJsonHomeClient build on top of a CachingHttpClient with in-memory storage. */ public HttpJsonHomeClient() { final CacheConfig cacheConfig = CacheConfig.custom() .setMaxCacheEntries(100) .setMaxObjectSize(50000) .build(); this.cacheStorage = new BasicHttpCacheStorage(cacheConfig); this.httpClient = CachingHttpClientBuilder.create() .setHttpCacheStorage(cacheStorage) .setCacheConfig(cacheConfig) .build(); }
.setMaxObjectSize(1024 * 128).build(); final CloseableHttpClient httpClient = CachingHttpClientBuilder.create()
public static HttpClientBuilder createDefaultHttpClientBuilder(final CacheConfig cacheConfig) { // Common CacheConfig for both the JarCacheStorage and the underlying // BasicHttpCacheStorage return CachingHttpClientBuilder.create() // allow caching .setCacheConfig(cacheConfig) // Wrap the local JarCacheStorage around a BasicHttpCacheStorage .setHttpCacheStorage(new JarCacheStorage(null, cacheConfig, new BasicHttpCacheStorage(cacheConfig))) // Support compressed data // https://wayback.archive.org/web/20130901115452/http://hc.apache.org:80/httpcomponents-client-ga/tutorial/html/httpagent.html#d5e1238 .addInterceptorFirst(new RequestAcceptEncoding()) .addInterceptorFirst(new ResponseContentEncoding()) .setRedirectStrategy(DefaultRedirectStrategy.INSTANCE) // User agent customisation .setUserAgent(JSONLD_JAVA_USER_AGENT) // use system defaults for proxy etc. .useSystemProperties(); }
private static CloseableHttpClient createTestHttpClient(CacheConfig cacheConfig, JarCacheStorage jarCacheConfig) { final CloseableHttpClient result = CachingHttpClientBuilder.create() // allow caching .setCacheConfig(cacheConfig) // Set the JarCacheStorage instance as the HttpCache .setHttpCacheStorage(jarCacheConfig) // Support compressed data // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/httpagent.html#d5e1238 .addInterceptorFirst(new RequestAcceptEncoding()) .addInterceptorFirst(new ResponseContentEncoding()) .setRedirectStrategy(DefaultRedirectStrategy.INSTANCE) // use system defaults for proxy etc. .useSystemProperties().build(); return result; } }
public static HttpClientBuilder createDefaultHttpClientBuilder(final CacheConfig cacheConfig) { // Common CacheConfig for both the JarCacheStorage and the underlying // BasicHttpCacheStorage return CachingHttpClientBuilder.create() // allow caching .setCacheConfig(cacheConfig) // Wrap the local JarCacheStorage around a BasicHttpCacheStorage .setHttpCacheStorage(new JarCacheStorage(null, cacheConfig, new BasicHttpCacheStorage(cacheConfig))) // Support compressed data // https://wayback.archive.org/web/20130901115452/http://hc.apache.org:80/httpcomponents-client-ga/tutorial/html/httpagent.html#d5e1238 .addInterceptorFirst(new RequestAcceptEncoding()) .addInterceptorFirst(new ResponseContentEncoding()) .setRedirectStrategy(DefaultRedirectStrategy.INSTANCE) // User agent customisation .setUserAgent(JSONLD_JAVA_USER_AGENT) // use system defaults for proxy etc. .useSystemProperties(); }