HTTPCLIENT-1005: reduced public API
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1023261 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6892f58f2c
commit
65528c02ec
|
@ -13,7 +13,6 @@ import org.apache.http.HttpRequest;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.HttpVersion;
|
import org.apache.http.HttpVersion;
|
||||||
import org.apache.http.client.cache.HttpCache;
|
|
||||||
import org.apache.http.client.cache.HttpCacheEntry;
|
import org.apache.http.client.cache.HttpCacheEntry;
|
||||||
import org.apache.http.client.cache.HttpCacheStorage;
|
import org.apache.http.client.cache.HttpCacheStorage;
|
||||||
import org.apache.http.client.cache.HttpCacheUpdateCallback;
|
import org.apache.http.client.cache.HttpCacheUpdateCallback;
|
||||||
|
@ -23,7 +22,7 @@ import org.apache.http.client.cache.ResourceFactory;
|
||||||
import org.apache.http.entity.ByteArrayEntity;
|
import org.apache.http.entity.ByteArrayEntity;
|
||||||
import org.apache.http.message.BasicHttpResponse;
|
import org.apache.http.message.BasicHttpResponse;
|
||||||
|
|
||||||
public class BasicHttpCache implements HttpCache {
|
class BasicHttpCache implements HttpCache {
|
||||||
|
|
||||||
private final URIExtractor uriExtractor;
|
private final URIExtractor uriExtractor;
|
||||||
private final ResourceFactory resourceFactory;
|
private final ResourceFactory resourceFactory;
|
||||||
|
|
|
@ -37,7 +37,6 @@ import org.apache.http.HttpHost;
|
||||||
import org.apache.http.HttpRequest;
|
import org.apache.http.HttpRequest;
|
||||||
import org.apache.http.annotation.ThreadSafe;
|
import org.apache.http.annotation.ThreadSafe;
|
||||||
import org.apache.http.client.cache.HeaderConstants;
|
import org.apache.http.client.cache.HeaderConstants;
|
||||||
import org.apache.http.client.cache.HttpCache;
|
|
||||||
import org.apache.http.client.cache.HttpCacheEntry;
|
import org.apache.http.client.cache.HttpCacheEntry;
|
||||||
import org.apache.http.client.cache.HttpCacheStorage;
|
import org.apache.http.client.cache.HttpCacheStorage;
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,9 @@ import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.ResponseHandler;
|
import org.apache.http.client.ResponseHandler;
|
||||||
import org.apache.http.client.cache.CacheResponseStatus;
|
import org.apache.http.client.cache.CacheResponseStatus;
|
||||||
import org.apache.http.client.cache.HeaderConstants;
|
import org.apache.http.client.cache.HeaderConstants;
|
||||||
import org.apache.http.client.cache.HttpCache;
|
|
||||||
import org.apache.http.client.cache.HttpCacheEntry;
|
import org.apache.http.client.cache.HttpCacheEntry;
|
||||||
|
import org.apache.http.client.cache.HttpCacheStorage;
|
||||||
|
import org.apache.http.client.cache.ResourceFactory;
|
||||||
import org.apache.http.client.methods.HttpUriRequest;
|
import org.apache.http.client.methods.HttpUriRequest;
|
||||||
import org.apache.http.conn.ClientConnectionManager;
|
import org.apache.http.conn.ClientConnectionManager;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
@ -96,7 +97,7 @@ public class CachingHttpClient implements HttpClient {
|
||||||
|
|
||||||
private final Log log = LogFactory.getLog(getClass());
|
private final Log log = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
public CachingHttpClient(
|
CachingHttpClient(
|
||||||
HttpClient client,
|
HttpClient client,
|
||||||
HttpCache cache,
|
HttpCache cache,
|
||||||
CacheConfig config) {
|
CacheConfig config) {
|
||||||
|
@ -150,26 +151,22 @@ public class CachingHttpClient implements HttpClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CachingHttpClient(
|
public CachingHttpClient(
|
||||||
HttpCache cache) {
|
HttpClient client,
|
||||||
this(new DefaultHttpClient(),
|
ResourceFactory resourceFactory,
|
||||||
cache,
|
HttpCacheStorage storage,
|
||||||
new CacheConfig());
|
|
||||||
}
|
|
||||||
|
|
||||||
public CachingHttpClient(
|
|
||||||
HttpCache cache,
|
|
||||||
CacheConfig config) {
|
CacheConfig config) {
|
||||||
this(new DefaultHttpClient(),
|
this(client,
|
||||||
cache,
|
new BasicHttpCache(resourceFactory, storage, config),
|
||||||
config);
|
config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CachingHttpClient(
|
public CachingHttpClient(
|
||||||
HttpClient client,
|
HttpClient client,
|
||||||
HttpCache cache) {
|
HttpCacheStorage storage,
|
||||||
|
CacheConfig config) {
|
||||||
this(client,
|
this(client,
|
||||||
cache,
|
new BasicHttpCache(new HeapResourceFactory(), storage, config),
|
||||||
new CacheConfig());
|
config);
|
||||||
}
|
}
|
||||||
|
|
||||||
CachingHttpClient(
|
CachingHttpClient(
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
* <http://www.apache.org/>.
|
* <http://www.apache.org/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.apache.http.client.cache;
|
package org.apache.http.impl.client.cache;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -33,11 +33,12 @@ import java.util.Set;
|
||||||
import org.apache.http.HttpHost;
|
import org.apache.http.HttpHost;
|
||||||
import org.apache.http.HttpRequest;
|
import org.apache.http.HttpRequest;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.cache.HttpCacheEntry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 4.1
|
* @since 4.1
|
||||||
*/
|
*/
|
||||||
public interface HttpCache {
|
interface HttpCache {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all matching {@link HttpCacheEntry}s.
|
* Clear all matching {@link HttpCacheEntry}s.
|
|
@ -29,7 +29,7 @@ package org.apache.http.impl.client.cache;
|
||||||
/**
|
/**
|
||||||
* @since 4.1
|
* @since 4.1
|
||||||
*/
|
*/
|
||||||
public enum RequestProtocolError {
|
enum RequestProtocolError {
|
||||||
|
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
BODY_BUT_NO_LENGTH_ERROR,
|
BODY_BUT_NO_LENGTH_ERROR,
|
||||||
|
|
|
@ -9,7 +9,6 @@ import org.apache.http.HttpRequest;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpVersion;
|
import org.apache.http.HttpVersion;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.cache.HttpCache;
|
|
||||||
import org.apache.http.client.cache.HttpCacheEntry;
|
import org.apache.http.client.cache.HttpCacheEntry;
|
||||||
import org.apache.http.message.BasicHttpRequest;
|
import org.apache.http.message.BasicHttpRequest;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
|
|
|
@ -40,7 +40,6 @@ import org.apache.http.NameValuePair;
|
||||||
import org.apache.http.ProtocolVersion;
|
import org.apache.http.ProtocolVersion;
|
||||||
import org.apache.http.client.ClientProtocolException;
|
import org.apache.http.client.ClientProtocolException;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.cache.HttpCache;
|
|
||||||
import org.apache.http.entity.ByteArrayEntity;
|
import org.apache.http.entity.ByteArrayEntity;
|
||||||
import org.apache.http.impl.cookie.DateUtils;
|
import org.apache.http.impl.cookie.DateUtils;
|
||||||
import org.apache.http.message.BasicHttpRequest;
|
import org.apache.http.message.BasicHttpRequest;
|
||||||
|
|
|
@ -47,7 +47,6 @@ import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.ResponseHandler;
|
import org.apache.http.client.ResponseHandler;
|
||||||
import org.apache.http.client.cache.CacheResponseStatus;
|
import org.apache.http.client.cache.CacheResponseStatus;
|
||||||
import org.apache.http.client.cache.HeaderConstants;
|
import org.apache.http.client.cache.HeaderConstants;
|
||||||
import org.apache.http.client.cache.HttpCache;
|
|
||||||
import org.apache.http.client.cache.HttpCacheEntry;
|
import org.apache.http.client.cache.HttpCacheEntry;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.methods.HttpUriRequest;
|
import org.apache.http.client.methods.HttpUriRequest;
|
||||||
|
@ -1907,7 +1906,7 @@ public class TestCachingHttpClient {
|
||||||
public void testTreatsCacheIOExceptionsAsCacheMiss()
|
public void testTreatsCacheIOExceptionsAsCacheMiss()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
impl = new CachingHttpClient(mockBackend, mockCache);
|
impl = new CachingHttpClient(mockBackend, mockCache, new CacheConfig());
|
||||||
HttpResponse resp = HttpTestUtils.make200Response();
|
HttpResponse resp = HttpTestUtils.make200Response();
|
||||||
|
|
||||||
mockCache.flushInvalidatedCacheEntriesFor(host, request);
|
mockCache.flushInvalidatedCacheEntriesFor(host, request);
|
||||||
|
|
|
@ -38,7 +38,6 @@ import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.ProtocolVersion;
|
import org.apache.http.ProtocolVersion;
|
||||||
import org.apache.http.client.ClientProtocolException;
|
import org.apache.http.client.ClientProtocolException;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.cache.HttpCache;
|
|
||||||
import org.apache.http.entity.ByteArrayEntity;
|
import org.apache.http.entity.ByteArrayEntity;
|
||||||
import org.apache.http.impl.cookie.DateUtils;
|
import org.apache.http.impl.cookie.DateUtils;
|
||||||
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
|
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
|
||||||
|
|
|
@ -31,18 +31,12 @@ import net.sf.ehcache.config.CacheConfiguration;
|
||||||
import net.sf.ehcache.config.Configuration;
|
import net.sf.ehcache.config.Configuration;
|
||||||
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
|
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
|
||||||
|
|
||||||
import org.apache.http.HttpHost;
|
|
||||||
import org.apache.http.HttpVersion;
|
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.cache.HttpCache;
|
|
||||||
import org.apache.http.client.cache.HttpCacheStorage;
|
import org.apache.http.client.cache.HttpCacheStorage;
|
||||||
import org.apache.http.impl.client.cache.BasicHttpCache;
|
|
||||||
import org.apache.http.impl.client.cache.CacheConfig;
|
import org.apache.http.impl.client.cache.CacheConfig;
|
||||||
import org.apache.http.impl.client.cache.CachingHttpClient;
|
import org.apache.http.impl.client.cache.CachingHttpClient;
|
||||||
import org.apache.http.impl.client.cache.HeapResourceFactory;
|
import org.apache.http.impl.client.cache.HeapResourceFactory;
|
||||||
import org.apache.http.impl.client.cache.HttpTestUtils;
|
|
||||||
import org.apache.http.impl.client.cache.TestProtocolRequirements;
|
import org.apache.http.impl.client.cache.TestProtocolRequirements;
|
||||||
import org.apache.http.message.BasicHttpRequest;
|
|
||||||
import org.easymock.classextension.EasyMock;
|
import org.easymock.classextension.EasyMock;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
|
@ -68,14 +62,7 @@ public class TestEhcacheProtocolRequirements extends TestProtocolRequirements{
|
||||||
@Override
|
@Override
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
host = new HttpHost("foo.example.com");
|
super.setUp();
|
||||||
|
|
||||||
body = HttpTestUtils.makeBody(entityLength);
|
|
||||||
|
|
||||||
request = new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1);
|
|
||||||
|
|
||||||
originResponse = HttpTestUtils.make200Response();
|
|
||||||
|
|
||||||
params = new CacheConfig();
|
params = new CacheConfig();
|
||||||
params.setMaxObjectSizeBytes(MAX_BYTES);
|
params.setMaxObjectSizeBytes(MAX_BYTES);
|
||||||
|
|
||||||
|
@ -84,11 +71,9 @@ public class TestEhcacheProtocolRequirements extends TestProtocolRequirements{
|
||||||
}
|
}
|
||||||
CACHE_MANAGER.addCache(TEST_EHCACHE_NAME);
|
CACHE_MANAGER.addCache(TEST_EHCACHE_NAME);
|
||||||
HttpCacheStorage storage = new EhcacheHttpCacheStorage(CACHE_MANAGER.getCache(TEST_EHCACHE_NAME));
|
HttpCacheStorage storage = new EhcacheHttpCacheStorage(CACHE_MANAGER.getCache(TEST_EHCACHE_NAME));
|
||||||
cache = new BasicHttpCache(new HeapResourceFactory(), storage, params);
|
|
||||||
mockBackend = EasyMock.createMock(HttpClient.class);
|
mockBackend = EasyMock.createMock(HttpClient.class);
|
||||||
mockCache = EasyMock.createMock(HttpCache.class);
|
|
||||||
|
|
||||||
impl = new CachingHttpClient(mockBackend, cache, params);
|
impl = new CachingHttpClient(mockBackend, new HeapResourceFactory(), storage, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
Loading…
Reference in New Issue