org.apache.http.impl.client.cache.CachingHttpClients Java Examples
The following examples show how to use
org.apache.http.impl.client.cache.CachingHttpClients.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeySetRetriever.java From deprecated-security-advanced-modules with Apache License 2.0 | 7 votes |
private CloseableHttpClient createHttpClient(HttpCacheStorage httpCacheStorage) { HttpClientBuilder builder; if (httpCacheStorage != null) { builder = CachingHttpClients.custom().setCacheConfig(cacheConfig).setHttpCacheStorage(httpCacheStorage); } else { builder = HttpClients.custom(); } builder.useSystemProperties(); if (sslConfig != null) { builder.setSSLSocketFactory(sslConfig.toSSLConnectionSocketFactory()); } return builder.build(); }
Example #2
Source File: MCRURIResolver.java From mycore with GNU General Public License v3.0 | 6 votes |
MCRRESTResolver() { CacheConfig cacheConfig = CacheConfig.custom() .setMaxObjectSize(MAX_OBJECT_SIZE) .setMaxCacheEntries(MAX_CACHE_ENTRIES) .build(); RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(REQUEST_TIMEOUT) .setSocketTimeout(REQUEST_TIMEOUT) .build(); this.restClient = CachingHttpClients.custom() .setCacheConfig(cacheConfig) .setDefaultRequestConfig(requestConfig) .setUserAgent(MCRHttpUtils.getHttpUserAgent()) .useSystemProperties() .build(); MCRShutdownHandler.getInstance().addCloseable(this::close); this.logger = LogManager.getLogger(); }
Example #3
Source File: FetchServlet.java From apicurio-studio with Apache License 2.0 | 6 votes |
@PostConstruct protected void postConstruct() { try { // TODO make these settings configurable!! CacheConfig cacheConfig = CacheConfig.custom() .setMaxCacheEntries(2000) .setMaxObjectSize(16384) .build(); RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(30000) .setSocketTimeout(30000) .build(); this.httpClient = CachingHttpClients.custom() .setCacheConfig(cacheConfig) .setDefaultRequestConfig(requestConfig) .build(); } catch (Exception e) { logger.error("Error creating HTTP client.", e); throw new RuntimeException(e); } }
Example #4
Source File: HttpClientFactory.java From riptide with MIT License | 6 votes |
private static HttpClientBuilder configureCaching(final Caching caching, @Nullable final Object cacheStorage) { final Heuristic heuristic = caching.getHeuristic(); final CacheConfig.Builder config = CacheConfig.custom() .setSharedCache(caching.getShared()) .setMaxObjectSize(caching.getMaxObjectSize()) .setMaxCacheEntries(caching.getMaxCacheEntries()); if (heuristic.getEnabled()) { config.setHeuristicCachingEnabled(true); config.setHeuristicCoefficient(heuristic.getCoefficient()); config.setHeuristicDefaultLifetime(heuristic.getDefaultLifeTime().to(TimeUnit.SECONDS)); } @Hack("return cast tricks classloader in case of missing httpclient-cache") CachingHttpClientBuilder builder = CachingHttpClients.custom() .setCacheConfig(config.build()) .setHttpCacheStorage((HttpCacheStorage) cacheStorage) .setCacheDir(Optional.ofNullable(caching.getDirectory()) .map(Path::toFile) .orElse(null)); return HttpClientBuilder.class.cast(builder); }
Example #5
Source File: HttpEndpoint.java From Brutusin-RPC with Apache License 2.0 | 5 votes |
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()); }
Example #6
Source File: HttpUtil.java From thym with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings("restriction") private static CloseableHttpClient getHttpClient(URI url){ CacheConfig cacheConfig = CacheConfig.custom() .setMaxCacheEntries(1000) .setMaxObjectSize(120*1024).setHeuristicCachingEnabled(true) .setHeuristicDefaultLifetime(TimeUnit.HOURS.toSeconds(12)) .build(); CachingHttpClientBuilder builder = CachingHttpClients.custom() .setCacheConfig(cacheConfig) .setHttpCacheStorage(new BundleHttpCacheStorage(HybridCore.getContext().getBundle())); builder = setupProxy(builder, url); return builder.build(); }