hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r966642 [1/5] - in /httpcomponents/httpclient/trunk/httpclient-cache/src: main/java/org/apache/http/client/cache/ main/java/org/apache/http/impl/client/cache/ test/java/org/apache/http/impl/client/cache/
Date Thu, 22 Jul 2010 13:16:30 GMT
Author: olegk
Date: Thu Jul 22 13:16:29 2010
New Revision: 966642

URL: http://svn.apache.org/viewvc?rev=966642&view=rev
Log:
HTTP Cache API refactoring: entry validation logic factored out from CacheEntry to a separate policy class; HttpCacheEntry should now contain (almost) no protocol specific code

Added:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/CachedHeaderGroup.java
      - copied, changed from r965979, httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHeaderGroup.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HeaderConstants.java
      - copied, changed from r965979, httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeaderConstants.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntry.java
      - copied, changed from r965979, httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntry.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheValidityPolicy.java
      - copied, changed from r965979, httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntry.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/CacheEntry.java   (with props)
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/OKStatus.java   (with props)
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheValidityPolicy.java
      - copied, changed from r965979, httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntry.java
Removed:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntry.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHeaderGroup.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeaderConstants.java
Modified:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCache.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateCallback.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryGenerator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheInvalidator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheableRequestPolicy.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHttpResponseGenerator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedResponseSuitabilityChecker.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ConditionalRequestBuilder.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseCachingPolicy.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseProtocolCompliance.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/URIExtractor.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntry.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryGenerator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryUpdater.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheInvalidator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedHttpResponseGenerator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedResponseSuitabilityChecker.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClient.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestConditionalRequestBuilder.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestResponseCache.java

Copied: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/CachedHeaderGroup.java (from r965979, httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHeaderGroup.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/CachedHeaderGroup.java?p2=httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/CachedHeaderGroup.java&p1=httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHeaderGroup.java&r1=965979&r2=966642&rev=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHeaderGroup.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/CachedHeaderGroup.java Thu Jul 22 13:16:29 2010
@@ -24,7 +24,7 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.impl.client.cache;
+package org.apache.http.client.cache;
 
 import java.io.Serializable;
 
@@ -35,5 +35,5 @@ import org.apache.http.message.HeaderGro
 class CachedHeaderGroup extends HeaderGroup implements Serializable {
 
     private static final long serialVersionUID = -4572663568087431896L;
-    
+
 }

Copied: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HeaderConstants.java (from r965979, httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeaderConstants.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HeaderConstants.java?p2=httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HeaderConstants.java&p1=httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeaderConstants.java&r1=965979&r2=966642&rev=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeaderConstants.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HeaderConstants.java Thu Jul 22 13:16:29 2010
@@ -24,7 +24,7 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.impl.client.cache;
+package org.apache.http.client.cache;
 
 import org.apache.http.annotation.Immutable;
 
@@ -32,7 +32,7 @@ import org.apache.http.annotation.Immuta
  * @since 4.1
  */
 @Immutable
-class HeaderConstants {
+public class HeaderConstants {
 
     public static final String GET_METHOD = "GET";
     public static final String HEAD_METHOD = "HEAD";

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCache.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCache.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCache.java Thu Jul 22 13:16:29 2010
@@ -29,15 +29,15 @@ package org.apache.http.client.cache;
 /**
  * @since 4.1
  */
-public interface HttpCache<K, E> {
+public interface HttpCache {
 
-    void putEntry(K key, E entry) throws HttpCacheOperationException;
+    void putEntry(String key, HttpCacheEntry entry) throws HttpCacheOperationException;
 
-    E getEntry(K key) throws HttpCacheOperationException;
+    HttpCacheEntry getEntry(String key) throws HttpCacheOperationException;
 
-    void removeEntry(K key) throws HttpCacheOperationException;
+    void removeEntry(String key) throws HttpCacheOperationException;
 
     void updateEntry(
-            K key, HttpCacheUpdateCallback<E> callback) throws HttpCacheOperationException;
+            String key, HttpCacheUpdateCallback callback) throws HttpCacheOperationException;
 
 }

Copied: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntry.java (from r965979, httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntry.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntry.java?p2=httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntry.java&p1=httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntry.java&r1=965979&r2=966642&rev=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntry.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntry.java Thu Jul 22 13:16:29 2010
@@ -24,7 +24,7 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.impl.client.cache;
+package org.apache.http.client.cache;
 
 import java.io.IOException;
 import java.io.ObjectInputStream;
@@ -36,16 +36,12 @@ import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.http.Header;
-import org.apache.http.HeaderElement;
 import org.apache.http.HttpEntity;
-import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.ProtocolVersion;
+import org.apache.http.StatusLine;
 import org.apache.http.annotation.Immutable;
-import org.apache.http.impl.cookie.DateParseException;
-import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.message.BasicHeader;
-import org.apache.http.protocol.HTTP;
 
 /**
  * Structure used to store an {@link HttpResponse} in a cache
@@ -53,23 +49,19 @@ import org.apache.http.protocol.HTTP;
  * @since 4.1
  */
 @Immutable
-public class CacheEntry implements Serializable {
+public class HttpCacheEntry implements Serializable {
 
     private static final long serialVersionUID = -6300496422359477413L;
 
-    public static final long MAX_AGE = 2147483648L;
-
     private final Date requestDate;
     private final Date responseDate;
-    private final ProtocolVersion version;
-    private final int status;
-    private final String reason;
+    private final StatusLine statusLine;
     private final CachedHeaderGroup responseHeaders;
     private final HttpEntity body;
     private final Set<String> variantURIs;
 
     /**
-     * Create a new {@link CacheEntry}
+     * Create a new {@link HttpCacheEntry}
      *
      * @param requestDate
      *          Date/time when the request was made (Used for age
@@ -88,53 +80,53 @@ public class CacheEntry implements Seria
      * @param reason
      *          String message from HTTP Status Line
      */
-    public CacheEntry(Date requestDate, Date responseDate, ProtocolVersion version,
-            Header[] responseHeaders, HttpEntity body, int status, String reason) {
+    public HttpCacheEntry(
+            final Date requestDate,
+            final Date responseDate,
+            final StatusLine statusLine,
+            final Header[] responseHeaders,
+            final HttpEntity body,
+            final Set<String> variants) {
         super();
+        if (requestDate == null) {
+            throw new IllegalArgumentException("Request date may not be null");
+        }
+        if (responseDate == null) {
+            throw new IllegalArgumentException("Response date may not be null");
+        }
+        if (statusLine == null) {
+            throw new IllegalArgumentException("Status line may not be null");
+        }
+        if (responseHeaders == null) {
+            throw new IllegalArgumentException("Response headers may not be null");
+        }
+        if (body == null) {
+            throw new IllegalArgumentException("Response body may not be null");
+        }
         this.requestDate = requestDate;
         this.responseDate = responseDate;
-        this.version = version;
+        this.statusLine = statusLine;
         this.responseHeaders = new CachedHeaderGroup();
         this.responseHeaders.setHeaders(responseHeaders);
-        this.status = status;
-        this.reason = reason;
         this.body = body;
-        this.variantURIs = new HashSet<String>();
-
-    }
+        this.variantURIs = variants != null ? new HashSet<String>(variants) : new HashSet<String>();
 
-    /**
-     * Constructor used to create a copy of an existing entry, while adding another variant URI to it.
-     *
-     * @param entry CacheEntry to be duplicated
-     * @param variantURI URI to add
-     */
-    private CacheEntry(CacheEntry entry, String variantURI){
-        this(entry.getRequestDate(),
-                entry.getResponseDate(),
-                entry.getProtocolVersion(),
-                entry.getAllHeaders(),
-                entry.body,
-                entry.getStatusCode(),
-                entry.getReasonPhrase());
-        this.variantURIs.addAll(entry.getVariantURIs());
-        this.variantURIs.add(variantURI);
     }
 
-    public CacheEntry copyWithVariant(String variantURI){
-        return new CacheEntry(this,variantURI);
+    public StatusLine getStatusLine() {
+        return this.statusLine;
     }
 
     public ProtocolVersion getProtocolVersion() {
-        return version;
+        return this.statusLine.getProtocolVersion();
     }
 
     public String getReasonPhrase() {
-        return reason;
+        return this.statusLine.getReasonPhrase();
     }
 
     public int getStatusCode() {
-        return status;
+        return this.statusLine.getStatusCode();
     }
 
     public Date getRequestDate() {
@@ -161,211 +153,14 @@ public class CacheEntry implements Seria
         return responseHeaders.getHeaders(name);
     }
 
-    public long getCurrentAgeSecs() {
-        return getCorrectedInitialAgeSecs() + getResidentTimeSecs();
-    }
-
-    public long getFreshnessLifetimeSecs() {
-        long maxage = getMaxAge();
-        if (maxage > -1)
-            return maxage;
-
-        Date dateValue = getDateValue();
-        if (dateValue == null)
-            return 0L;
-
-        Date expiry = getExpirationDate();
-        if (expiry == null)
-            return 0;
-        long diff = expiry.getTime() - dateValue.getTime();
-        return (diff / 1000);
-    }
-
-    public boolean isResponseFresh() {
-        return (getCurrentAgeSecs() < getFreshnessLifetimeSecs());
-    }
-
-    /**
-     *
-     * @return boolean indicating whether ETag or Last-Modified responseHeaders
-     *         are present
-     */
-    public boolean isRevalidatable() {
-        return getFirstHeader(HeaderConstants.ETAG) != null
-                || getFirstHeader(HeaderConstants.LAST_MODIFIED) != null;
-
-    }
-
-    public boolean modifiedSince(HttpRequest request) {
-        Header unmodHeader = request.getFirstHeader(HeaderConstants.IF_UNMODIFIED_SINCE);
-
-        if (unmodHeader == null) {
-            return false;
-        }
-
-        try {
-            Date unmodifiedSinceDate = DateUtils.parseDate(unmodHeader.getValue());
-            Date lastModifiedDate = DateUtils.parseDate(getFirstHeader(
-                    HeaderConstants.LAST_MODIFIED).getValue());
-
-            if (unmodifiedSinceDate.before(lastModifiedDate)) {
-                return true;
-            }
-        } catch (DateParseException e) {
-            return false;
-        }
-
-        return false;
-    }
-
-    /**
-     *
-     * @return boolean indicating whether any Vary responseHeaders are present
-     */
     public boolean hasVariants() {
-        return (getFirstHeader(HeaderConstants.VARY) != null);
+        return getFirstHeader(HeaderConstants.VARY) != null;
     }
 
     public Set<String> getVariantURIs() {
         return Collections.unmodifiableSet(this.variantURIs);
     }
 
-    public boolean mustRevalidate() {
-        return hasCacheControlDirective("must-revalidate");
-    }
-    public boolean proxyRevalidate() {
-        return hasCacheControlDirective("proxy-revalidate");
-    }
-
-    Date getDateValue() {
-        Header dateHdr = getFirstHeader(HTTP.DATE_HEADER);
-        if (dateHdr == null)
-            return null;
-        try {
-            return DateUtils.parseDate(dateHdr.getValue());
-        } catch (DateParseException dpe) {
-            // ignore malformed date
-        }
-        return null;
-    }
-
-    long getContentLengthValue() {
-        Header cl = getFirstHeader(HTTP.CONTENT_LEN);
-        if (cl == null)
-            return -1;
-
-        try {
-            return Long.parseLong(cl.getValue());
-        } catch (NumberFormatException ex) {
-            return -1;
-        }
-    }
-
-    /**
-     * This matters for deciding whether the cache entry is valid to serve as a
-     * response. If these values do not match, we might have a partial response
-     *
-     * @return boolean indicating whether actual length matches Content-Length
-     */
-    boolean contentLengthHeaderMatchesActualLength() {
-        return getContentLengthValue() == body.getContentLength();
-    }
-
-    long getApparentAgeSecs() {
-        Date dateValue = getDateValue();
-        if (dateValue == null)
-            return MAX_AGE;
-        long diff = responseDate.getTime() - dateValue.getTime();
-        if (diff < 0L)
-            return 0;
-        return (diff / 1000);
-    }
-
-    long getAgeValue() {
-        long ageValue = 0;
-        for (Header hdr : getHeaders(HeaderConstants.AGE)) {
-            long hdrAge;
-            try {
-                hdrAge = Long.parseLong(hdr.getValue());
-                if (hdrAge < 0) {
-                    hdrAge = MAX_AGE;
-                }
-            } catch (NumberFormatException nfe) {
-                hdrAge = MAX_AGE;
-            }
-            ageValue = (hdrAge > ageValue) ? hdrAge : ageValue;
-        }
-        return ageValue;
-    }
-
-    long getCorrectedReceivedAgeSecs() {
-        long apparentAge = getApparentAgeSecs();
-        long ageValue = getAgeValue();
-        return (apparentAge > ageValue) ? apparentAge : ageValue;
-    }
-
-    long getResponseDelaySecs() {
-        long diff = responseDate.getTime() - requestDate.getTime();
-        return (diff / 1000L);
-    }
-
-    long getCorrectedInitialAgeSecs() {
-        return getCorrectedReceivedAgeSecs() + getResponseDelaySecs();
-    }
-
-    Date getCurrentDate() {
-        return new Date();
-    }
-
-    long getResidentTimeSecs() {
-        long diff = getCurrentDate().getTime() - responseDate.getTime();
-        return (diff / 1000L);
-    }
-
-    long getMaxAge() {
-        long maxage = -1;
-        for (Header hdr : getHeaders(HeaderConstants.CACHE_CONTROL)) {
-            for (HeaderElement elt : hdr.getElements()) {
-                if (HeaderConstants.CACHE_CONTROL_MAX_AGE.equals(elt.getName())
-                        || "s-maxage".equals(elt.getName())) {
-                    try {
-                        long currMaxAge = Long.parseLong(elt.getValue());
-                        if (maxage == -1 || currMaxAge < maxage) {
-                            maxage = currMaxAge;
-                        }
-                    } catch (NumberFormatException nfe) {
-                        // be conservative if can't parse
-                        maxage = 0;
-                    }
-                }
-            }
-        }
-        return maxage;
-    }
-
-    Date getExpirationDate() {
-        Header expiresHeader = getFirstHeader(HeaderConstants.EXPIRES);
-        if (expiresHeader == null)
-            return null;
-        try {
-            return DateUtils.parseDate(expiresHeader.getValue());
-        } catch (DateParseException dpe) {
-            // malformed expires header
-        }
-        return null;
-    }
-
-    boolean hasCacheControlDirective(String directive) {
-        for(Header h : responseHeaders.getHeaders("Cache-Control")) {
-            for(HeaderElement elt : h.getElements()) {
-                if (directive.equalsIgnoreCase(elt.getName())) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
     private void writeObject(ObjectOutputStream out) throws IOException {
 
         // write CacheEntry
@@ -405,8 +200,19 @@ public class CacheEntry implements Seria
 
     @Override
     public String toString() {
-        return "[request date=" + requestDate + "; response date=" + responseDate
-                + "; status=" + status + "]";
+        return "[request date=" + this.requestDate + "; response date=" + this.responseDate
+                + "; statusLine=" + this.statusLine + "]";
+    }
+
+    public static HttpCacheEntry copyWithVariant(final HttpCacheEntry entry, final String variantURI){
+        Set<String> variants = new HashSet<String>(entry.getVariantURIs());
+        variants.add(variantURI);
+        return new HttpCacheEntry(
+                entry.getRequestDate(),
+                entry.getResponseDate(),
+                entry.getStatusLine(),
+                entry.getAllHeaders(),
+                entry.getBody(), variants);
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateCallback.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateCallback.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateCallback.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateCallback.java Thu Jul 22 13:16:29 2010
@@ -26,7 +26,7 @@
  */
 package org.apache.http.client.cache;
 
-public interface HttpCacheUpdateCallback<E> {
+public interface HttpCacheUpdateCallback {
 
     /**
      * Returns the new cache entry that should replace an existing one.
@@ -41,6 +41,6 @@ public interface HttpCacheUpdateCallback
      *
      * @since 4.1
      */
-    E update(E existing) throws HttpCacheOperationException;
+    HttpCacheEntry update(HttpCacheEntry existing) throws HttpCacheOperationException;
 
 }
\ No newline at end of file

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java Thu Jul 22 13:16:29 2010
@@ -31,6 +31,7 @@ import java.util.Map;
 
 import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.client.cache.HttpCache;
+import org.apache.http.client.cache.HttpCacheEntry;
 import org.apache.http.client.cache.HttpCacheOperationException;
 import org.apache.http.client.cache.HttpCacheUpdateCallback;
 
@@ -40,15 +41,15 @@ import org.apache.http.client.cache.Http
  * @since 4.1
  */
 @ThreadSafe
-public class BasicHttpCache implements HttpCache<String, CacheEntry> {
+public class BasicHttpCache implements HttpCache {
 
-    private final LinkedHashMap<String, CacheEntry> baseMap = new LinkedHashMap<String, CacheEntry>(
+    private final LinkedHashMap<String, HttpCacheEntry> baseMap = new LinkedHashMap<String, HttpCacheEntry>(
             20, 0.75f, true) {
 
         private static final long serialVersionUID = -7750025207539768511L;
 
         @Override
-        protected boolean removeEldestEntry(Map.Entry<String, CacheEntry> eldest) {
+        protected boolean removeEldestEntry(Map.Entry<String, HttpCacheEntry> eldest) {
             return size() > maxEntries;
         }
 
@@ -61,14 +62,14 @@ public class BasicHttpCache implements H
     }
 
     /**
-     * Places a CacheEntry in the cache
+     * Places a HttpCacheEntry in the cache
      *
      * @param url
      *            Url to use as the cache key
      * @param entry
-     *            CacheEntry to place in the cache
+     *            HttpCacheEntry to place in the cache
      */
-    public synchronized void putEntry(String url, CacheEntry entry) {
+    public synchronized void putEntry(String url, HttpCacheEntry entry) {
         baseMap.put(url, entry);
     }
 
@@ -77,14 +78,14 @@ public class BasicHttpCache implements H
      *
      * @param url
      *            Url that is the cache key
-     * @return CacheEntry if one exists, or null for cache miss
+     * @return HttpCacheEntry if one exists, or null for cache miss
      */
-    public synchronized CacheEntry getEntry(String url) {
+    public synchronized HttpCacheEntry getEntry(String url) {
         return baseMap.get(url);
     }
 
     /**
-     * Removes a CacheEntry from the cache
+     * Removes a HttpCacheEntry from the cache
      *
      * @param url
      *            Url that is the cache key
@@ -95,8 +96,8 @@ public class BasicHttpCache implements H
 
     public synchronized void updateEntry(
             String url,
-            HttpCacheUpdateCallback<CacheEntry> callback) throws HttpCacheOperationException {
-        CacheEntry existingEntry = baseMap.get(url);
+            HttpCacheUpdateCallback callback) throws HttpCacheOperationException {
+        HttpCacheEntry existingEntry = baseMap.get(url);
         baseMap.put(url, callback.update(existingEntry));
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryGenerator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryGenerator.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryGenerator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryGenerator.java Thu Jul 22 13:16:29 2010
@@ -30,6 +30,7 @@ import java.util.Date;
 
 import org.apache.http.HttpResponse;
 import org.apache.http.annotation.Immutable;
+import org.apache.http.client.cache.HttpCacheEntry;
 
 /**
  * Generates a {@link CacheEntry} from a {@link HttpResponse}
@@ -39,18 +40,18 @@ import org.apache.http.annotation.Immuta
 @Immutable
 class CacheEntryGenerator {
 
-    public CacheEntry generateEntry(
-            Date requestDate, 
-            Date responseDate, 
+    public HttpCacheEntry generateEntry(
+            Date requestDate,
+            Date responseDate,
             HttpResponse response,
             byte[] body) {
         CacheEntity entity = new CacheEntity(body, response);
-        return new CacheEntry(requestDate,
+        return new HttpCacheEntry(requestDate,
                               responseDate,
-                              response.getProtocolVersion(),
+                              response.getStatusLine(),
                               response.getAllHeaders(),
                               entity,
-                              response.getStatusLine().getStatusCode(),
-                              response.getStatusLine().getReasonPhrase());
+                              null);
     }
+
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java Thu Jul 22 13:16:29 2010
@@ -36,12 +36,14 @@ import java.util.ListIterator;
 import org.apache.http.Header;
 import org.apache.http.HttpResponse;
 import org.apache.http.annotation.Immutable;
+import org.apache.http.client.cache.HeaderConstants;
+import org.apache.http.client.cache.HttpCacheEntry;
 import org.apache.http.impl.cookie.DateParseException;
 import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.protocol.HTTP;
 
 /**
- * Update a {@link CacheEntry} with new or updated information based on the latest
+ * Update a {@link HttpCacheEntry} with new or updated information based on the latest
  * 200 or 304 status responses from the Server.  Use the {@link HttpResponse} to perform
  * the update.
  *
@@ -57,27 +59,25 @@ class CacheEntryUpdater {
      * @param requestDate When the request was performed
      * @param responseDate When the response was gotten
      * @param response The HttpResponse from the backend server call
-     * @return CacheEntry an updated version of the cache entry
+     * @return HttpCacheEntry an updated version of the cache entry
      * @throws java.io.IOException if something bad happens while trying to read the body from the original entry
      */
-    public CacheEntry updateCacheEntry(
-            CacheEntry entry,
+    public HttpCacheEntry updateCacheEntry(
+            HttpCacheEntry entry,
             Date requestDate,
             Date responseDate,
             HttpResponse response) throws IOException {
 
         Header[] mergedHeaders = mergeHeaders(entry, response);
-        CacheEntry updated = new CacheEntry(requestDate, responseDate,
-                                            entry.getProtocolVersion(),
+        HttpCacheEntry updated = new HttpCacheEntry(requestDate, responseDate,
+                                            entry.getStatusLine(),
                                             mergedHeaders,
                                             entry.getBody(),
-                                            entry.getStatusCode(),
-                                            entry.getReasonPhrase());
-
+                                            null);
         return updated;
     }
 
-    protected Header[] mergeHeaders(CacheEntry entry, HttpResponse response) {
+    protected Header[] mergeHeaders(HttpCacheEntry entry, HttpResponse response) {
         List<Header> cacheEntryHeaderList = new ArrayList<Header>(Arrays.asList(entry
                 .getAllHeaders()));
 
@@ -112,7 +112,7 @@ class CacheEntryUpdater {
         }
     }
 
-    private void removeCacheEntry1xxWarnings(List<Header> cacheEntryHeaderList, CacheEntry entry) {
+    private void removeCacheEntry1xxWarnings(List<Header> cacheEntryHeaderList, HttpCacheEntry entry) {
         ListIterator<Header> cacheEntryHeaderListIter = cacheEntryHeaderList.listIterator();
 
         while (cacheEntryHeaderListIter.hasNext()) {
@@ -128,7 +128,7 @@ class CacheEntryUpdater {
         }
     }
 
-    private boolean entryDateHeaderNewerThenResponse(CacheEntry entry, HttpResponse response) {
+    private boolean entryDateHeaderNewerThenResponse(HttpCacheEntry entry, HttpResponse response) {
         try {
             Date entryDate = DateUtils.parseDate(entry.getFirstHeader(HTTP.DATE_HEADER)
                     .getValue());
@@ -145,7 +145,7 @@ class CacheEntryUpdater {
         return true;
     }
 
-    private boolean entryAndResponseHaveDateHeader(CacheEntry entry, HttpResponse response) {
+    private boolean entryAndResponseHaveDateHeader(HttpCacheEntry entry, HttpResponse response) {
         if (entry.getFirstHeader(HTTP.DATE_HEADER) != null
                 && response.getFirstHeader(HTTP.DATE_HEADER) != null) {
             return true;

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheInvalidator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheInvalidator.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheInvalidator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheInvalidator.java Thu Jul 22 13:16:29 2010
@@ -36,7 +36,9 @@ import org.apache.http.HeaderElement;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.annotation.ThreadSafe;
+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.HttpCacheOperationException;
 
 /**
@@ -48,7 +50,7 @@ import org.apache.http.client.cache.Http
 @ThreadSafe // so long as the cache implementation is thread-safe
 class CacheInvalidator {
 
-    private final HttpCache<String, CacheEntry> cache;
+    private final HttpCache cache;
     private final URIExtractor uriExtractor;
 
     private final Log log = LogFactory.getLog(getClass());
@@ -60,7 +62,9 @@ class CacheInvalidator {
      * @param uriExtractor Provides identifiers for the keys to store cache entries
      * @param cache the cache to store items away in
      */
-    public CacheInvalidator(URIExtractor uriExtractor, HttpCache<String, CacheEntry> cache) {
+    public CacheInvalidator(
+            final URIExtractor uriExtractor,
+            final HttpCache cache) {
         this.uriExtractor = uriExtractor;
         this.cache = cache;
     }
@@ -79,7 +83,7 @@ class CacheInvalidator {
             try {
                 String theUri = uriExtractor.getURI(host, req);
 
-                CacheEntry parent = cache.getEntry(theUri);
+                HttpCacheEntry parent = cache.getEntry(theUri);
 
                 log.debug("parent entry: " + parent);
 

Copied: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheValidityPolicy.java (from r965979, httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntry.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheValidityPolicy.java?p2=httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheValidityPolicy.java&p1=httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntry.java&r1=965979&r2=966642&rev=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntry.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheValidityPolicy.java Thu Jul 22 13:16:29 2010
@@ -26,177 +26,60 @@
  */
 package org.apache.http.impl.client.cache;
 
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.Collections;
 import java.util.Date;
-import java.util.HashSet;
-import java.util.Set;
 
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
-import org.apache.http.HttpEntity;
 import org.apache.http.HttpRequest;
-import org.apache.http.HttpResponse;
-import org.apache.http.ProtocolVersion;
 import org.apache.http.annotation.Immutable;
+import org.apache.http.client.cache.HeaderConstants;
+import org.apache.http.client.cache.HttpCacheEntry;
 import org.apache.http.impl.cookie.DateParseException;
 import org.apache.http.impl.cookie.DateUtils;
-import org.apache.http.message.BasicHeader;
 import org.apache.http.protocol.HTTP;
 
 /**
- * Structure used to store an {@link HttpResponse} in a cache
- *
  * @since 4.1
  */
 @Immutable
-public class CacheEntry implements Serializable {
-
-    private static final long serialVersionUID = -6300496422359477413L;
+class CacheValidityPolicy {
 
     public static final long MAX_AGE = 2147483648L;
 
-    private final Date requestDate;
-    private final Date responseDate;
-    private final ProtocolVersion version;
-    private final int status;
-    private final String reason;
-    private final CachedHeaderGroup responseHeaders;
-    private final HttpEntity body;
-    private final Set<String> variantURIs;
-
-    /**
-     * Create a new {@link CacheEntry}
-     *
-     * @param requestDate
-     *          Date/time when the request was made (Used for age
-     *            calculations)
-     * @param responseDate
-     *          Date/time that the response came back (Used for age
-     *            calculations)
-     * @param version
-     *          HTTP Response Version
-     * @param responseHeaders
-     *          Header[] from original HTTP Response
-     * @param body
-     *          HttpEntity representing the body of the response
-     * @param status
-     *          Numeric HTTP Status Code
-     * @param reason
-     *          String message from HTTP Status Line
-     */
-    public CacheEntry(Date requestDate, Date responseDate, ProtocolVersion version,
-            Header[] responseHeaders, HttpEntity body, int status, String reason) {
+    CacheValidityPolicy() {
         super();
-        this.requestDate = requestDate;
-        this.responseDate = responseDate;
-        this.version = version;
-        this.responseHeaders = new CachedHeaderGroup();
-        this.responseHeaders.setHeaders(responseHeaders);
-        this.status = status;
-        this.reason = reason;
-        this.body = body;
-        this.variantURIs = new HashSet<String>();
-
-    }
-
-    /**
-     * Constructor used to create a copy of an existing entry, while adding another variant URI to it.
-     *
-     * @param entry CacheEntry to be duplicated
-     * @param variantURI URI to add
-     */
-    private CacheEntry(CacheEntry entry, String variantURI){
-        this(entry.getRequestDate(),
-                entry.getResponseDate(),
-                entry.getProtocolVersion(),
-                entry.getAllHeaders(),
-                entry.body,
-                entry.getStatusCode(),
-                entry.getReasonPhrase());
-        this.variantURIs.addAll(entry.getVariantURIs());
-        this.variantURIs.add(variantURI);
-    }
-
-    public CacheEntry copyWithVariant(String variantURI){
-        return new CacheEntry(this,variantURI);
-    }
-
-    public ProtocolVersion getProtocolVersion() {
-        return version;
-    }
-
-    public String getReasonPhrase() {
-        return reason;
-    }
-
-    public int getStatusCode() {
-        return status;
-    }
-
-    public Date getRequestDate() {
-        return requestDate;
     }
 
-    public Date getResponseDate() {
-        return responseDate;
+    public long getCurrentAgeSecs(final HttpCacheEntry entry) {
+        return getCorrectedInitialAgeSecs(entry) + getResidentTimeSecs(entry);
     }
 
-    public HttpEntity getBody() {
-        return body;
-    }
-
-    public Header[] getAllHeaders() {
-        return responseHeaders.getAllHeaders();
-    }
-
-    public Header getFirstHeader(String name) {
-        return responseHeaders.getFirstHeader(name);
-    }
-
-    public Header[] getHeaders(String name) {
-        return responseHeaders.getHeaders(name);
-    }
-
-    public long getCurrentAgeSecs() {
-        return getCorrectedInitialAgeSecs() + getResidentTimeSecs();
-    }
-
-    public long getFreshnessLifetimeSecs() {
-        long maxage = getMaxAge();
+    public long getFreshnessLifetimeSecs(final HttpCacheEntry entry) {
+        long maxage = getMaxAge(entry);
         if (maxage > -1)
             return maxage;
 
-        Date dateValue = getDateValue();
+        Date dateValue = getDateValue(entry);
         if (dateValue == null)
             return 0L;
 
-        Date expiry = getExpirationDate();
+        Date expiry = getExpirationDate(entry);
         if (expiry == null)
             return 0;
         long diff = expiry.getTime() - dateValue.getTime();
         return (diff / 1000);
     }
 
-    public boolean isResponseFresh() {
-        return (getCurrentAgeSecs() < getFreshnessLifetimeSecs());
+    public boolean isResponseFresh(final HttpCacheEntry entry) {
+        return (getCurrentAgeSecs(entry) < getFreshnessLifetimeSecs(entry));
     }
 
-    /**
-     *
-     * @return boolean indicating whether ETag or Last-Modified responseHeaders
-     *         are present
-     */
-    public boolean isRevalidatable() {
-        return getFirstHeader(HeaderConstants.ETAG) != null
-                || getFirstHeader(HeaderConstants.LAST_MODIFIED) != null;
-
+    public boolean isRevalidatable(final HttpCacheEntry entry) {
+        return entry.getFirstHeader(HeaderConstants.ETAG) != null
+                || entry.getFirstHeader(HeaderConstants.LAST_MODIFIED) != null;
     }
 
-    public boolean modifiedSince(HttpRequest request) {
+    public boolean modifiedSince(final HttpCacheEntry entry, final HttpRequest request) {
         Header unmodHeader = request.getFirstHeader(HeaderConstants.IF_UNMODIFIED_SINCE);
 
         if (unmodHeader == null) {
@@ -205,7 +88,7 @@ public class CacheEntry implements Seria
 
         try {
             Date unmodifiedSinceDate = DateUtils.parseDate(unmodHeader.getValue());
-            Date lastModifiedDate = DateUtils.parseDate(getFirstHeader(
+            Date lastModifiedDate = DateUtils.parseDate(entry.getFirstHeader(
                     HeaderConstants.LAST_MODIFIED).getValue());
 
             if (unmodifiedSinceDate.before(lastModifiedDate)) {
@@ -218,27 +101,16 @@ public class CacheEntry implements Seria
         return false;
     }
 
-    /**
-     *
-     * @return boolean indicating whether any Vary responseHeaders are present
-     */
-    public boolean hasVariants() {
-        return (getFirstHeader(HeaderConstants.VARY) != null);
+    public boolean mustRevalidate(final HttpCacheEntry entry) {
+        return hasCacheControlDirective(entry, "must-revalidate");
     }
 
-    public Set<String> getVariantURIs() {
-        return Collections.unmodifiableSet(this.variantURIs);
+    public boolean proxyRevalidate(final HttpCacheEntry entry) {
+        return hasCacheControlDirective(entry, "proxy-revalidate");
     }
 
-    public boolean mustRevalidate() {
-        return hasCacheControlDirective("must-revalidate");
-    }
-    public boolean proxyRevalidate() {
-        return hasCacheControlDirective("proxy-revalidate");
-    }
-
-    Date getDateValue() {
-        Header dateHdr = getFirstHeader(HTTP.DATE_HEADER);
+    protected Date getDateValue(final HttpCacheEntry entry) {
+        Header dateHdr = entry.getFirstHeader(HTTP.DATE_HEADER);
         if (dateHdr == null)
             return null;
         try {
@@ -249,8 +121,8 @@ public class CacheEntry implements Seria
         return null;
     }
 
-    long getContentLengthValue() {
-        Header cl = getFirstHeader(HTTP.CONTENT_LEN);
+    protected long getContentLengthValue(final HttpCacheEntry entry) {
+        Header cl = entry.getFirstHeader(HTTP.CONTENT_LEN);
         if (cl == null)
             return -1;
 
@@ -267,23 +139,23 @@ public class CacheEntry implements Seria
      *
      * @return boolean indicating whether actual length matches Content-Length
      */
-    boolean contentLengthHeaderMatchesActualLength() {
-        return getContentLengthValue() == body.getContentLength();
+    protected boolean contentLengthHeaderMatchesActualLength(final HttpCacheEntry entry) {
+        return getContentLengthValue(entry) == entry.getBody().getContentLength();
     }
 
-    long getApparentAgeSecs() {
-        Date dateValue = getDateValue();
+    protected long getApparentAgeSecs(final HttpCacheEntry entry) {
+        Date dateValue = getDateValue(entry);
         if (dateValue == null)
             return MAX_AGE;
-        long diff = responseDate.getTime() - dateValue.getTime();
+        long diff = entry.getResponseDate().getTime() - dateValue.getTime();
         if (diff < 0L)
             return 0;
         return (diff / 1000);
     }
 
-    long getAgeValue() {
+    protected long getAgeValue(final HttpCacheEntry entry) {
         long ageValue = 0;
-        for (Header hdr : getHeaders(HeaderConstants.AGE)) {
+        for (Header hdr : entry.getHeaders(HeaderConstants.AGE)) {
             long hdrAge;
             try {
                 hdrAge = Long.parseLong(hdr.getValue());
@@ -298,33 +170,33 @@ public class CacheEntry implements Seria
         return ageValue;
     }
 
-    long getCorrectedReceivedAgeSecs() {
-        long apparentAge = getApparentAgeSecs();
-        long ageValue = getAgeValue();
+    protected long getCorrectedReceivedAgeSecs(final HttpCacheEntry entry) {
+        long apparentAge = getApparentAgeSecs(entry);
+        long ageValue = getAgeValue(entry);
         return (apparentAge > ageValue) ? apparentAge : ageValue;
     }
 
-    long getResponseDelaySecs() {
-        long diff = responseDate.getTime() - requestDate.getTime();
+    protected long getResponseDelaySecs(final HttpCacheEntry entry) {
+        long diff = entry.getResponseDate().getTime() - entry.getRequestDate().getTime();
         return (diff / 1000L);
     }
 
-    long getCorrectedInitialAgeSecs() {
-        return getCorrectedReceivedAgeSecs() + getResponseDelaySecs();
+    protected long getCorrectedInitialAgeSecs(final HttpCacheEntry entry) {
+        return getCorrectedReceivedAgeSecs(entry) + getResponseDelaySecs(entry);
     }
 
-    Date getCurrentDate() {
+    protected Date getCurrentDate() {
         return new Date();
     }
 
-    long getResidentTimeSecs() {
-        long diff = getCurrentDate().getTime() - responseDate.getTime();
+    protected long getResidentTimeSecs(final HttpCacheEntry entry) {
+        long diff = getCurrentDate().getTime() - entry.getResponseDate().getTime();
         return (diff / 1000L);
     }
 
-    long getMaxAge() {
+    protected long getMaxAge(final HttpCacheEntry entry) {
         long maxage = -1;
-        for (Header hdr : getHeaders(HeaderConstants.CACHE_CONTROL)) {
+        for (Header hdr : entry.getHeaders(HeaderConstants.CACHE_CONTROL)) {
             for (HeaderElement elt : hdr.getElements()) {
                 if (HeaderConstants.CACHE_CONTROL_MAX_AGE.equals(elt.getName())
                         || "s-maxage".equals(elt.getName())) {
@@ -343,8 +215,8 @@ public class CacheEntry implements Seria
         return maxage;
     }
 
-    Date getExpirationDate() {
-        Header expiresHeader = getFirstHeader(HeaderConstants.EXPIRES);
+    protected Date getExpirationDate(final HttpCacheEntry entry) {
+        Header expiresHeader = entry.getFirstHeader(HeaderConstants.EXPIRES);
         if (expiresHeader == null)
             return null;
         try {
@@ -355,8 +227,8 @@ public class CacheEntry implements Seria
         return null;
     }
 
-    boolean hasCacheControlDirective(String directive) {
-        for(Header h : responseHeaders.getHeaders("Cache-Control")) {
+    protected boolean hasCacheControlDirective(final HttpCacheEntry entry, final String directive) {
+        for (Header h : entry.getHeaders("Cache-Control")) {
             for(HeaderElement elt : h.getElements()) {
                 if (directive.equalsIgnoreCase(elt.getName())) {
                     return true;
@@ -366,47 +238,4 @@ public class CacheEntry implements Seria
         return false;
     }
 
-    private void writeObject(ObjectOutputStream out) throws IOException {
-
-        // write CacheEntry
-        out.defaultWriteObject();
-
-        // write (non-serializable) responseHeaders
-        if (null == responseHeaders || responseHeaders.getAllHeaders().length < 1)
-            return;
-        int headerCount = responseHeaders.getAllHeaders().length;
-        Header[] headers = responseHeaders.getAllHeaders();
-        String[][] sheaders = new String[headerCount][2];
-        for (int i = 0; i < headerCount; i++) {
-            sheaders[i][0] = headers[i].getName();
-            sheaders[i][1] = headers[i].getValue();
-        }
-        out.writeObject(sheaders);
-
-    }
-
-    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
-
-        // read CacheEntry
-        in.defaultReadObject();
-
-        // read (non-serializable) responseHeaders
-        String[][] sheaders = (String[][]) in.readObject();
-        if (null == sheaders || sheaders.length < 1)
-            return;
-        BasicHeader[] headers = new BasicHeader[sheaders.length];
-        for (int i = 0; i < sheaders.length; i++) {
-            String[] sheader = sheaders[i];
-            headers[i] = new BasicHeader(sheader[0], sheader[1]);
-        }
-
-        this.responseHeaders.setHeaders(headers);
-    }
-
-    @Override
-    public String toString() {
-        return "[request date=" + requestDate + "; response date=" + responseDate
-                + "; status=" + status + "]";
-    }
-
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheableRequestPolicy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheableRequestPolicy.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheableRequestPolicy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheableRequestPolicy.java Thu Jul 22 13:16:29 2010
@@ -34,6 +34,7 @@ import org.apache.http.HttpRequest;
 import org.apache.http.HttpVersion;
 import org.apache.http.ProtocolVersion;
 import org.apache.http.annotation.Immutable;
+import org.apache.http.client.cache.HeaderConstants;
 
 /**
  * Determines if an HttpRequest is allowed to be served from the cache.

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHttpResponseGenerator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHttpResponseGenerator.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHttpResponseGenerator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHttpResponseGenerator.java Thu Jul 22 13:16:29 2010
@@ -32,6 +32,8 @@ import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
 import org.apache.http.annotation.Immutable;
+import org.apache.http.client.cache.HeaderConstants;
+import org.apache.http.client.cache.HttpCacheEntry;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.message.BasicHttpResponse;
 import org.apache.http.protocol.HTTP;
@@ -44,6 +46,17 @@ import org.apache.http.protocol.HTTP;
 @Immutable
 class CachedHttpResponseGenerator {
 
+    private final CacheValidityPolicy validityStrategy;
+
+    CachedHttpResponseGenerator(final CacheValidityPolicy validityStrategy) {
+        super();
+        this.validityStrategy = validityStrategy;
+    }
+
+    CachedHttpResponseGenerator() {
+        this(new CacheValidityPolicy());
+    }
+
     /**
      * If I was able to use a {@link CacheEntry} to response to the {@link org.apache.http.HttpRequest} then
      * generate an {@link HttpResponse} based on the cache entry.
@@ -51,7 +64,7 @@ class CachedHttpResponseGenerator {
      *            {@link CacheEntry} to transform into an {@link HttpResponse}
      * @return {@link HttpResponse} that was constructed
      */
-    HttpResponse generateResponse(CacheEntry entry) {
+    HttpResponse generateResponse(HttpCacheEntry entry) {
 
         HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, entry
                 .getStatusCode(), entry.getReasonPhrase());
@@ -63,7 +76,7 @@ class CachedHttpResponseGenerator {
             addMissingContentLengthHeader(response, entity);
         }
 
-        long age = entry.getCurrentAgeSecs();
+        long age = this.validityStrategy.getCurrentAgeSecs(entry);
         if (age > 0) {
             if (age >= Integer.MAX_VALUE) {
                 response.setHeader(HeaderConstants.AGE, "2147483648");

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedResponseSuitabilityChecker.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedResponseSuitabilityChecker.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedResponseSuitabilityChecker.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedResponseSuitabilityChecker.java Thu Jul 22 13:16:29 2010
@@ -33,9 +33,11 @@ import org.apache.http.HeaderElement;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.annotation.Immutable;
+import org.apache.http.client.cache.HeaderConstants;
+import org.apache.http.client.cache.HttpCacheEntry;
 
 /**
- * Determines whether a given {@link CacheEntry} is suitable to be
+ * Determines whether a given {@link HttpCacheEntry} is suitable to be
  * used as a response for a given {@link HttpRequest}.
  *
  * @since 4.1
@@ -45,8 +47,19 @@ class CachedResponseSuitabilityChecker {
 
     private final Log log = LogFactory.getLog(getClass());
 
+    private final CacheValidityPolicy validityStrategy;
+
+    CachedResponseSuitabilityChecker(final CacheValidityPolicy validityStrategy) {
+        super();
+        this.validityStrategy = validityStrategy;
+    }
+
+    CachedResponseSuitabilityChecker() {
+        this(new CacheValidityPolicy());
+    }
+
     /**
-     * Determine if I can utilize a {@link CacheEntry} to respond to the given
+     * Determine if I can utilize a {@link HttpCacheEntry} to respond to the given
      * {@link HttpRequest}
      *
      * @param host
@@ -54,21 +67,21 @@ class CachedResponseSuitabilityChecker {
      * @param request
      *            {@link HttpRequest}
      * @param entry
-     *            {@link CacheEntry}
+     *            {@link HttpCacheEntry}
      * @return boolean yes/no answer
      */
-    public boolean canCachedResponseBeUsed(HttpHost host, HttpRequest request, CacheEntry entry) {
-        if (!entry.isResponseFresh()) {
+    public boolean canCachedResponseBeUsed(HttpHost host, HttpRequest request, HttpCacheEntry entry) {
+        if (!validityStrategy.isResponseFresh(entry)) {
             log.debug("Cache entry was not fresh enough");
             return false;
         }
 
-        if (!entry.contentLengthHeaderMatchesActualLength()) {
+        if (!validityStrategy.contentLengthHeaderMatchesActualLength(entry)) {
             log.debug("Cache entry Content-Length and header information do not match");
             return false;
         }
 
-        if (entry.modifiedSince(request)) {
+        if (validityStrategy.modifiedSince(entry, request)) {
             log.debug("Cache entry modified times didn't line up. Cache Entry should not be used");
             return false;
         }
@@ -88,7 +101,7 @@ class CachedResponseSuitabilityChecker {
                 if (HeaderConstants.CACHE_CONTROL_MAX_AGE.equals(elt.getName())) {
                     try {
                         int maxage = Integer.parseInt(elt.getValue());
-                        if (entry.getCurrentAgeSecs() > maxage) {
+                        if (validityStrategy.getCurrentAgeSecs(entry) > maxage) {
                             log.debug("Response from cache was NOT suitable due to max age");
                             return false;
                         }
@@ -102,7 +115,7 @@ class CachedResponseSuitabilityChecker {
                 if (HeaderConstants.CACHE_CONTROL_MAX_STALE.equals(elt.getName())) {
                     try {
                         int maxstale = Integer.parseInt(elt.getValue());
-                        if (entry.getFreshnessLifetimeSecs() > maxstale) {
+                        if (validityStrategy.getFreshnessLifetimeSecs(entry) > maxstale) {
                             log.debug("Response from cache was not suitable due to Max stale freshness");
                             return false;
                         }
@@ -116,7 +129,7 @@ class CachedResponseSuitabilityChecker {
                 if (HeaderConstants.CACHE_CONTROL_MIN_FRESH.equals(elt.getName())) {
                     try {
                         int minfresh = Integer.parseInt(elt.getValue());
-                        if (entry.getFreshnessLifetimeSecs() < minfresh) {
+                        if (validityStrategy.getFreshnessLifetimeSecs(entry) < minfresh) {
                             log.debug("Response from cache was not suitable due to min fresh " +
                                     "freshness requirement");
                             return false;

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java Thu Jul 22 13:16:29 2010
@@ -47,7 +47,9 @@ import org.apache.http.annotation.Thread
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.ResponseHandler;
+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.HttpCacheOperationException;
 import org.apache.http.client.cache.HttpCacheUpdateCallback;
 import org.apache.http.client.methods.HttpUriRequest;
@@ -75,10 +77,11 @@ public class CachingHttpClient implement
     private final AtomicLong cacheUpdates = new AtomicLong();
 
     private final HttpClient backend;
+    private final HttpCache responseCache;
+    private final CacheValidityPolicy validityPolicy;
     private final ResponseCachingPolicy responseCachingPolicy;
     private final CacheEntryGenerator cacheEntryGenerator;
     private final URIExtractor uriExtractor;
-    private final HttpCache<String, CacheEntry> responseCache;
     private final CachedHttpResponseGenerator responseGenerator;
     private final CacheInvalidator cacheInvalidator;
     private final CacheableRequestPolicy cacheableRequestPolicy;
@@ -93,17 +96,18 @@ public class CachingHttpClient implement
 
     private final Log log = LogFactory.getLog(getClass());
 
-    public CachingHttpClient(HttpClient client, HttpCache<String, CacheEntry> cache, int maxObjectSizeBytes) {
+    public CachingHttpClient(HttpClient client, HttpCache cache, int maxObjectSizeBytes) {
         super();
-        this.responseCache = cache;
         this.backend = client;
+        this.responseCache = cache;
+        this.validityPolicy = new CacheValidityPolicy();
         this.responseCachingPolicy = new ResponseCachingPolicy(maxObjectSizeBytes);
+        this.responseGenerator = new CachedHttpResponseGenerator(this.validityPolicy);
         this.cacheEntryGenerator = new CacheEntryGenerator();
         this.uriExtractor = new URIExtractor();
-        this.responseGenerator = new CachedHttpResponseGenerator();
         this.cacheInvalidator = new CacheInvalidator(this.uriExtractor, this.responseCache);
         this.cacheableRequestPolicy = new CacheableRequestPolicy();
-        this.suitabilityChecker = new CachedResponseSuitabilityChecker();
+        this.suitabilityChecker = new CachedResponseSuitabilityChecker(this.validityPolicy);
         this.conditionalRequestBuilder = new ConditionalRequestBuilder();
         this.cacheEntryUpdater = new CacheEntryUpdater();
         this.maxObjectSizeBytes = maxObjectSizeBytes;
@@ -115,13 +119,13 @@ public class CachingHttpClient implement
         this(new DefaultHttpClient(), new BasicHttpCache(MAX_CACHE_ENTRIES), DEFAULT_MAX_OBJECT_SIZE_BYTES);
     }
 
-    public CachingHttpClient(HttpCache<String, CacheEntry> cache, int maxObjectSizeBytes) {
+    public CachingHttpClient(HttpCache cache, int maxObjectSizeBytes) {
         this(new DefaultHttpClient(), cache, maxObjectSizeBytes);
     }
 
-    CachingHttpClient(HttpClient backend, ResponseCachingPolicy responseCachingPolicy,
+    CachingHttpClient(HttpClient backend, CacheValidityPolicy validityPolicy, ResponseCachingPolicy responseCachingPolicy,
                              CacheEntryGenerator cacheEntryGenerator, URIExtractor uriExtractor,
-                             HttpCache<String, CacheEntry> responseCache, CachedHttpResponseGenerator responseGenerator,
+                             HttpCache responseCache, CachedHttpResponseGenerator responseGenerator,
                              CacheInvalidator cacheInvalidator, CacheableRequestPolicy cacheableRequestPolicy,
                              CachedResponseSuitabilityChecker suitabilityChecker,
                              ConditionalRequestBuilder conditionalRequestBuilder, CacheEntryUpdater entryUpdater,
@@ -129,6 +133,7 @@ public class CachingHttpClient implement
                              RequestProtocolCompliance requestCompliance) {
         this.maxObjectSizeBytes = DEFAULT_MAX_OBJECT_SIZE_BYTES;
         this.backend = backend;
+        this.validityPolicy = validityPolicy;
         this.responseCachingPolicy = responseCachingPolicy;
         this.cacheEntryGenerator = cacheEntryGenerator;
         this.uriExtractor = uriExtractor;
@@ -330,7 +335,7 @@ public class CachingHttpClient implement
             return callBackend(target, request, context);
         }
 
-        CacheEntry entry = getCacheEntry(target, request);
+        HttpCacheEntry entry = getCacheEntry(target, request);
         if (entry == null) {
             cacheMisses.getAndIncrement();
             if (log.isDebugEnabled()) {
@@ -352,14 +357,14 @@ public class CachingHttpClient implement
             return responseGenerator.generateResponse(entry);
         }
 
-        if (entry.isRevalidatable()) {
+        if (validityPolicy.isRevalidatable(entry)) {
             log.debug("Revalidating the cache entry");
 
             try {
                 return revalidateCacheEntry(target, request, context, entry);
             } catch (IOException ioex) {
-                if (entry.mustRevalidate()
-                    || (isSharedCache() && entry.proxyRevalidate())) {
+                if (validityPolicy.mustRevalidate(entry)
+                    || (isSharedCache() && validityPolicy.proxyRevalidate(entry))) {
                     return new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_GATEWAY_TIMEOUT, "Gateway Timeout");
                 } else {
                     HttpResponse response = responseGenerator.generateResponse(entry);
@@ -386,17 +391,18 @@ public class CachingHttpClient implement
         return new Date();
     }
 
-    CacheEntry getCacheEntry(HttpHost target, HttpRequest request) {
+    HttpCacheEntry getCacheEntry(HttpHost target, HttpRequest request) {
         String uri = uriExtractor.getURI(target, request);
-        CacheEntry entry = null;
+        HttpCacheEntry entry = null;
         try {
             entry = responseCache.getEntry(uri);
         } catch (HttpCacheOperationException ex) {
             log.debug("Was unable to get an entry from the cache based on the uri provided", ex);
         }
 
-        if (entry == null || !entry.hasVariants())
+        if (entry == null || !entry.hasVariants()) {
             return entry;
+        }
 
         String variantUri = uriExtractor.getVariantURI(target, request, entry);
         try {
@@ -445,7 +451,7 @@ public class CachingHttpClient implement
             HttpHost target,
             HttpRequest request,
             HttpContext context,
-            CacheEntry cacheEntry) throws IOException, ProtocolException {
+            HttpCacheEntry cacheEntry) throws IOException, ProtocolException {
         HttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequest(request, cacheEntry);
         Date requestDate = getCurrentDate();
 
@@ -456,7 +462,7 @@ public class CachingHttpClient implement
         int statusCode = backendResponse.getStatusLine().getStatusCode();
         if (statusCode == HttpStatus.SC_NOT_MODIFIED || statusCode == HttpStatus.SC_OK) {
             cacheUpdates.getAndIncrement();
-            CacheEntry updatedEntry = cacheEntryUpdater.updateCacheEntry(cacheEntry, requestDate, responseDate, backendResponse);
+            HttpCacheEntry updatedEntry = cacheEntryUpdater.updateCacheEntry(cacheEntry, requestDate, responseDate, backendResponse);
             storeInCache(target, request, updatedEntry);
             return responseGenerator.generateResponse(updatedEntry);
         }
@@ -465,7 +471,7 @@ public class CachingHttpClient implement
                                      backendResponse);
     }
 
-    void storeInCache(HttpHost target, HttpRequest request, CacheEntry entry) {
+    void storeInCache(HttpHost target, HttpRequest request, HttpCacheEntry entry) {
         if (entry.hasVariants()) {
             storeVariantEntry(target, request, entry);
         } else {
@@ -473,7 +479,7 @@ public class CachingHttpClient implement
         }
     }
 
-    void storeNonVariantEntry(HttpHost target, HttpRequest req, CacheEntry entry) {
+    void storeNonVariantEntry(HttpHost target, HttpRequest req, HttpCacheEntry entry) {
         String uri = uriExtractor.getURI(target, req);
         try {
             responseCache.putEntry(uri, entry);
@@ -485,7 +491,7 @@ public class CachingHttpClient implement
     void storeVariantEntry(
             final HttpHost target,
             final HttpRequest req,
-            final CacheEntry entry) {
+            final HttpCacheEntry entry) {
         final String variantURI = uriExtractor.getVariantURI(target, req, entry);
         try {
             responseCache.putEntry(variantURI, entry);
@@ -493,9 +499,9 @@ public class CachingHttpClient implement
             log.debug("Was unable to PUT a variant entry into the cache based on the uri provided", e);
         }
 
-        HttpCacheUpdateCallback<CacheEntry> callback = new HttpCacheUpdateCallback<CacheEntry>() {
+        HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback() {
 
-            public CacheEntry update(CacheEntry existing) throws HttpCacheOperationException {
+            public HttpCacheEntry update(HttpCacheEntry existing) throws HttpCacheOperationException {
                 return doGetUpdatedParentEntry(existing, entry, variantURI);
             }
 
@@ -508,13 +514,13 @@ public class CachingHttpClient implement
         }
     }
 
-    CacheEntry doGetUpdatedParentEntry(
-            CacheEntry existing,
-            CacheEntry entry, String variantURI) throws HttpCacheOperationException {
+    HttpCacheEntry doGetUpdatedParentEntry(
+            HttpCacheEntry existing,
+            HttpCacheEntry entry, String variantURI) throws HttpCacheOperationException {
         if (existing != null) {
-            return existing.copyWithVariant(variantURI);
+            return HttpCacheEntry.copyWithVariant(existing, variantURI);
         } else {
-            return entry.copyWithVariant(variantURI);
+            return HttpCacheEntry.copyWithVariant(entry, variantURI);
         }
     }
 
@@ -570,7 +576,7 @@ public class CachingHttpClient implement
                                                                responseBytes);
             int correctedStatus = corrected.getStatusLine().getStatusCode();
             if (HttpStatus.SC_BAD_GATEWAY != correctedStatus) {
-                CacheEntry entry = cacheEntryGenerator
+                HttpCacheEntry entry = cacheEntryGenerator
                     .generateEntry(requestDate, responseDate, corrected,
                                    responseBytes);
                 storeInCache(target, request, entry);

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ConditionalRequestBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ConditionalRequestBuilder.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ConditionalRequestBuilder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ConditionalRequestBuilder.java Thu Jul 22 13:16:29 2010
@@ -31,6 +31,8 @@ import org.apache.http.HeaderElement;
 import org.apache.http.HttpRequest;
 import org.apache.http.ProtocolException;
 import org.apache.http.annotation.Immutable;
+import org.apache.http.client.cache.HeaderConstants;
+import org.apache.http.client.cache.HttpCacheEntry;
 import org.apache.http.impl.client.RequestWrapper;
 
 /**
@@ -40,7 +42,7 @@ import org.apache.http.impl.client.Reque
 class ConditionalRequestBuilder {
 
     /**
-     * When a {@link CacheEntry} is stale but 'might' be used as a response
+     * When a {@link HttpCacheEntry} is stale but 'might' be used as a response
      * to an {@link HttpRequest} we will attempt to revalidate the entry with
      * the origin.  Build the origin {@link HttpRequest} here and return it.
      *
@@ -49,7 +51,7 @@ class ConditionalRequestBuilder {
      * @return the wrapped request
      * @throws ProtocolException when I am unable to build a new origin request.
      */
-    public HttpRequest buildConditionalRequest(HttpRequest request, CacheEntry cacheEntry)
+    public HttpRequest buildConditionalRequest(HttpRequest request, HttpCacheEntry cacheEntry)
             throws ProtocolException {
         RequestWrapper wrapperRequest = new RequestWrapper(request);
         wrapperRequest.resetHeaders();

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java Thu Jul 22 13:16:29 2010
@@ -39,6 +39,7 @@ import org.apache.http.HttpVersion;
 import org.apache.http.ProtocolException;
 import org.apache.http.ProtocolVersion;
 import org.apache.http.annotation.Immutable;
+import org.apache.http.client.cache.HeaderConstants;
 import org.apache.http.entity.AbstractHttpEntity;
 import org.apache.http.impl.client.RequestWrapper;
 import org.apache.http.message.BasicHeader;

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseCachingPolicy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseCachingPolicy.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseCachingPolicy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseCachingPolicy.java Thu Jul 22 13:16:29 2010
@@ -36,6 +36,7 @@ import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
 import org.apache.http.annotation.Immutable;
+import org.apache.http.client.cache.HeaderConstants;
 import org.apache.http.impl.cookie.DateParseException;
 import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.protocol.HTTP;

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseProtocolCompliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseProtocolCompliance.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseProtocolCompliance.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseProtocolCompliance.java Thu Jul 22 13:16:29 2010
@@ -36,6 +36,7 @@ import org.apache.http.HttpVersion;
 import org.apache.http.ProtocolVersion;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.cache.HeaderConstants;
 import org.apache.http.impl.client.RequestWrapper;
 import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.protocol.HTTP;

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/URIExtractor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/URIExtractor.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/URIExtractor.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/URIExtractor.java Thu Jul 22 13:16:29 2010
@@ -37,6 +37,8 @@ import org.apache.http.HeaderElement;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.annotation.Immutable;
+import org.apache.http.client.cache.HeaderConstants;
+import org.apache.http.client.cache.HttpCacheEntry;
 import org.apache.http.protocol.HTTP;
 
 /**
@@ -84,7 +86,7 @@ class URIExtractor {
      * @param entry the parent entry used to track the varients
      * @return String the extracted variant URI
      */
-    public String getVariantURI(HttpHost host, HttpRequest req, CacheEntry entry) {
+    public String getVariantURI(HttpHost host, HttpRequest req, HttpCacheEntry entry) {
         Header[] varyHdrs = entry.getHeaders(HeaderConstants.VARY);
         if (varyHdrs == null || varyHdrs.length == 0) {
             return getURI(host, req);

Added: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/CacheEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/CacheEntry.java?rev=966642&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/CacheEntry.java (added)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/CacheEntry.java Thu Jul 22 13:16:29 2010
@@ -0,0 +1,84 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import java.util.Date;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.StatusLine;
+import org.apache.http.client.cache.HttpCacheEntry;
+import org.apache.http.entity.BasicHttpEntity;
+import org.apache.http.entity.ByteArrayEntity;
+
+public class CacheEntry extends HttpCacheEntry {
+
+    private static final long serialVersionUID = 7964121802841871079L;
+
+    public static final long MAX_AGE = CacheValidityPolicy.MAX_AGE;
+
+    public CacheEntry(
+            Date requestDate,
+            Date responseDate,
+            StatusLine statusLine,
+            Header[] responseHeaders,
+            HttpEntity body) {
+        super(requestDate, responseDate, statusLine, responseHeaders, body, null);
+    }
+
+    public CacheEntry(
+            Date requestDate,
+            Date responseDate) {
+        super(requestDate, responseDate, new OKStatus(), new Header[] {}, new BasicHttpEntity(), null);
+    }
+
+    public CacheEntry(
+            Date requestDate,
+            Date responseDate,
+            Header[] headers) {
+        super(requestDate, responseDate, new OKStatus(), headers, new BasicHttpEntity(), null);
+    }
+
+    public CacheEntry(Header[] headers) {
+        super(new Date(), new Date(), new OKStatus(), headers, new BasicHttpEntity(), null);
+    }
+
+    public CacheEntry(
+            Header[] headers,
+            byte[] content) {
+        super(new Date(), new Date(), new OKStatus(), headers, new ByteArrayEntity(content), null);
+    }
+
+    public CacheEntry() {
+        this(new Date(), new Date());
+    }
+
+    public CacheEntry(byte[] content) {
+        super(new Date(), new Date(), new OKStatus(), new Header[] {}, new ByteArrayEntity(content), null);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/CacheEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/CacheEntry.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/CacheEntry.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java?rev=966642&r1=966641&r2=966642&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java Thu Jul 22 13:16:29 2010
@@ -62,13 +62,12 @@ public class DoNotTestProtocolRequiremen
     private HttpHost host;
     private HttpEntity mockEntity;
     private HttpClient mockBackend;
-    private HttpCache<String, CacheEntry> mockCache;
+    private HttpCache mockCache;
     private HttpRequest request;
     private HttpResponse originResponse;
 
     private CachingHttpClient impl;
 
-    @SuppressWarnings("unchecked")
     @Before
     public void setUp() {
         host = new HttpHost("foo.example.com");
@@ -77,7 +76,7 @@ public class DoNotTestProtocolRequiremen
 
         originResponse = make200Response();
 
-        HttpCache<String, CacheEntry> cache = new BasicHttpCache(MAX_ENTRIES);
+        HttpCache cache = new BasicHttpCache(MAX_ENTRIES);
         mockBackend = EasyMock.createMock(HttpClient.class);
         mockEntity = EasyMock.createMock(HttpEntity.class);
         mockCache = EasyMock.createMock(HttpCache.class);

Added: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/OKStatus.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/OKStatus.java?rev=966642&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/OKStatus.java (added)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/OKStatus.java Thu Jul 22 13:16:29 2010
@@ -0,0 +1,39 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
+import org.apache.http.message.BasicStatusLine;
+
+public class OKStatus extends BasicStatusLine {
+
+    public OKStatus() {
+        super(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+    }
+
+}
\ No newline at end of file

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/OKStatus.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/OKStatus.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/OKStatus.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message