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

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


                EasyMock.eq(target),
                EasyMock.isA(HttpRequest.class),
                EasyMock.same(context))).andReturn(response);
        EasyMock.replay(client);
       
        CachingHttpClient t = new CachingHttpClient(client, resourceFactory, httpCacheStorage, cacheConfig);

        HttpResponse response1 = t.execute(get, context);
        Assert.assertEquals(200, response1.getStatusLine().getStatusCode());
        EntityUtils.consume(response1.getEntity());
       
        EasyMock.verify(client);
       
        removeCache();

        EasyMock.reset(client);
        EasyMock.expect(client.execute(
                EasyMock.eq(target),
                EasyMock.isA(HttpRequest.class),
                EasyMock.same(context))).andReturn(response);
        EasyMock.replay(client);
       
        HttpResponse response2 = t.execute(get, context);
        Assert.assertEquals(200, response2.getStatusLine().getStatusCode());
        EntityUtils.consume(response2.getEntity());

        EasyMock.verify(client);
    }
View Full Code Here


        }
        CACHE_MANAGER.addCache(TEST_EHCACHE_NAME);
        HttpCacheStorage storage = new EhcacheHttpCacheStorage(CACHE_MANAGER.getCache(TEST_EHCACHE_NAME));
        mockBackend = EasyMock.createMock(HttpClient.class);

        impl = new CachingHttpClient(mockBackend, new HeapResourceFactory(), storage, params);
    }
View Full Code Here

        }
        CACHE_MANAGER.addCache(TEST_EHCACHE_NAME);
        HttpCacheStorage storage = new EhcacheHttpCacheStorage(CACHE_MANAGER.getCache(TEST_EHCACHE_NAME));
        mockBackend = EasyMock.createNiceMock(HttpClient.class);

        impl = new CachingHttpClient(mockBackend, new HeapResourceFactory(), storage, params);
    }
View Full Code Here

                EasyMock.eq(target),
                EasyMock.isA(HttpRequest.class),
                EasyMock.same(context))).andReturn(response);
        EasyMock.replay(client);
       
        CachingHttpClient t = new CachingHttpClient(client, resourceFactory, httpCacheStorage, cacheConfig);

        HttpResponse response1 = t.execute(get, context);
        Assert.assertEquals(200, response1.getStatusLine().getStatusCode());
        EntityUtils.consume(response1.getEntity());
       
        EasyMock.verify(client);
       
        removeCache();

        EasyMock.reset(client);
        EasyMock.expect(client.execute(
                EasyMock.eq(target),
                EasyMock.isA(HttpRequest.class),
                EasyMock.same(context))).andReturn(response);
        EasyMock.replay(client);
       
        HttpResponse response2 = t.execute(get, context);
        Assert.assertEquals(200, response2.getStatusLine().getStatusCode());
        EntityUtils.consume(response2.getEntity());

        EasyMock.verify(client);
    }
View Full Code Here

        }
        CACHE_MANAGER.addCache(TEST_EHCACHE_NAME);
        HttpCacheStorage storage = new EhcacheHttpCacheStorage(CACHE_MANAGER.getCache(TEST_EHCACHE_NAME));
        mockBackend = EasyMock.createMock(HttpClient.class);

        impl = new CachingHttpClient(mockBackend, new HeapResourceFactory(), storage, params);
    }
View Full Code Here

        }
        CACHE_MANAGER.addCache(TEST_EHCACHE_NAME);
        HttpCacheStorage storage = new EhcacheHttpCacheStorage(CACHE_MANAGER.getCache(TEST_EHCACHE_NAME));
        mockBackend = EasyMock.createMock(HttpClient.class);

        impl = new CachingHttpClient(mockBackend, new HeapResourceFactory(), storage, params);
    }
View Full Code Here

                EasyMock.eq(target),
                EasyMock.isA(HttpRequest.class),
                EasyMock.same(context))).andReturn(response);
        EasyMock.replay(client);
       
        CachingHttpClient t = new CachingHttpClient(client, resourceFactory, httpCacheStorage, cacheConfig);

        HttpResponse response1 = t.execute(get, context);
        Assert.assertEquals(200, response1.getStatusLine().getStatusCode());
        EntityUtils.consume(response1.getEntity());
       
        EasyMock.verify(client);
       
        removeCache();

        EasyMock.reset(client);
        EasyMock.expect(client.execute(
                EasyMock.eq(target),
                EasyMock.isA(HttpRequest.class),
                EasyMock.same(context))).andReturn(response);
        EasyMock.replay(client);
       
        HttpResponse response2 = t.execute(get, context);
        Assert.assertEquals(200, response2.getStatusLine().getStatusCode());
        EntityUtils.consume(response2.getEntity());

        EasyMock.verify(client);
    }
View Full Code Here

    IntermediateHttpClient HTTPClient = new IntermediateHttpClient();
    CacheCon  = new ThreadSafeClientConnManager();
    config = new CacheConfig();
    config.setSharedCache(true);
    config.setMaxObjectSizeBytes(2<<31);
    CacheClient = new CachingHttpClient(HTTPClient, cache, config);
    return false;
  }
View Full Code Here

   
    IntermediateHttpClient interClient = new IntermediateHttpClient();
    ((ThreadSafeClientConnManager)interClient.getConnectionManager()).setMaxTotal(100);
        CacheConfig config = new CacheConfig();
        config.setMaxObjectSizeBytes(2<<24);
        CachingHttpClient httpclient = new CachingHttpClient(new IntermediateHttpClient(), new Cache((long)2<<34, "places"), config);

        try {
            // create an array of URIs to perform GETs on
            String[] urisToGet = {
                "http://www.gutenberg.org/files/76/76-h/76-h/76-h.htm",
                "http://www.gutenberg.org/cache/epub/10947/pg10947.html"
                //"http://hc.apache.org/httpcomponents-client-ga/",
                //"http://svn.apache.org/viewvc/httpcomponents/"
            };

            // create a thread for each URI
            GetThread[] threads = new GetThread[10];
            for (int i = 0; i < threads.length; i++) {
                HttpGet httpget = new HttpGet(urisToGet[i%2]);
                threads[i] = new GetThread(httpclient, httpget, i + 1);
            }

            // start the threads
            for (int j = 0; j < threads.length; j++) {
                threads[j].start();
               // threads[j].join();
            }

            // join the threads
            for (int j = 0; j < threads.length; j++) {
                threads[j].join();
            }

        } finally {
            // When HttpClient instance is no longer needed,
            // shut down the connection manager to ensure
            // immediate deallocation of all system resources
            httpclient.getConnectionManager().shutdown();
        }
    }
View Full Code Here

                cacheConfig.setMaxCacheEntries(1000);
                cacheConfig.setMaxObjectSize(81920);

                final HttpCacheStorage cacheStore = new EhcacheHttpCacheStorage(ehcache.get(), cacheConfig);

                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

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.