Package org.apache.http.impl.client.cache

Examples of org.apache.http.impl.client.cache.CachingHttpClient


                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);
View Full Code Here


        cacheConfig.setMaxCacheEntries(1000);
        cacheConfig.setHeuristicCachingEnabled(true);
        cacheConfig.setHeuristicDefaultLifetime(
            settings.getCacheExpiration());
        cacheConfig.setHeuristicCoefficient(0.9f);
        CachingHttpClient cachingClient = new CachingHttpClient(
            defaultClient, cacheConfig);
        return cachingClient;
      } else {
        return defaultClient;
      }
View Full Code Here

                client.addResponseInterceptor(new ResponseContentEncoding());
                final CacheConfig cacheConfig = new CacheConfig();
                cacheConfig.setMaxObjectSize(1024 * 128); // 128 kB
                cacheConfig.setMaxCacheEntries(1000);
                // and allow caching
                final CachingHttpClient cachingClient = new CachingHttpClient(client, cacheConfig);

                // Wrap again with JAR cache
                final JarCacheStorage jarCache = new JarCacheStorage();
                defaultHttpClient = new CachingHttpClient(cachingClient, jarCache,
                        jarCache.getCacheConfig());
            }
            return defaultHttpClient;
        }
    }
View Full Code Here

public class JarCacheTest {

    @Test
    public void cacheHit() throws Exception {
        final JarCacheStorage storage = new JarCacheStorage();
        final HttpClient httpClient = new CachingHttpClient(new SystemDefaultHttpClient(), storage,
                storage.getCacheConfig());
        final HttpGet get = new HttpGet("http://nonexisting.example.com/context");
        final HttpResponse resp = httpClient.execute(get);

        assertEquals("application/ld+json", resp.getEntity().getContentType().getValue());
        final String str = IOUtils.toString(resp.getEntity().getContent(), "UTF-8");
        assertTrue(str.contains("ex:datatype"));
    }
View Full Code Here

    }

    @Test(expected = IOException.class)
    public void cacheMiss() throws Exception {
        final JarCacheStorage storage = new JarCacheStorage();
        final HttpClient httpClient = new CachingHttpClient(new SystemDefaultHttpClient(), storage,
                storage.getCacheConfig());
        final HttpGet get = new HttpGet("http://nonexisting.example.com/notfound");
        // Should throw an IOException as the DNS name
        // nonexisting.example.com does not exist
        final HttpResponse resp = httpClient.execute(get);
    }
View Full Code Here

    }

    @Test
    public void doubleLoad() throws Exception {
        final JarCacheStorage storage = new JarCacheStorage();
        final HttpClient httpClient = new CachingHttpClient(new SystemDefaultHttpClient(), storage,
                storage.getCacheConfig());
        final HttpGet get = new HttpGet("http://nonexisting.example.com/context");
        HttpResponse resp = httpClient.execute(get);
        resp = httpClient.execute(get);
        // Ensure second load through the cached jarcache list works
        assertEquals("application/ld+json", resp.getEntity().getContentType().getValue());
    }
View Full Code Here

    public void customClassPath() throws Exception {
        final URL nestedJar = getClass().getResource("/nested.jar");
        final ClassLoader cl = new URLClassLoader(new URL[] { nestedJar });
        final JarCacheStorage storage = new JarCacheStorage(cl);

        final HttpClient httpClient = new CachingHttpClient(new SystemDefaultHttpClient(), storage,
                storage.getCacheConfig());
        final HttpGet get = new HttpGet("http://nonexisting.example.com/nested/hello");
        final HttpResponse resp = httpClient.execute(get);

        assertEquals("application/json", resp.getEntity().getContentType().getValue());
        final String str = IOUtils.toString(resp.getEntity().getContent(), "UTF-8");
        assertEquals("{ \"Hello\": \"World!\" }", str.trim());
    }
View Full Code Here

        final ClassLoader cl = new URLClassLoader(new URL[] { nestedJar });

        final JarCacheStorage storage = new JarCacheStorage();
        Thread.currentThread().setContextClassLoader(cl);

        final HttpClient httpClient = new CachingHttpClient(new SystemDefaultHttpClient(), storage,
                storage.getCacheConfig());
        final HttpGet get = new HttpGet("http://nonexisting.example.com/nested/hello");
        final HttpResponse resp = httpClient.execute(get);

        assertEquals("application/json", resp.getEntity().getContentType().getValue());
        final String str = IOUtils.toString(resp.getEntity().getContent(), "UTF-8");
        assertEquals("{ \"Hello\": \"World!\" }", str.trim());
    }
View Full Code Here

    public void systemClassLoader() throws Exception {
        final URL nestedJar = getClass().getResource("/nested.jar");
        assertNotNull(nestedJar);
        final JarCacheStorage storage = new JarCacheStorage(null);

        final HttpClient httpClient = new CachingHttpClient(new SystemDefaultHttpClient(), storage,
                storage.getCacheConfig());
        final HttpGet get = new HttpGet("http://nonexisting.example.com/context");
        final HttpResponse resp = httpClient.execute(get);
        assertEquals("application/ld+json", resp.getEntity().getContentType().getValue());
    }
View Full Code Here

        final URL url = new URL("http://json-ld.org/contexts/person.jsonld");
        documentLoader.fromURL(url);

        // Now try to get it again and ensure it is
        // cached
        final HttpClient client = new CachingHttpClient(documentLoader.getHttpClient());
        final HttpUriRequest get = new HttpGet(url.toURI());
        get.setHeader("Accept", DocumentLoader.ACCEPT_HEADER);
        final HttpContext localContext = new BasicHttpContext();
        final HttpResponse respo = client.execute(get, localContext);
        EntityUtils.consume(respo.getEntity());

        // Check cache status
        // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/caching.html
        final CacheResponseStatus responseStatus = (CacheResponseStatus) localContext
View Full Code Here

TOP

Related Classes of org.apache.http.impl.client.cache.CachingHttpClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.