List of usage examples for org.apache.http.impl.client.cache CacheConfig CacheConfig
CacheConfig
From source file:de.otto.jsonhome.client.HttpJsonHomeClient.java
/** * Constructs a default HttpJsonHomeClient build on top of a CachingHttpClient with in-memory storage. *///from w ww.ja va2s . c o m public HttpJsonHomeClient() { final CacheConfig cacheConfig = new CacheConfig(); cacheConfig.setMaxCacheEntries(100); cacheConfig.setMaxObjectSize(50000); this.cacheStorage = new BasicHttpCacheStorage(cacheConfig); this.httpClient = new CachingHttpClient(new DefaultHttpClient(), cacheStorage, cacheConfig); }
From source file:org.apache.abdera2.common.protocol.BasicCachingClient.java
protected HttpClient initClient(String useragent, DefaultHttpClient client) { inner = client != null ? client : (DefaultHttpClient) super.initClient(useragent); CacheConfig cacheConfig = new CacheConfig(); cacheConfig.setMaxCacheEntries(1000); cacheConfig.setMaxObjectSizeBytes(8192); cacheConfig.setHeuristicCachingEnabled(true); return store != null ? new CachingHttpClient(inner, store, cacheConfig) : new CachingHttpClient(inner, cacheConfig); }
From source file:com.riksof.a320.http.CoreHttpClient.java
/** * This method is used to execute Get Http Request * /*from ww w. j a va2s. co m*/ * @param url * @return * @throws ServerException */ public String executeGet(String url) throws ServerException { // Response String String responseString = null; headers = new HashMap<String, String>(); try { CacheConfig cacheConfig = new CacheConfig(); cacheConfig.setMaxCacheEntries(1000); cacheConfig.setMaxObjectSizeBytes(1024 * 1024); HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, connectionTimeOut); HttpConnectionParams.setSoTimeout(httpParameters, socketTimeOut); // Create http client object DefaultHttpClient realClient = new DefaultHttpClient(httpParameters); realClient.addResponseInterceptor(MakeCacheable.INSTANCE, 0); CachingHttpClient httpclient = new CachingHttpClient(realClient, cacheConfig); // Create http context object HttpContext localContext = new BasicHttpContext(); // Check for cached data against URL if (Cache.getInstance().get(url) == null) { // Execute HTTP Get Request HttpGet httpget = new HttpGet(url); // Get http response HttpResponse response = httpclient.execute(httpget, localContext); for (Header h : response.getAllHeaders()) { headers.put(h.getName(), h.getValue()); } // Create http entity object HttpEntity entity = response.getEntity(); // Create and convert stream into string InputStream inStream = entity.getContent(); responseString = convertStreamToString(inStream); // Cache url data Cache.getInstance().put(url, responseString); } else { // Returned cached data responseString = Cache.getInstance().get(url); } } catch (ClientProtocolException e) { // throw custom server exception in case of Exception e.printStackTrace(); throw new ServerException("ClientProtocolException"); } catch (ConnectTimeoutException e) { // throw custom server exception in case of Exception e.printStackTrace(); throw new ServerException("ConnectTimeoutException"); } catch (IOException e) { // throw custom server exception in case of Exception e.printStackTrace(); throw new ServerException("Request Timeout"); } catch (Exception e) { // throw custom server exception in case of Exception e.printStackTrace(); throw new ServerException("Exception"); } finally { } return responseString; }
From source file:gr.wavesoft.webng.io.web.WebStreams.java
public static void Initialize() { schemeRegistry = new SchemeRegistry(); // Register HTTP schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); // Register HTTPS with WebNG Extensions try {/*from ww w . j ava2s.co m*/ schemeRegistry.register(new Scheme("https", 443, new SSLSocketFactory(WebNGKeyStore.getKeyStore()))); } catch (NoSuchAlgorithmException ex) { systemLogger.except(ex); } catch (KeyManagementException ex) { systemLogger.except(ex); } catch (KeyStoreException ex) { systemLogger.except(ex); } catch (UnrecoverableKeyException ex) { systemLogger.except(ex); } // Setup connection manager connectionManager = new PoolingClientConnectionManager(schemeRegistry); // Increase max total connection to 200 connectionManager.setMaxTotal(200); // Increase default max connection per route to 20 connectionManager.setDefaultMaxPerRoute(20); // Increase max connections for localhost:80 to 50 HttpHost localhost = new HttpHost("locahost", 80); connectionManager.setMaxPerRoute(new HttpRoute(localhost), 50); // Setup http client httpClient = new DefaultHttpClient(connectionManager); // Setup cookie cache //((DefaultHttpClient)httpClient).setCookieStore(WebNGCache.instanceCookieCache()); // Setup cache CacheConfig cacheConfig = new CacheConfig(); cacheConfig.setMaxCacheEntries(WebNGCache.config.MAX_ENTRIES_MEM); cacheConfig.setMaxObjectSize(WebNGCache.config.MAX_OBJECT_SIZE); cachingClient = new CachingHttpClient(httpClient, WebNGCache.instanceDiskCacheStorage(), cacheConfig); }
From source file:com.grendelscan.commons.http.apache_overrides.client.CustomHttpClient.java
/** * // ww w . ja v a 2s.c o m * @param conman * @param params */ public CustomHttpClient(final ClientConnectionManager conman, final HttpParams params, final HttpContext contextTemplate) { super(conman, params); this.contextTemplate = contextTemplate; apacheCacheConfig = new CacheConfig(); apacheCacheConfig.setMaxCacheEntries(0); apacheCacheConfig.setMaxObjectSizeBytes(50000); CacheConfiguration ehCacheConfig = new CacheConfiguration("Cobra Cache", 50); ehCacheConfig.setOverflowToDisk(true); ehCacheConfig.setMaxElementsInMemory(50); ehCacheConfig.setDiskStorePath(Scan.getInstance().getOutputDirectory()); Ehcache ehCache = new Cache(ehCacheConfig); ehCache.initialise(); HttpCacheStorage storage = new EhcacheHttpCacheStorage(ehCache); cachingClient = new CachingHttpClient(this, storage, apacheCacheConfig); }
From source file:org.eclipse.thym.core.engine.AbstractEngineRepoProvider.java
private CacheConfig cacheConfig() { CacheConfig config = new CacheConfig(); config.setMaxObjectSize(120 * 1024); return config; }
From source file:org.eclipse.thym.core.plugin.registry.CordovaPluginRegistryManager.java
private static CacheConfig getCacheConfig() { CacheConfig config = new CacheConfig(); config.setMaxObjectSize(120 * 1024); return config; }
From source file:fr.ippon.wip.http.hc.HttpClientResourceManager.java
private CacheConfig createAndConfigureCache() { CacheConfig cacheConfig = new CacheConfig(); cacheConfig.setSharedCache(false);/*from ww w . j a v a 2 s. c o m*/ cacheConfig.setHeuristicCachingEnabled(true); cacheConfig.setHeuristicCoefficient((float) heuristicCacheRatio); cacheConfig.setHeuristicDefaultLifetime(60); cacheConfig.setMaxObjectSize(4000000); return cacheConfig; }
From source file:org.apache.marmotta.platform.core.services.http.HttpClientServiceImpl.java
@PostConstruct protected void initialize() { try {//ww w.java2 s.c om lock.writeLock().lock(); httpParams = new BasicHttpParams(); String userAgentString = "Apache Marmotta/" + configurationService.getStringConfiguration("kiwi.version") + " (running at " + configurationService.getServerUri() + ")" + " lmf-core/" + configurationService.getStringConfiguration("kiwi.version"); userAgentString = configurationService.getStringConfiguration("core.http.user_agent", userAgentString); httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, configurationService.getIntConfiguration("core.http.so_timeout", 60000)); httpParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, configurationService.getIntConfiguration("core.http.connection_timeout", 10000)); httpParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true); httpParams.setIntParameter(ClientPNames.MAX_REDIRECTS, 3); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry); cm.setMaxTotal(configurationService.getIntConfiguration(CoreOptions.HTTP_MAX_CONNECTIONS, 20)); cm.setDefaultMaxPerRoute( configurationService.getIntConfiguration(CoreOptions.HTTP_MAX_CONNECTIONS_PER_ROUTE, 10)); final DefaultHttpClient hc = new DefaultHttpClient(cm, httpParams); hc.setRedirectStrategy(new LMFRedirectStrategy()); hc.setHttpRequestRetryHandler(new LMFHttpRequestRetryHandler()); hc.removeRequestInterceptorByClass(org.apache.http.protocol.RequestUserAgent.class); hc.addRequestInterceptor(new LMFRequestUserAgent(userAgentString)); if (configurationService.getBooleanConfiguration(CoreOptions.HTTP_CLIENT_CACHE_ENABLE, true)) { CacheConfig cacheConfig = new CacheConfig(); // FIXME: Hardcoded constants - is this useful? cacheConfig.setMaxCacheEntries(1000); cacheConfig.setMaxObjectSize(81920); final HttpCacheStorage cacheStore = new MapHttpCacheStorage(httpCache); this.httpClient = new MonitoredHttpClient(new CachingHttpClient(hc, cacheStore, cacheConfig)); } else { this.httpClient = new MonitoredHttpClient(hc); } bytesSent.set(0); bytesReceived.set(0); requestsExecuted.set(0); idleConnectionMonitorThread = new IdleConnectionMonitorThread(httpClient.getConnectionManager()); idleConnectionMonitorThread.start(); StatisticsProvider stats = new StatisticsProvider(cm); statisticsService.registerModule(HttpClientService.class.getSimpleName(), stats); } finally { lock.writeLock().unlock(); } }
From source file:org.obiba.opal.rest.client.magma.OpalJavaClient.java
private HttpClient enableCaching(HttpClient httpClient) { CacheConfig config = new CacheConfig(); config.setSharedCache(false);//ww w .j a v a 2 s . c om config.setMaxObjectSizeBytes(MAX_OBJECT_SIZE_BYTES); cacheFolder = Files.createTempDir(); return new CachingHttpClient(httpClient, new FileResourceFactory(cacheFolder), cacheStorage = new ManagedHttpCacheStorage(config), config); }