Example usage for org.apache.http.impl.client.cache CacheConfig setMaxObjectSizeBytes

List of usage examples for org.apache.http.impl.client.cache CacheConfig setMaxObjectSizeBytes

Introduction

In this page you can find the example usage for org.apache.http.impl.client.cache CacheConfig setMaxObjectSizeBytes.

Prototype

public void setMaxObjectSizeBytes(int maxObjectSizeBytes) 

Source Link

Document

Specifies the maximum response body size that will be eligible for caching.

Usage

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 www . ja v  a2  s. c  o 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:org.obiba.opal.rest.client.magma.OpalJavaClient.java

private HttpClient enableCaching(HttpClient httpClient) {
    CacheConfig config = new CacheConfig();
    config.setSharedCache(false);//from  ww  w.  j a  v a2s .co m
    config.setMaxObjectSizeBytes(MAX_OBJECT_SIZE_BYTES);
    cacheFolder = Files.createTempDir();
    return new CachingHttpClient(httpClient, new FileResourceFactory(cacheFolder),
            cacheStorage = new ManagedHttpCacheStorage(config), config);
}