org.apache.http.impl.client.cache
Class CachingHttpClient

java.lang.Object
  extended by org.apache.http.impl.client.cache.CachingHttpClient
All Implemented Interfaces:
HttpClient

@ThreadSafe
public class CachingHttpClient
extends Object
implements HttpClient

Since:
4.1

Field Summary
static ProtocolVersion HTTP_1_1
           
 
Constructor Summary
CachingHttpClient()
           
CachingHttpClient(HttpCache<CacheEntry> cache, int maxObjectSizeBytes)
           
CachingHttpClient(HttpClient client, HttpCache<CacheEntry> cache, int maxObjectSizeBytes)
           
CachingHttpClient(HttpClient backend, ResponseCachingPolicy responseCachingPolicy, CacheEntryGenerator cacheEntryGenerator, URIExtractor uriExtractor, HttpCache<CacheEntry> responseCache, CachedHttpResponseGenerator responseGenerator, CacheInvalidator cacheInvalidator, CacheableRequestPolicy cacheableRequestPolicy, CachedResponseSuitabilityChecker suitabilityChecker, ConditionalRequestBuilder conditionalRequestBuilder, CacheEntryUpdater entryUpdater, ResponseProtocolCompliance responseCompliance, RequestProtocolCompliance requestCompliance)
           
 
Method Summary
protected  HttpResponse callBackend(HttpHost target, HttpRequest request, HttpContext context)
           
protected  HttpResponse correctIncompleteResponse(HttpResponse resp, byte[] bodyBytes)
           
protected  CacheEntry doGetUpdatedParentEntry(CacheEntry existing, HttpHost target, HttpRequest req, CacheEntry entry)
           
 HttpResponse execute(HttpHost target, HttpRequest request)
          Execute an HttpRequest @ a given HttpHost
 HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context)
          Executes a request to the target using the given context.
<T> T
execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler)
          Execute an HttpRequest @ a given HttpHost with a specified ResponseHandler that will deal with the result of the call.
<T> T
execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context)
          Execute an HttpRequest @ a given HttpHost with a specified ResponseHandler that will deal with the result of the call using a specific HttpContext
 HttpResponse execute(HttpUriRequest request)
          Executes a request using the default context.
 HttpResponse execute(HttpUriRequest request, HttpContext context)
          Executes a request using the given context.
<T> T
execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler)
          Executes a request using the default context and processes the response using the given response handler.
<T> T
execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context)
          Executes a request using the given context and processes the response using the given response handler.
protected  CacheEntry getCacheEntry(HttpHost target, HttpRequest request)
           
 long getCacheHits()
          Return the number of times that the cache successfully answered an HttpRequest for a document of information from the server.
 long getCacheMisses()
          Return the number of times that the cache was unable to answer an HttpRequest for a document of information from the server.
 long getCacheUpdates()
          Return the number of times that the cache was able to revalidate an existing cache entry for a document of information from the server.
 ClientConnectionManager getConnectionManager()
          Obtains the connection manager used by this client.
protected  Date getCurrentDate()
           
 HttpParams getParams()
          Obtains the parameters for this client.
protected  SizeLimitedResponseReader getResponseReader(HttpResponse backEndResponse)
           
protected  HttpResponse handleBackendResponse(HttpHost target, HttpRequest request, Date requestDate, Date responseDate, HttpResponse backendResponse)
           
 boolean isSharedCache()
           
protected  HttpResponse revalidateCacheEntry(HttpHost target, HttpRequest request, HttpContext context, CacheEntry cacheEntry)
           
protected  void storeInCache(HttpHost target, HttpRequest request, CacheEntry entry)
           
protected  HttpCacheUpdateCallback<CacheEntry> storeVariantEntry(HttpHost target, HttpRequest req, CacheEntry entry)
           
 boolean supportsRangeAndContentRangeHeaders()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTP_1_1

public static final ProtocolVersion HTTP_1_1
Constructor Detail

CachingHttpClient

public CachingHttpClient()

CachingHttpClient

public CachingHttpClient(HttpCache<CacheEntry> cache,
                         int maxObjectSizeBytes)

CachingHttpClient

public CachingHttpClient(HttpClient client,
                         HttpCache<CacheEntry> cache,
                         int maxObjectSizeBytes)

CachingHttpClient

public CachingHttpClient(HttpClient backend,
                         ResponseCachingPolicy responseCachingPolicy,
                         CacheEntryGenerator cacheEntryGenerator,
                         URIExtractor uriExtractor,
                         HttpCache<CacheEntry> responseCache,
                         CachedHttpResponseGenerator responseGenerator,
                         CacheInvalidator cacheInvalidator,
                         CacheableRequestPolicy cacheableRequestPolicy,
                         CachedResponseSuitabilityChecker suitabilityChecker,
                         ConditionalRequestBuilder conditionalRequestBuilder,
                         CacheEntryUpdater entryUpdater,
                         ResponseProtocolCompliance responseCompliance,
                         RequestProtocolCompliance requestCompliance)
Method Detail

getCacheHits

public long getCacheHits()
Return the number of times that the cache successfully answered an HttpRequest for a document of information from the server.

Returns:
long the number of cache successes

getCacheMisses

public long getCacheMisses()
Return the number of times that the cache was unable to answer an HttpRequest for a document of information from the server.

Returns:
long the number of cache failures/misses

getCacheUpdates

public long getCacheUpdates()
Return the number of times that the cache was able to revalidate an existing cache entry for a document of information from the server.

Returns:
long the number of cache revalidations

execute

public HttpResponse execute(HttpHost target,
                            HttpRequest request)
                     throws IOException
Execute an HttpRequest @ a given HttpHost

Specified by:
execute in interface HttpClient
Parameters:
target - the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.
request - the request to execute
Returns:
HttpResponse The cached entry or the result of a backend call
Throws:
IOException
ClientProtocolException - in case of an http protocol error

execute

public <T> T execute(HttpHost target,
                     HttpRequest request,
                     ResponseHandler<? extends T> responseHandler)
          throws IOException
Execute an HttpRequest @ a given HttpHost with a specified ResponseHandler that will deal with the result of the call.

Specified by:
execute in interface HttpClient
Type Parameters:
T - The Return Type Identified by the generic type of the ResponseHandler
Parameters:
target - the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.
request - the request to execute
responseHandler - the response handler
Returns:
T The response type as handled by ResponseHandler
Throws:
IOException
ClientProtocolException - in case of an http protocol error

execute

public <T> T execute(HttpHost target,
                     HttpRequest request,
                     ResponseHandler<? extends T> responseHandler,
                     HttpContext context)
          throws IOException
Execute an HttpRequest @ a given HttpHost with a specified ResponseHandler that will deal with the result of the call using a specific HttpContext

Specified by:
execute in interface HttpClient
Type Parameters:
T - The Return Type Identified by the generic type of the ResponseHandler
Parameters:
target - the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.
request - the request to execute
responseHandler - the response handler
context - the context to use for the execution, or null to use the default context
Returns:
T The response type as handled by ResponseHandler
Throws:
IOException
ClientProtocolException - in case of an http protocol error

execute

public HttpResponse execute(HttpUriRequest request)
                     throws IOException
Description copied from interface: HttpClient
Executes a request using the default context.

Specified by:
execute in interface HttpClient
Parameters:
request - the request to execute
Returns:
HttpResponse The cached entry or the result of a backend call
Throws:
IOException
ClientProtocolException - in case of an http protocol error

execute

public HttpResponse execute(HttpUriRequest request,
                            HttpContext context)
                     throws IOException
Description copied from interface: HttpClient
Executes a request using the given context. The route to the target will be determined by the HTTP client.

Specified by:
execute in interface HttpClient
Parameters:
request - the request to execute
context - the context to use for the execution, or null to use the default context
Returns:
HttpResponse The cached entry or the result of a backend call
Throws:
IOException
ClientProtocolException - in case of an http protocol error

execute

public <T> T execute(HttpUriRequest request,
                     ResponseHandler<? extends T> responseHandler)
          throws IOException
Description copied from interface: HttpClient
Executes a request using the default context and processes the response using the given response handler.

Specified by:
execute in interface HttpClient
Type Parameters:
T - The Return Type Identified by the generic type of the ResponseHandler
Parameters:
request - the request to execute
responseHandler - the response handler
Returns:
T The response type as handled by ResponseHandler
Throws:
IOException
ClientProtocolException - in case of an http protocol error

execute

public <T> T execute(HttpUriRequest request,
                     ResponseHandler<? extends T> responseHandler,
                     HttpContext context)
          throws IOException
Description copied from interface: HttpClient
Executes a request using the given context and processes the response using the given response handler.

Specified by:
execute in interface HttpClient
Type Parameters:
T - The Return Type Identified by the generic type of the ResponseHandler
Parameters:
request - the request to execute
responseHandler - the response handler
context - the http context
Returns:
T The response type as handled by ResponseHandler
Throws:
IOException
ClientProtocolException - in case of an http protocol error

getConnectionManager

public ClientConnectionManager getConnectionManager()
Description copied from interface: HttpClient
Obtains the connection manager used by this client.

Specified by:
getConnectionManager in interface HttpClient
Returns:
the connection manager

getParams

public HttpParams getParams()
Description copied from interface: HttpClient
Obtains the parameters for this client. These parameters will become defaults for all requests being executed with this client, and for the parameters of dependent objects in this client.

Specified by:
getParams in interface HttpClient
Returns:
the parameters

getCurrentDate

protected Date getCurrentDate()

getCacheEntry

protected CacheEntry getCacheEntry(HttpHost target,
                                   HttpRequest request)

execute

public HttpResponse execute(HttpHost target,
                            HttpRequest request,
                            HttpContext context)
                     throws IOException
Description copied from interface: HttpClient
Executes a request to the target using the given context.

Specified by:
execute in interface HttpClient
Parameters:
target - the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.
request - the request to execute
context - the context to use for the execution, or null to use the default context
Returns:
the response
Throws:
IOException
ClientProtocolException - in case of an http protocol error

callBackend

protected HttpResponse callBackend(HttpHost target,
                                   HttpRequest request,
                                   HttpContext context)
                            throws IOException
Throws:
IOException

revalidateCacheEntry

protected HttpResponse revalidateCacheEntry(HttpHost target,
                                            HttpRequest request,
                                            HttpContext context,
                                            CacheEntry cacheEntry)
                                     throws IOException,
                                            ProtocolException
Throws:
IOException
ProtocolException

storeInCache

protected void storeInCache(HttpHost target,
                            HttpRequest request,
                            CacheEntry entry)

storeVariantEntry

protected HttpCacheUpdateCallback<CacheEntry> storeVariantEntry(HttpHost target,
                                                                HttpRequest req,
                                                                CacheEntry entry)

doGetUpdatedParentEntry

protected CacheEntry doGetUpdatedParentEntry(CacheEntry existing,
                                             HttpHost target,
                                             HttpRequest req,
                                             CacheEntry entry)
                                      throws HttpCacheOperationException
Throws:
HttpCacheOperationException

correctIncompleteResponse

protected HttpResponse correctIncompleteResponse(HttpResponse resp,
                                                 byte[] bodyBytes)

handleBackendResponse

protected HttpResponse handleBackendResponse(HttpHost target,
                                             HttpRequest request,
                                             Date requestDate,
                                             Date responseDate,
                                             HttpResponse backendResponse)
                                      throws IOException
Throws:
IOException

getResponseReader

protected SizeLimitedResponseReader getResponseReader(HttpResponse backEndResponse)

supportsRangeAndContentRangeHeaders

public boolean supportsRangeAndContentRangeHeaders()

isSharedCache

public boolean isSharedCache()


Copyright © 1999-2010 Apache Software Foundation. All Rights Reserved.