RequestOptions options) {
boolean usecache = useCache(method,options);
options = options != null ? options : getDefaultRequestOptions();
HttpMethod httpMethod = null;
try {
Cache cache = getCache();
CachedResponse cached_response = cache.get(uri);
switch(
getCacheDisposition(
usecache,
uri,
options,
cached_response)) {
case FRESH: // CACHE HIT: FRESH
if (cached_response != null)
return checkRequestException(
cached_response,options);
case STALE: // CACHE HIT: STALE
// revalidate the cached entry
if (cached_response != null) {
if (cached_response.getEntityTag() != null)
options.setIfNoneMatch(cached_response.getEntityTag().toString());
else if (cached_response.getLastModified() != null)
options.setIfModifiedSince(cached_response.getLastModified());
else options.setNoCache(true);
}
default: // CACHE MISS
httpMethod =
MethodHelper.createMethod(
method, uri, entity, options);
client.executeMethod(httpMethod);
if (usecache &&
(httpMethod.getStatusCode() == 304 ||
httpMethod.getStatusCode() == 412) &&
cached_response != null) return cached_response;
ClientResponse response = new CommonsResponse(abdera,httpMethod);
response = options.getUseLocalCache() ?
response = cache.update(uri, options, response, cached_response) :
response;
return checkRequestException(response,options);
}
} catch (RuntimeException r) {
throw r;