/** * 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(); }
/** * 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(); }
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(); }
manager.setMaxTotal(SettingsManager.settings().maxConnections()); client = clientBuilderHelper(HttpClientBuilder.create(), manager); cachingClient = clientBuilderHelper(CachingHttpClientBuilder.create() .setCacheConfig(cacheConfig) .setHttpCacheStorage(httpCache), manager);
/******************************************************************************************************************* * * * ******************************************************************************************************************/ @PostConstruct /* VisibleForTesting */ void initialize() { connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(200); connectionManager.setDefaultMaxPerRoute(20); cacheConfig = CacheConfig.custom() .setAllow303Caching(true) .setMaxCacheEntries(Integer.MAX_VALUE) .setMaxObjectSize(Integer.MAX_VALUE) .setSharedCache(false) .setHeuristicCachingEnabled(true) .build(); httpClient = CachingHttpClients.custom() .setHttpCacheStorage(cacheStorage) .setCacheConfig(cacheConfig) .setRedirectStrategy(dontFollowRedirect) .setUserAgent("blueMarine (fabrizio.giudici@tidalwave.it)") .setDefaultHeaders(Arrays.asList(new BasicHeader("Accept", "application/n3"))) .setConnectionManager(connectionManager) .addInterceptorFirst(killCacheHeaders) // FIXME: only if explicitly configured .build(); }
static CloseableHttpClient defaultHttpClient() { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_CONNECTIONS); connectionManager.setMaxTotal(DEFAULT_MAX_CONNECTIONS); RequestConfig.Builder requestConfigBuilder = RequestConfig.custom(); requestConfigBuilder.setConnectTimeout(((int) TimeUnit.SECONDS.toMillis(5))); requestConfigBuilder.setSocketTimeout((int) TimeUnit.SECONDS.toMillis(10)); CacheConfig cacheConfig = CacheConfig.custom() .setMaxCacheEntries(128) .setMaxObjectSize(2048) // keys (.pem) are small .setHeuristicCachingEnabled(false) .setSharedCache(false) .setAsynchronousWorkersMax(2) .build(); return CachingHttpClients.custom() .setCacheConfig(cacheConfig) .setDefaultRequestConfig(requestConfigBuilder.build()) .setConnectionManager(connectionManager) .useSystemProperties() .setRedirectStrategy(DefaultRedirectStrategy.INSTANCE) .build(); } }
private CloseableHttpClient createDefaultClient(HttpClientConnectionManager fClientCm) { final CacheConfig cacheConfig = CacheConfig.custom() .setMaxCacheEntries(DEFAULT_CACHE_MAX_ENTRIES) .setMaxObjectSize(DEFAULT_CACHE_MAX_OBJ_SIZE) .setHeuristicCachingEnabled(true) .setHeuristicDefaultLifetime(DEFAULT_CACHE_TTL_IN_SECS) .build(); final RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(DEFAULT_REQUEST_CONN_TIMEOUT_IN_MS) .setSocketTimeout(DEFAULT_REQUEST_SOCK_TIMEOUT_IN_MS) .build(); return CachingHttpClients.custom() .setCacheConfig(cacheConfig) .setConnectionManager(fClientCm) .setDefaultRequestConfig(requestConfig) .build(); }
.setCacheConfig(cacheConfig) .setDefaultConnectionConfig(connectionConfig) .setDefaultCredentialsProvider(credentialsProvider) .setDefaultRequestConfig(requestConfig)
/** * Creates builder object for construction of custom * {@link CloseableHttpClient} instances. */ public static CachingHttpClientBuilder custom() { return CachingHttpClientBuilder.create(); }
/** * 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() ; }
@Override public CloseableHttpClient build() { final CloseableHttpClient client = super.build(); httpClientTracker.track(client); return client; } });
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(); }
public HttpEndpoint(URI endpoint, Config cfg, HttpClientContextFactory clientContextFactory) { if (endpoint == null) { throw new IllegalArgumentException("Endpoint is required"); } if (cfg == null) { cfg = new ConfigurationBuilder().build(); } CacheConfig cacheConfig = CacheConfig.custom() .setMaxCacheEntries(cfg.getMaxCacheEntries()) .setMaxObjectSize(cfg.getMaxCacheObjectSize()) .build(); RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(1000 * cfg.getConnectTimeOutSeconds()) .setSocketTimeout(1000 * cfg.getSocketTimeOutSeconds()) .build(); PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(cfg.getMaxConections()); this.endpoint = endpoint; this.httpClient = CachingHttpClients.custom() .setCacheConfig(cacheConfig) .setDefaultRequestConfig(requestConfig) .setRetryHandler(new StandardHttpRequestRetryHandler()) .setConnectionManager(cm) .build(); this.clientContextFactory = clientContextFactory; initPingThread(cfg.getPingSeconds()); }
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; } }
.setMaxObjectSize(1024 * 128).build(); final CloseableHttpClient httpClient = CachingHttpClientBuilder.create() .setCacheConfig(cacheConfig) .setHttpCacheStorage(new JarCacheStorage(null, cacheConfig, new BasicHttpCacheStorage(cacheConfig))) .addInterceptorFirst(new RequestAcceptEncoding()) .addInterceptorFirst(new ResponseContentEncoding()) .setRedirectStrategy(DefaultRedirectStrategy.INSTANCE)