hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r941886 [1/2] - in /httpcomponents/httpclient/trunk/httpclient-cache/src: main/java/org/apache/http/client/cache/impl/ test/java/org/apache/http/client/cache/impl/
Date Thu, 06 May 2010 20:02:23 GMT
Author: olegk
Date: Thu May  6 20:02:22 2010
New Revision: 941886

URL: http://svn.apache.org/viewvc?rev=941886&view=rev
Log:
HTTPCLIENT-427: CacheEntry made immutable
Contributed by David Mays <david_mays at comcast.com>

Added:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CachedHeaderGroup.java
Modified:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/BasicHttpCache.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheEntry.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheEntryGenerator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheEntryUpdater.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheInvalidator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheableRequestPolicy.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CachedResponseSuitabilityChecker.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CachingHttpClient.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CombinedInputStream.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/ConditionalRequestBuilder.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/DefaultCacheEntrySerializer.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/HeaderConstants.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/OptionsHttp11Response.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/RequestProtocolCompliance.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/ResponseCachingPolicy.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/ResponseProtocolCompliance.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/SizeLimitedResponseReader.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/DoNotTestProtocolRequirements.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCacheEntry.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCacheEntryGenerator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCacheEntryUpdater.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCacheInvalidator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCacheableRequestPolicy.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCachedHttpResponseGenerator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCachedResponseSuitabilityChecker.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCachingHttpClient.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCombinedInputStream.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestConditionalRequestBuilder.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestDefaultCacheEntrySerializer.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestProtocolDeviations.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestProtocolRequirements.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestResponseCache.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestResponseCachingPolicy.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestSizeLimitedResponseReader.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestURIExtractor.java

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/BasicHttpCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/BasicHttpCache.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/BasicHttpCache.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/BasicHttpCache.java Thu May  6 20:02:22 2010
@@ -31,9 +31,9 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 
 import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.client.cache.HttpCache;
 import org.apache.http.client.cache.HttpCacheOperationException;
 import org.apache.http.client.cache.HttpCacheUpdateCallback;
-import org.apache.http.client.cache.HttpCache;
 
 /**
  * Implements {@link HttpCache} using LinkedHashMap for backing store

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheEntry.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheEntry.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheEntry.java Thu May  6 20:02:22 2010
@@ -30,7 +30,6 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashSet;
@@ -41,7 +40,7 @@ import org.apache.http.HeaderElement;
 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;
@@ -51,56 +50,73 @@ import org.apache.http.message.BasicHead
  *
  * @since 4.1
  */
+@Immutable
 public class CacheEntry implements Serializable {
 
     private static final long serialVersionUID = -6300496422359477413L;
 
     public static final long MAX_AGE = 2147483648L;
 
-    private transient Header[] responseHeaders;
-    private byte[] body;
-    private ProtocolVersion version;
-    private int status;
-    private String reason;
-    private Date requestDate;
-    private Date responseDate;
-    private Set<String> variantURIs = new HashSet<String>();
-
-    /**
-     * Default constructor
-     */
-    public CacheEntry() {
-    }
+    private final Date requestDate;
+    private final Date responseDate;
+    private final ProtocolVersion version;
+    private final int status;
+    private final String reason;
+    private final CachedHeaderGroup responseHeaders = new CachedHeaderGroup();
+    private final byte[] body;
+    private final Set<String> variantURIs = new HashSet<String>();
 
     /**
+     *
      * @param requestDate
-     *            Date/time when the request was made (Used for age
+     *          Date/time when the request was made (Used for age
      *            calculations)
      * @param responseDate
-     *            Date/time that the response came back (Used for age
+     *          Date/time that the response came back (Used for age
      *            calculations)
-     * @param response
-     *            original {@link HttpResponse}
+     * @param version
+     *          HTTP Response Version
+     * @param responseHeaders
+     *          Header[] from original HTTP Response
      * @param responseBytes
-     *            Byte array containing the body of the response
-     * @throws IOException
-     *             Does not attempt to handle IOExceptions
+     *          Byte array containing 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, HttpResponse response,
-            byte[] responseBytes) throws IOException {
+    public CacheEntry(Date requestDate, Date responseDate, ProtocolVersion version, Header[] responseHeaders, byte[] responseBytes, int status, String reason){
+
+        super();
         this.requestDate = requestDate;
         this.responseDate = responseDate;
-        version = response.getProtocolVersion();
-        responseHeaders = response.getAllHeaders();
-        StatusLine sl = response.getStatusLine();
-        status = sl.getStatusCode();
-        reason = sl.getReasonPhrase();
+        this.version = version;
+        this.responseHeaders.setHeaders(responseHeaders);
+        this.status = status;
+        this.reason = reason;
+        this.body = responseBytes;
+    }
 
-        body = responseBytes;
+    /**
+     * Constructor used to create a copy of an existing entry, while adding another variant URI to it.
+     * @param toCopy CacheEntry to be duplicated
+     * @param variantURI URI to add
+     */
+    private CacheEntry(CacheEntry toCopy, String variantURI){
+        this(toCopy.getRequestDate(),
+             toCopy.getResponseDate(),
+             toCopy.getProtocolVersion(),
+             toCopy.getAllHeaders(),
+             toCopy.getBody(),
+             toCopy.getStatusCode(),
+             toCopy.getReasonPhrase());
+
+        this.variantURIs.addAll(toCopy.getVariantURIs());
+        this.variantURIs.add(variantURI);
     }
 
-    public void setProtocolVersion(ProtocolVersion version) {
-        this.version = version;
+    public CacheEntry addVariantURI(String variantURI){
+        return new CacheEntry(this,variantURI);
     }
 
     public ProtocolVersion getProtocolVersion() {
@@ -115,61 +131,28 @@ public class CacheEntry implements Seria
         return this.status;
     }
 
-    public void setRequestDate(Date requestDate) {
-        this.requestDate = requestDate;
-    }
-
     public Date getRequestDate() {
         return requestDate;
     }
 
-    public void setResponseDate(Date responseDate) {
-        this.responseDate = responseDate;
-    }
-
     public Date getResponseDate() {
         return this.responseDate;
     }
 
-    public void setBody(byte[] body) {
-        this.body = body;
-    }
-
     public byte[] getBody() {
         return body;
     }
 
     public Header[] getAllHeaders() {
-        return responseHeaders;
-    }
-
-    public void setResponseHeaders(Header[] responseHeaders) {
-        this.responseHeaders = responseHeaders;
+        return responseHeaders.getAllHeaders();
     }
 
     public Header getFirstHeader(String name) {
-        for (Header h : responseHeaders) {
-            if (h.getName().equals(name))
-                return h;
-        }
-
-        return null;
+        return responseHeaders.getFirstHeader(name);
     }
 
     public Header[] getHeaders(String name) {
-
-        ArrayList<Header> headers = new ArrayList<Header>();
-
-        for (Header h : this.responseHeaders) {
-            if (h.getName().equals(name))
-                headers.add(h);
-        }
-
-        Header[] headerArray = new Header[headers.size()];
-
-        headers.toArray(headerArray);
-
-        return headerArray;
+        return responseHeaders.getHeaders(name);
     }
 
     /**
@@ -377,12 +360,14 @@ public class CacheEntry implements Seria
         out.defaultWriteObject();
 
         // write (non-serializable) responseHeaders
-        if (null == responseHeaders || responseHeaders.length < 1)
+        if (null == responseHeaders || responseHeaders.getAllHeaders().length < 1)
             return;
-        String[][] sheaders = new String[responseHeaders.length][2];
-        for (int i = 0; i < responseHeaders.length; i++) {
-            sheaders[i][0] = responseHeaders[i].getName();
-            sheaders[i][1] = responseHeaders[i].getValue();
+        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);
 
@@ -402,15 +387,12 @@ public class CacheEntry implements Seria
             String[] sheader = sheaders[i];
             headers[i] = new BasicHeader(sheader[0], sheader[1]);
         }
-        this.responseHeaders = headers;
-
-    }
 
-    public void addVariantURI(String URI) {
-        this.variantURIs.add(URI);
+        this.responseHeaders.setHeaders(headers);
     }
 
     public Set<String> getVariantURIs() {
         return Collections.unmodifiableSet(this.variantURIs);
     }
+
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheEntryGenerator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheEntryGenerator.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheEntryGenerator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheEntryGenerator.java Thu May  6 20:02:22 2010
@@ -33,6 +33,8 @@ import org.apache.http.HttpResponse;
 import org.apache.http.annotation.Immutable;
 
 /**
+ * Generates a {@link CacheEntry} from a {@link HttpResponse}
+ *
  * @since 4.1
  */
 @Immutable
@@ -41,7 +43,15 @@ public class CacheEntryGenerator {
     public CacheEntry generateEntry(Date requestDate, Date responseDate, HttpResponse response,
             byte[] responseBytes) throws IOException {
 
-        return new CacheEntry(requestDate, responseDate, response, responseBytes);
+
+
+        return new CacheEntry(requestDate,
+                              responseDate,
+                              response.getProtocolVersion(),
+                              response.getAllHeaders(),
+                              responseBytes,
+                              response.getStatusLine().getStatusCode(),
+                              response.getStatusLine().getReasonPhrase());
 
     }
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheEntryUpdater.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheEntryUpdater.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheEntryUpdater.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheEntryUpdater.java Thu May  6 20:02:22 2010
@@ -39,19 +39,39 @@ import org.apache.http.impl.cookie.DateP
 import org.apache.http.impl.cookie.DateUtils;
 
 /**
+ * Update a {@link CacheEntry} 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.
+ *
  * @since 4.1
  */
 @Immutable
 public class CacheEntryUpdater {
 
-    public void updateCacheEntry(CacheEntry entry, Date requestDate, Date responseDate,
-            HttpResponse response) {
-        entry.setRequestDate(requestDate);
-        entry.setResponseDate(responseDate);
-        mergeHeaders(entry, response);
+    /**
+     * Update the entry with the new information from the response.
+     *
+     * @param entry The cache Entry to be updated
+     * @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
+     */
+    public CacheEntry updateCacheEntry(CacheEntry entry, Date requestDate, Date responseDate, HttpResponse response) {
+
+        Header[] mergedHeaders = mergeHeaders(entry, response);
+
+        CacheEntry updated = new CacheEntry(requestDate, responseDate,
+                                            entry.getProtocolVersion(),
+                                            mergedHeaders,
+                                            entry.getBody(),
+                                            entry.getStatusCode(),
+                                            entry.getReasonPhrase());
+
+        return updated;
     }
 
-    protected void mergeHeaders(CacheEntry entry, HttpResponse response) {
+    protected Header[] mergeHeaders(CacheEntry entry, HttpResponse response) {
         List<Header> cacheEntryHeaderList = new ArrayList<Header>(Arrays.asList(entry
                 .getAllHeaders()));
 
@@ -60,7 +80,7 @@ public class CacheEntryUpdater {
             // Don't merge Headers, keep the entries headers as they are newer.
             removeCacheEntry1xxWarnings(cacheEntryHeaderList, entry);
 
-            return;
+            return cacheEntryHeaderList.toArray(new Header[cacheEntryHeaderList.size()]);
         }
 
         removeCacheHeadersThatMatchResponse(cacheEntryHeaderList, response);
@@ -68,8 +88,7 @@ public class CacheEntryUpdater {
         cacheEntryHeaderList.addAll(Arrays.asList(response.getAllHeaders()));
         removeCacheEntry1xxWarnings(cacheEntryHeaderList, entry);
 
-        entry.setResponseHeaders(cacheEntryHeaderList.toArray(new Header[cacheEntryHeaderList
-                .size()]));
+        return cacheEntryHeaderList.toArray(new Header[cacheEntryHeaderList.size()]);
     }
 
     private void removeCacheHeadersThatMatchResponse(List<Header> cacheEntryHeaderList,

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheInvalidator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheInvalidator.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheInvalidator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheInvalidator.java Thu May  6 20:02:22 2010
@@ -33,8 +33,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.HttpCacheOperationException;
 import org.apache.http.client.cache.HttpCache;
+import org.apache.http.client.cache.HttpCacheOperationException;
 
 /**
  * Given a particular HttpRequest, flush any cache entries that this request
@@ -48,19 +48,30 @@ public class CacheInvalidator {
     private final HttpCache<CacheEntry> cache;
     private final URIExtractor uriExtractor;
 
-    private static final Log LOG = LogFactory.getLog(CacheInvalidator.class);
+    private final Log LOG = LogFactory.getLog(CacheInvalidator.class);
 
+    /**
+     *
+     * @param uriExtractor
+     * @param cache
+     */
     public CacheInvalidator(URIExtractor uriExtractor, HttpCache<CacheEntry> cache) {
         this.uriExtractor = uriExtractor;
         this.cache = cache;
     }
 
+    /**
+     * Remove cache entries from the cache that are no longer fresh or
+     * have been invalidated in some way.
+     *
+     * @param host The backend host we are talking to
+     * @param req The HttpRequest to that host
+     */
     public void flushInvalidatedCacheEntries(HttpHost host, HttpRequest req) {
         LOG.debug("CacheInvalidator: flushInvalidatedCacheEntries, BEGIN");
 
         if (requestShouldNotBeCached(req)) {
-            LOG
-                    .debug("CacheInvalidator: flushInvalidatedCacheEntries, Request should not be cached");
+            LOG.debug("CacheInvalidator: flushInvalidatedCacheEntries, Request should not be cached");
 
             try {
                 String theUri = uriExtractor.getURI(host, req);
@@ -76,6 +87,7 @@ public class CacheInvalidator {
                     cache.removeEntry(theUri);
                 }
             } catch (HttpCacheOperationException coe) {
+                LOG.warn("Cache: Was unable to REMOVE an entry from the cache based on the uri provided.", coe);
                 // TODO: track failed state
             }
         }
@@ -124,4 +136,4 @@ public class CacheInvalidator {
 
         return false;
     }
-}
\ No newline at end of file
+}

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheableRequestPolicy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheableRequestPolicy.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheableRequestPolicy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CacheableRequestPolicy.java Thu May  6 20:02:22 2010
@@ -42,7 +42,7 @@ import org.apache.http.annotation.Immuta
 @Immutable
 public class CacheableRequestPolicy {
 
-    private static final Log LOG = LogFactory.getLog(CacheableRequestPolicy.class);
+    private final Log LOG = LogFactory.getLog(CacheableRequestPolicy.class);
 
     /**
      * Determines if an HttpRequest can be served from the cache.

Added: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CachedHeaderGroup.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CachedHeaderGroup.java?rev=941886&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CachedHeaderGroup.java (added)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CachedHeaderGroup.java Thu May  6 20:02:22 2010
@@ -0,0 +1,11 @@
+package org.apache.http.client.cache.impl;
+
+import java.io.Serializable;
+
+import org.apache.http.message.HeaderGroup;
+
+/**
+ */
+public class CachedHeaderGroup extends HeaderGroup implements Serializable {
+    private static final long serialVersionUID = -4572663568087431896L;
+}

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CachedResponseSuitabilityChecker.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CachedResponseSuitabilityChecker.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CachedResponseSuitabilityChecker.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CachedResponseSuitabilityChecker.java Thu May  6 20:02:22 2010
@@ -35,14 +35,15 @@ import org.apache.http.HttpRequest;
 import org.apache.http.annotation.Immutable;
 
 /**
- * Determines whether a given response can be cached.
+ * Determines whether a given {@link CacheEntry} is suitable to be
+ * used as a response for a given {@link HttpRequest}.
  *
  * @since 4.1
  */
 @Immutable
 public class CachedResponseSuitabilityChecker {
 
-    private static final Log LOG = LogFactory.getLog(CachedResponseSuitabilityChecker.class);
+    private final Log LOG = LogFactory.getLog(CachedResponseSuitabilityChecker.class);
 
     /**
      * @param host
@@ -60,28 +61,24 @@ public class CachedResponseSuitabilityCh
         }
 
         if (!entry.contentLengthHeaderMatchesActualLength()) {
-            LOG
-                    .debug("CachedResponseSuitabilityChecker: Cache Entry Content Length and header information DO NOT match.");
+            LOG.debug("CachedResponseSuitabilityChecker: Cache Entry Content Length and header information DO NOT match.");
             return false;
         }
 
         if (entry.modifiedSince(request)) {
-            LOG
-                    .debug("CachedResponseSuitabilityChecker: Cache Entry modified times didn't line up.  Cache Entry should NOT be used.");
+            LOG.debug("CachedResponseSuitabilityChecker: Cache Entry modified times didn't line up.  Cache Entry should NOT be used.");
             return false;
         }
 
         for (Header ccHdr : request.getHeaders(HeaderConstants.CACHE_CONTROL)) {
             for (HeaderElement elt : ccHdr.getElements()) {
                 if (HeaderConstants.CACHE_CONTROL_NO_CACHE.equals(elt.getName())) {
-                    LOG
-                            .debug("CachedResponseSuitabilityChecker: Response contained NO CACHE directive, cache was NOT suitable.");
+                    LOG.debug("CachedResponseSuitabilityChecker: Response contained NO CACHE directive, cache was NOT suitable.");
                     return false;
                 }
 
                 if (HeaderConstants.CACHE_CONTROL_NO_STORE.equals(elt.getName())) {
-                    LOG
-                            .debug("CachedResponseSuitabilityChecker: Response contained NO SORE directive, cache was NOT suitable.");
+                    LOG.debug("CachedResponseSuitabilityChecker: Response contained NO SORE directive, cache was NOT suitable.");
                     return false;
                 }
 
@@ -89,14 +86,12 @@ public class CachedResponseSuitabilityCh
                     try {
                         int maxage = Integer.parseInt(elt.getValue());
                         if (entry.getCurrentAgeSecs() > maxage) {
-                            LOG
-                                    .debug("CachedResponseSuitabilityChecker: Response from cache was NOT suitable.");
+                            LOG.debug("CachedResponseSuitabilityChecker: Response from cache was NOT suitable due to max age.");
                             return false;
                         }
                     } catch (NumberFormatException nfe) {
                         // err conservatively
-                        LOG
-                                .debug("CachedResponseSuitabilityChecker: Response from cache was NOT suitable.");
+                        LOG.debug("CachedResponseSuitabilityChecker: Response from cache was NOT suitable. "+nfe);
                         return false;
                     }
                 }
@@ -105,14 +100,12 @@ public class CachedResponseSuitabilityCh
                     try {
                         int maxstale = Integer.parseInt(elt.getValue());
                         if (entry.getFreshnessLifetimeSecs() > maxstale) {
-                            LOG
-                                    .debug("CachedResponseSuitabilityChecker: Response from cache was NOT suitable.");
+                            LOG.debug("CachedResponseSuitabilityChecker: Response from cache was NOT suitable due to Max stale freshness");
                             return false;
                         }
                     } catch (NumberFormatException nfe) {
                         // err conservatively
-                        LOG
-                                .debug("CachedResponseSuitabilityChecker: Response from cache was NOT suitable.");
+                        LOG.debug("CachedResponseSuitabilityChecker: Response from cache was NOT suitable. "+nfe);
                         return false;
                     }
                 }
@@ -121,14 +114,12 @@ public class CachedResponseSuitabilityCh
                     try {
                         int minfresh = Integer.parseInt(elt.getValue());
                         if (entry.getFreshnessLifetimeSecs() < minfresh) {
-                            LOG
-                                    .debug("CachedResponseSuitabilityChecker: Response from cache was NOT suitable.");
+                            LOG.debug("CachedResponseSuitabilityChecker: Response from cache was NOT suitable due to min fresh freshness requirement");
                             return false;
                         }
                     } catch (NumberFormatException nfe) {
                         // err conservatively
-                        LOG
-                                .debug("CachedResponseSuitabilityChecker: Response from cache was NOT suitable.");
+                        LOG.debug("CachedResponseSuitabilityChecker: Response from cache was NOT suitable. " + nfe);
                         return false;
                     }
                 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CachingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CachingHttpClient.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CachingHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CachingHttpClient.java Thu May  6 20:02:22 2010
@@ -30,6 +30,7 @@ import java.io.IOException;
 import java.net.URI;
 import java.util.Date;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -44,9 +45,9 @@ import org.apache.http.StatusLine;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.cache.HttpCache;
 import org.apache.http.client.cache.HttpCacheOperationException;
 import org.apache.http.client.cache.HttpCacheUpdateCallback;
-import org.apache.http.client.cache.HttpCache;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.impl.client.DefaultHttpClient;
@@ -60,7 +61,6 @@ import org.apache.http.protocol.HttpCont
  */
 public class CachingHttpClient implements HttpClient {
 
-    private static final Log LOG = LogFactory.getLog(CachingHttpClient.class);
     private final static int MAX_CACHE_ENTRIES = 1000;
     private final static int DEFAULT_MAX_OBJECT_SIZE_BYTES = 8192;
 
@@ -82,12 +82,15 @@ public class CachingHttpClient implement
     private final int maxObjectSizeBytes;
     private final CacheEntryUpdater cacheEntryUpdater;
 
-    private volatile long cacheHits;
-    private volatile long cacheMisses;
-    private volatile long cacheUpdates;
+    private volatile AtomicLong cacheHits = new AtomicLong();
+    private volatile AtomicLong cacheMisses = new AtomicLong();
+    private volatile AtomicLong cacheUpdates = new AtomicLong();
+
     private final ResponseProtocolCompliance responseCompliance;
     private final RequestProtocolCompliance requestCompliance;
 
+    private final Log LOG = LogFactory.getLog(CachingHttpClient.class);
+
     public CachingHttpClient() {
         this.backend = new DefaultHttpClient();
         this.maxObjectSizeBytes = DEFAULT_MAX_OBJECT_SIZE_BYTES;
@@ -142,13 +145,13 @@ public class CachingHttpClient implement
     }
 
     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) {
+                             CacheEntryGenerator cacheEntryGenerator, URIExtractor uriExtractor,
+                             HttpCache<CacheEntry> responseCache, CachedHttpResponseGenerator responseGenerator,
+                             CacheInvalidator cacheInvalidator, CacheableRequestPolicy cacheableRequestPolicy,
+                             CachedResponseSuitabilityChecker suitabilityChecker,
+                             ConditionalRequestBuilder conditionalRequestBuilder, CacheEntryUpdater entryUpdater,
+                             ResponseProtocolCompliance responseCompliance,
+                             RequestProtocolCompliance requestCompliance) {
         this.maxObjectSizeBytes = DEFAULT_MAX_OBJECT_SIZE_BYTES;
         this.backend = backend;
         this.responseCachingPolicy = responseCachingPolicy;
@@ -165,60 +168,153 @@ public class CachingHttpClient implement
         this.requestCompliance = requestCompliance;
     }
 
+    /**
+     * Return the number of times that the cache successfully answered an HttpRequest
+     * for a document of information from the server.
+     *
+     * @return long the number of cache successes
+     */
     public long getCacheHits() {
-        return cacheHits;
+        return cacheHits.get();
     }
 
+    /**
+     * Return the number of times that the cache was unable to answer an HttpRequest
+     * for a document of information from the server.
+     *
+     * @return long the number of cache failures/misses
+     */
     public long getCacheMisses() {
-        return cacheMisses;
+        return cacheMisses.get();
     }
 
+    /**
+     * Return the number of times that the cache was able to revalidate
+     * an existing cache entry for a document of information from the server.
+     *
+     * @return long the number of cache revalidations
+     */
     public long getCacheUpdates() {
-        return cacheUpdates;
+        return cacheUpdates.get();
     }
 
+    /**
+     * Execute an {@link HttpRequest} @ a given {@link HttpHost}
+     *
+     * @param target  the target host for the request.
+     *                Implementations may accept <code>null</code>
+     *                if they can still determine a route, for example
+     *                to a default target or by inspecting the request.
+     * @param request the request to execute
+     * @return HttpResponse The cached entry or the result of a backend call
+     * @throws IOException
+     */
     public HttpResponse execute(HttpHost target, HttpRequest request) throws IOException {
         HttpContext defaultContext = null;
         return execute(target, request, defaultContext);
     }
 
+    /**
+     * Execute an {@link HttpRequest} @ a given {@link HttpHost} with a specified
+     * {@link ResponseHandler} that will deal with the result of the call.
+     *
+     * @param target          the target host for the request.
+     *                        Implementations may accept <code>null</code>
+     *                        if they can still determine a route, for example
+     *                        to a default target or by inspecting the request.
+     * @param request         the request to execute
+     * @param responseHandler the response handler
+     * @param <T>             The Return Type Identified by the generic type of the {@link ResponseHandler}
+     * @return T The response type as handled by ResponseHandler
+     * @throws IOException
+     */
     public <T> T execute(HttpHost target, HttpRequest request,
-            ResponseHandler<? extends T> responseHandler) throws IOException {
+                         ResponseHandler<? extends T> responseHandler) throws IOException {
         return execute(target, request, responseHandler, null);
     }
 
+    /**
+     * Execute an {@link HttpRequest} @ a given {@link HttpHost} with a specified
+     * {@link ResponseHandler} that will deal with the result of the call using
+     * a specific {@link HttpContext}
+     *
+     * @param target          the target host for the request.
+     *                        Implementations may accept <code>null</code>
+     *                        if they can still determine a route, for example
+     *                        to a default target or by inspecting the request.
+     * @param request         the request to execute
+     * @param responseHandler the response handler
+     * @param context         the context to use for the execution, or
+     *                        <code>null</code> to use the default context
+     * @param <T>             The Return Type Identified by the generic type of the {@link ResponseHandler}
+     * @return T The response type as handled by ResponseHandler
+     * @throws IOException
+     */
     public <T> T execute(HttpHost target, HttpRequest request,
-            ResponseHandler<? extends T> responseHandler, HttpContext context) throws IOException {
+                         ResponseHandler<? extends T> responseHandler, HttpContext context) throws IOException {
         HttpResponse resp = execute(target, request, context);
         return responseHandler.handleResponse(resp);
     }
 
+    /**
+     * @param request the request to execute
+     * @return HttpResponse The cached entry or the result of a backend call
+     * @throws IOException
+     */
     public HttpResponse execute(HttpUriRequest request) throws IOException {
         HttpContext context = null;
         return execute(request, context);
     }
 
+    /**
+     * @param request the request to execute
+     * @param context the context to use for the execution, or
+     *                <code>null</code> to use the default context
+     * @return HttpResponse The cached entry or the result of a backend call
+     * @throws IOException
+     */
     public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException {
         URI uri = request.getURI();
         HttpHost httpHost = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
         return execute(httpHost, request, context);
     }
 
+    /**
+     * @param request         the request to execute
+     * @param responseHandler the response handler
+     * @param <T>             The Return Type Identified by the generic type of the {@link ResponseHandler}
+     * @return T The response type as handled by ResponseHandler
+     * @throws IOException
+     */
     public <T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler)
             throws IOException {
         return execute(request, responseHandler, null);
     }
 
+    /**
+     * @param request         the request to execute
+     * @param responseHandler the response handler
+     * @param context
+     * @param <T>             The Return Type Identified by the generic type of the {@link ResponseHandler}
+     * @return T The response type as handled by ResponseHandler
+     * @throws IOException
+     */
     public <T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler,
-            HttpContext context) throws IOException {
+                         HttpContext context) throws IOException {
         HttpResponse resp = execute(request, context);
         return responseHandler.handleResponse(resp);
     }
 
+    /**
+     * @return
+     */
     public ClientConnectionManager getConnectionManager() {
         return backend.getConnectionManager();
     }
 
+    /**
+     * @return
+     */
     public HttpParams getParams() {
         return backend.getParams();
     }
@@ -233,7 +329,7 @@ public class CachingHttpClient implement
         try {
             entry = responseCache.getEntry(uri);
         } catch (HttpCacheOperationException probablyIgnore) {
-            // TODO: do something useful with this exception
+            LOG.warn("Cache: Was unable to get an entry from the cache based on the uri provided.", probablyIgnore);
         }
 
         if (entry == null || !entry.hasVariants())
@@ -247,6 +343,17 @@ public class CachingHttpClient implement
         }
     }
 
+    /**
+     * @param target  the target host for the request.
+     *                Implementations may accept <code>null</code>
+     *                if they can still determine a route, for example
+     *                to a default target or by inspecting the request.
+     * @param request the request to execute
+     * @param context the context to use for the execution, or
+     *                <code>null</code> to use the default context
+     * @return
+     * @throws IOException
+     */
     public HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context)
             throws IOException {
 
@@ -254,8 +361,7 @@ public class CachingHttpClient implement
             return new OptionsHttp11Response();
         }
 
-        List<RequestProtocolError> fatalError = requestCompliance
-                .requestIsFatallyNonCompliant(request);
+        List<RequestProtocolError> fatalError = requestCompliance.requestIsFatallyNonCompliant(request);
 
         for (RequestProtocolError error : fatalError) {
             return requestCompliance.getErrorForRequest(error);
@@ -275,13 +381,13 @@ public class CachingHttpClient implement
 
         CacheEntry entry = getCacheEntry(target, request);
         if (entry == null) {
-            cacheMisses++;
+            cacheMisses.getAndIncrement();
             LOG.debug("CLIENT: Cache Miss.");
             return callBackend(target, request, context);
         }
 
         LOG.debug("CLIENT: Cache HIT.");
-        cacheHits++;
+        cacheHits.getAndIncrement();
 
         if (suitabilityChecker.canCachedResponseBeUsed(target, request, entry)) {
             return responseGenerator.generateResponse(entry);
@@ -294,8 +400,8 @@ public class CachingHttpClient implement
                 return revalidateCacheEntry(target, request, context, entry);
             } catch (IOException ioex) {
                 HttpResponse response = responseGenerator.generateResponse(entry);
-                response.addHeader(HeaderConstants.WARNING, "111 Revalidation Failed - "
-                        + ioex.getMessage());
+                response.addHeader(HeaderConstants.WARNING, "111 Revalidation Failed - " + ioex.getMessage());
+                LOG.debug("111 revalidation failed due to exception: " + ioex);
                 return response;
             } catch (ProtocolException e) {
                 throw new ClientProtocolException(e);
@@ -328,7 +434,7 @@ public class CachingHttpClient implement
             LOG.debug("CLIENT: Calling the backend.");
             HttpResponse backendResponse = backend.execute(target, request, context);
             return handleBackendResponse(target, request, requestDate, getCurrentDate(),
-                    backendResponse);
+                                         backendResponse);
         } catch (ClientProtocolException cpex) {
             throw cpex;
         } catch (IOException ex) {
@@ -340,9 +446,8 @@ public class CachingHttpClient implement
     }
 
     protected HttpResponse revalidateCacheEntry(HttpHost target, HttpRequest request,
-            HttpContext context, CacheEntry cacheEntry) throws IOException, ProtocolException {
-        HttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequest(request,
-                cacheEntry);
+                                                HttpContext context, CacheEntry cacheEntry) throws IOException, ProtocolException {
+        HttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequest(request, cacheEntry);
         Date requestDate = getCurrentDate();
 
         HttpResponse backendResponse = backend.execute(target, conditionalRequest, context);
@@ -351,15 +456,14 @@ public class CachingHttpClient implement
 
         int statusCode = backendResponse.getStatusLine().getStatusCode();
         if (statusCode == HttpStatus.SC_NOT_MODIFIED || statusCode == HttpStatus.SC_OK) {
-            cacheUpdates++;
-            cacheEntryUpdater.updateCacheEntry(cacheEntry, requestDate, responseDate,
-                    backendResponse);
-            storeInCache(target, request, cacheEntry);
-            return responseGenerator.generateResponse(cacheEntry);
+            cacheUpdates.getAndIncrement();
+            CacheEntry updatedEntry = cacheEntryUpdater.updateCacheEntry(cacheEntry, requestDate, responseDate, backendResponse);
+            storeInCache(target, request, updatedEntry);
+            return responseGenerator.generateResponse(updatedEntry);
         }
 
         return handleBackendResponse(target, conditionalRequest, requestDate, responseDate,
-                backendResponse);
+                                     backendResponse);
     }
 
     protected void storeInCache(HttpHost target, HttpRequest request, CacheEntry entry) {
@@ -369,7 +473,7 @@ public class CachingHttpClient implement
                 HttpCacheUpdateCallback<CacheEntry> callback = storeVariantEntry(target, request, entry);
                 responseCache.updateCacheEntry(uri, callback);
             } catch (HttpCacheOperationException probablyIgnore) {
-                // TODO: do something useful with this exception
+                LOG.warn("Cache: Was unable to PUT/UPDATE an entry into the cache based on the uri provided.", probablyIgnore);
             }
         } else {
             storeNonVariantEntry(target, request, entry);
@@ -381,31 +485,35 @@ public class CachingHttpClient implement
         try {
             responseCache.putEntry(uri, entry);
         } catch (HttpCacheOperationException probablyIgnore) {
-            // TODO: do something useful with this exception
+            LOG.warn("Cache: Was unable to PUT an entry into the cache based on the uri provided.", probablyIgnore);
         }
     }
 
     protected HttpCacheUpdateCallback<CacheEntry> storeVariantEntry(final HttpHost target, final HttpRequest req,
-            final CacheEntry entry) {
+                                                                    final CacheEntry entry) {
+
         return new HttpCacheUpdateCallback<CacheEntry>() {
             public CacheEntry getUpdatedEntry(CacheEntry existing) throws HttpCacheOperationException {
 
-                String variantURI = uriExtractor.getVariantURI(target, req, entry);
-                responseCache.putEntry(variantURI, entry);
-
-                if (existing != null) {
-                    existing.addVariantURI(variantURI);
-                    return existing;
-                } else {
-                    entry.addVariantURI(variantURI);
-                    return entry;
-                }
+                return doGetUpdatedParentEntry(existing, target, req, entry);
             }
         };
     }
 
+    protected CacheEntry doGetUpdatedParentEntry(CacheEntry existing, HttpHost target, HttpRequest req, CacheEntry entry) throws HttpCacheOperationException {
+
+        String variantURI = uriExtractor.getVariantURI(target, req, entry);
+        responseCache.putEntry(variantURI, entry);
+
+        if (existing != null) {
+            return existing.addVariantURI(variantURI);
+        } else {
+            return entry.addVariantURI(variantURI);
+        }
+    }
+
     protected HttpResponse handleBackendResponse(HttpHost target, HttpRequest request,
-            Date requestDate, Date responseDate, HttpResponse backendResponse) throws IOException {
+                                                 Date requestDate, Date responseDate, HttpResponse backendResponse) throws IOException {
 
         LOG.debug("CLIENT: Handling Backend response.");
         responseCompliance.ensureProtocolCompliance(request, backendResponse);
@@ -421,7 +529,7 @@ public class CachingHttpClient implement
             }
 
             CacheEntry entry = cacheEntryGenerator.generateEntry(requestDate, responseDate,
-                    backendResponse, responseReader.getResponseBytes());
+                                                                 backendResponse, responseReader.getResponseBytes());
             storeInCache(target, request, entry);
             return responseGenerator.generateResponse(entry);
         }
@@ -430,6 +538,7 @@ public class CachingHttpClient implement
         try {
             responseCache.removeEntry(uri);
         } catch (HttpCacheOperationException coe) {
+            LOG.warn("Cache: Was unable to remove an entry from the cache based on the uri provided.", coe);
             // TODO: track failed state
         }
         return backendResponse;

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CombinedInputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CombinedInputStream.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CombinedInputStream.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/CombinedInputStream.java Thu May  6 20:02:22 2010
@@ -40,6 +40,8 @@ class CombinedInputStream extends InputS
     private final InputStream inputStream2;
 
     /**
+     * Take two inputstreams and produce an object that makes them appear as if they
+     * are actually a 'single' input stream.
      *
      * @param inputStream1
      *            First stream to read

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/ConditionalRequestBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/ConditionalRequestBuilder.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/ConditionalRequestBuilder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/ConditionalRequestBuilder.java Thu May  6 20:02:22 2010
@@ -38,16 +38,23 @@ import org.apache.http.impl.client.Reque
 @Immutable
 public class ConditionalRequestBuilder {
 
+    /**
+     *
+     * @param request
+     * @param cacheEntry
+     * @return
+     * @throws ProtocolException
+     */
     public HttpRequest buildConditionalRequest(HttpRequest request, CacheEntry cacheEntry)
             throws ProtocolException {
         RequestWrapper wrapperRequest = new RequestWrapper(request);
         wrapperRequest.resetHeaders();
         Header eTag = cacheEntry.getFirstHeader(HeaderConstants.ETAG);
         if (eTag != null) {
-            wrapperRequest.setHeader("If-None-Match", eTag.getValue());
+            wrapperRequest.setHeader(HeaderConstants.IF_NONE_MATCH, eTag.getValue());
         } else {
             Header lastModified = cacheEntry.getFirstHeader(HeaderConstants.LAST_MODIFIED);
-            wrapperRequest.setHeader("If-Modified-Since", lastModified.getValue());
+            wrapperRequest.setHeader(HeaderConstants.IF_MODIFIED_SINCE, lastModified.getValue());
         }
         return wrapperRequest;
 

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/DefaultCacheEntrySerializer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/DefaultCacheEntrySerializer.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/DefaultCacheEntrySerializer.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/DefaultCacheEntrySerializer.java Thu May  6 20:02:22 2010
@@ -46,6 +46,12 @@ import org.apache.http.client.cache.Http
 @Immutable
 public class DefaultCacheEntrySerializer implements HttpCacheEntrySerializer<CacheEntry> {
 
+    /**
+     *
+     * @param cacheEntry
+     * @param os
+     * @throws IOException
+     */
     public void writeTo(CacheEntry cacheEntry, OutputStream os) throws IOException {
 
         ObjectOutputStream oos = null;
@@ -77,6 +83,12 @@ public class DefaultCacheEntrySerializer
 
     }
 
+    /**
+     *
+     * @param is
+     * @return
+     * @throws IOException
+     */
     public CacheEntry readFrom(InputStream is) throws IOException {
 
         ObjectInputStream ois = null;
@@ -112,4 +124,4 @@ public class DefaultCacheEntrySerializer
 
     }
 
-}
\ No newline at end of file
+}

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/HeaderConstants.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/HeaderConstants.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/HeaderConstants.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/HeaderConstants.java Thu May  6 20:02:22 2010
@@ -42,6 +42,8 @@ public class HeaderConstants {
     public static final String TRACE_METHOD = "TRACE";
 
     public static final String LAST_MODIFIED = "Last-Modified";
+    public static final String IF_MATCH = "If-Match";
+    public static final String IF_RANGE = "If-Range";
     public static final String IF_UNMODIFIED_SINCE = "If-Unmodified-Since";
     public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
     public static final String IF_NONE_MATCH = "If-None-Match";

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/OptionsHttp11Response.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/OptionsHttp11Response.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/OptionsHttp11Response.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/OptionsHttp11Response.java Thu May  6 20:02:22 2010
@@ -35,6 +35,7 @@ import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.ProtocolVersion;
 import org.apache.http.StatusLine;
+import org.apache.http.annotation.Immutable;
 import org.apache.http.message.AbstractHttpMessage;
 import org.apache.http.message.BasicStatusLine;
 import org.apache.http.params.BasicHttpParams;
@@ -43,11 +44,12 @@ import org.apache.http.params.HttpParams
 /**
  * @since 4.1
  */
+@Immutable
 public final class OptionsHttp11Response extends AbstractHttpMessage implements HttpResponse {
 
-    StatusLine statusLine = new BasicStatusLine(CachingHttpClient.HTTP_1_1,
+    private final StatusLine statusLine = new BasicStatusLine(CachingHttpClient.HTTP_1_1,
             HttpStatus.SC_NOT_IMPLEMENTED, "");
-    ProtocolVersion version = CachingHttpClient.HTTP_1_1;
+    private final ProtocolVersion version = CachingHttpClient.HTTP_1_1;
 
     public StatusLine getStatusLine() {
         return statusLine;

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/RequestProtocolCompliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/RequestProtocolCompliance.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/RequestProtocolCompliance.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/RequestProtocolCompliance.java Thu May  6 20:02:22 2010
@@ -50,6 +50,11 @@ import org.apache.http.message.BasicStat
 @Immutable
 public class RequestProtocolCompliance {
 
+    /**
+     *
+     * @param request
+     * @return
+     */
     public List<RequestProtocolError> requestIsFatallyNonCompliant(HttpRequest request) {
         List<RequestProtocolError> theErrors = new ArrayList<RequestProtocolError>();
 
@@ -71,6 +76,12 @@ public class RequestProtocolCompliance {
         return theErrors;
     }
 
+    /**
+     *
+     * @param request
+     * @return
+     * @throws ProtocolException
+     */
     public HttpRequest makeRequestCompliant(HttpRequest request) throws ProtocolException {
         if (requestMustNotHaveEntity(request)) {
             ((HttpEntityEnclosingRequest) request).setEntity(null);
@@ -250,11 +261,11 @@ public class RequestProtocolCompliance {
             return null;
         }
 
-        Header range = request.getFirstHeader("Range");
+        Header range = request.getFirstHeader(HeaderConstants.RANGE);
         if (range == null)
             return null;
 
-        Header ifRange = request.getFirstHeader("If-Range");
+        Header ifRange = request.getFirstHeader(HeaderConstants.IF_RANGE);
         if (ifRange == null)
             return null;
 
@@ -267,8 +278,7 @@ public class RequestProtocolCompliance {
     }
 
     private RequestProtocolError requestHasWeekETagForPUTOrDELETEIfMatch(HttpRequest request) {
-        // TODO: Should these be looking at all the headers marked as
-        // If-Match/If-None-Match?
+        // TODO: Should these be looking at all the headers marked as If-Match/If-None-Match?
 
         String method = request.getRequestLine().getMethod();
         if (!(HeaderConstants.PUT_METHOD.equals(method) || HeaderConstants.DELETE_METHOD
@@ -276,14 +286,14 @@ public class RequestProtocolCompliance {
             return null;
         }
 
-        Header ifMatch = request.getFirstHeader("If-Match");
+        Header ifMatch = request.getFirstHeader(HeaderConstants.IF_MATCH);
         if (ifMatch != null) {
             String val = ifMatch.getValue();
             if (val.startsWith("W/")) {
                 return RequestProtocolError.WEAK_ETAG_ON_PUTDELETE_METHOD_ERROR;
             }
         } else {
-            Header ifNoneMatch = request.getFirstHeader("If-None-Match");
+            Header ifNoneMatch = request.getFirstHeader(HeaderConstants.IF_NONE_MATCH);
             if (ifNoneMatch == null)
                 return null;
 

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/ResponseCachingPolicy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/ResponseCachingPolicy.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/ResponseCachingPolicy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/ResponseCachingPolicy.java Thu May  6 20:02:22 2010
@@ -46,8 +46,12 @@ import org.apache.http.impl.cookie.DateU
 public class ResponseCachingPolicy {
 
     private final int maxObjectSizeBytes;
-    private static final Log LOG = LogFactory.getLog(ResponseCachingPolicy.class);
+    private final Log LOG = LogFactory.getLog(ResponseCachingPolicy.class);
 
+    /**
+     *
+     * @param maxObjectSizeBytes
+     */
     public ResponseCachingPolicy(int maxObjectSizeBytes) {
         this.maxObjectSizeBytes = maxObjectSizeBytes;
     }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/ResponseProtocolCompliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/ResponseProtocolCompliance.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/ResponseProtocolCompliance.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/ResponseProtocolCompliance.java Thu May  6 20:02:22 2010
@@ -44,6 +44,12 @@ import org.apache.http.impl.cookie.DateU
 @Immutable
 public class ResponseProtocolCompliance {
 
+    /**
+     *
+     * @param request
+     * @param response
+     * @throws ClientProtocolException
+     */
     public void ensureProtocolCompliance(HttpRequest request, HttpResponse response)
             throws ClientProtocolException {
         if (backendResponseMustNotHaveBody(request, response)) {

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/SizeLimitedResponseReader.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/SizeLimitedResponseReader.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/SizeLimitedResponseReader.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/impl/SizeLimitedResponseReader.java Thu May  6 20:02:22 2010
@@ -52,12 +52,17 @@ public class SizeLimitedResponseReader {
     private byte[] sizeLimitedContent;
     private boolean outputStreamConsumed;
 
+    /**
+     *
+     * @param maxResponseSizeBytes
+     * @param response
+     */
     public SizeLimitedResponseReader(int maxResponseSizeBytes, HttpResponse response) {
         this.maxResponseSizeBytes = maxResponseSizeBytes;
         this.response = response;
     }
 
-    public boolean isResponseTooLarge() throws IOException {
+    protected boolean isResponseTooLarge() throws IOException {
         if (!responseIsConsumed)
             isTooLarge = consumeResponse();
 
@@ -108,14 +113,14 @@ public class SizeLimitedResponseReader {
         outputStreamConsumed = true;
     }
 
-    public byte[] getResponseBytes() {
+    protected byte[] getResponseBytes() {
         if (!outputStreamConsumed)
             consumeOutputStream();
 
         return sizeLimitedContent;
     }
 
-    public HttpResponse getReconstructedResponse() {
+    protected HttpResponse getReconstructedResponse() {
 
         InputStream combinedStream = getCombinedInputStream();
 

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/DoNotTestProtocolRequirements.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/DoNotTestProtocolRequirements.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/DoNotTestProtocolRequirements.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/DoNotTestProtocolRequirements.java Thu May  6 20:02:22 2010
@@ -41,8 +41,6 @@ import org.apache.http.ProtocolVersion;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.cache.HttpCache;
-import org.apache.http.client.cache.impl.BasicHttpCache;
-import org.apache.http.client.cache.impl.CachingHttpClient;
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.message.BasicHttpRequest;

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCacheEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCacheEntry.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCacheEntry.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCacheEntry.java Thu May  6 20:02:22 2010
@@ -26,11 +26,13 @@
  */
 package org.apache.http.client.cache.impl;
 
+import static junit.framework.Assert.assertFalse;
+
 import java.util.Date;
 import java.util.Set;
 
 import org.apache.http.Header;
-import org.apache.http.client.cache.impl.CacheEntry;
+import org.apache.http.ProtocolVersion;
 import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.message.BasicHeader;
 import org.junit.Assert;
@@ -38,22 +40,26 @@ import org.junit.Test;
 
 public class TestCacheEntry {
 
+    private static ProtocolVersion HTTP_1_1 = new ProtocolVersion("HTTP",1,1);
+
     @Test
     public void testGetHeadersReturnsCorrectHeaders() {
         Header[] headers = new Header[] { new BasicHeader("foo", "fooValue"),
                 new BasicHeader("bar", "barValue1"), new BasicHeader("bar", "barValue2") };
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
+        CacheEntry entry = getEntry(headers);
         Assert.assertEquals(2, entry.getHeaders("bar").length);
     }
 
+    private CacheEntry getEntry(Header[] headers) {
+        return getEntry(new Date(), new Date(), headers);
+    }
+
     @Test
     public void testGetFirstHeaderReturnsCorrectHeader() {
         Header[] headers = new Header[] { new BasicHeader("foo", "fooValue"),
                 new BasicHeader("bar", "barValue1"), new BasicHeader("bar", "barValue2") };
+        CacheEntry entry = getEntry(headers);
 
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
         Assert.assertEquals("barValue1", entry.getFirstHeader("bar").getValue());
     }
 
@@ -62,8 +68,8 @@ public class TestCacheEntry {
         Header[] headers = new Header[] { new BasicHeader("foo", "fooValue"),
                 new BasicHeader("bar", "barValue1"), new BasicHeader("bar", "barValue2") };
 
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
+
+        CacheEntry entry = getEntry(headers);
 
         Assert.assertEquals(0, entry.getHeaders("baz").length);
     }
@@ -72,9 +78,8 @@ public class TestCacheEntry {
     public void testGetFirstHeaderReturnsNullIfNoneMatch() {
         Header[] headers = new Header[] { new BasicHeader("foo", "fooValue"),
                 new BasicHeader("bar", "barValue1"), new BasicHeader("bar", "barValue2") };
+        CacheEntry entry = getEntry(headers);
 
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
 
         Assert.assertEquals(null, entry.getFirstHeader("quux"));
     }
@@ -82,8 +87,7 @@ public class TestCacheEntry {
     @Test
     public void testApparentAgeIsMaxIntIfDateHeaderNotPresent() {
         Header[] headers = new Header[0];
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
+        CacheEntry entry = getEntry(headers);
         Assert.assertEquals(2147483648L, entry.getApparentAgeSecs());
     }
 
@@ -96,13 +100,17 @@ public class TestCacheEntry {
         Header[] headers = new Header[] { new BasicHeader("Date", DateUtils
                 .formatDate(tenSecondsAgo)) };
 
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
-        entry.setResponseDate(sixSecondsAgo);
+
+
+        CacheEntry entry = getEntry(now, sixSecondsAgo, headers);
 
         Assert.assertEquals(4, entry.getApparentAgeSecs());
     }
 
+    private CacheEntry getEntry(Date requestDate, Date responseDate, Header[] headers) {
+        return new CacheEntry(requestDate,responseDate,HTTP_1_1,headers,new byte[]{},200,"OK");
+    }
+
     @Test
     public void testNegativeApparentAgeIsBroughtUpToZero() {
         Date now = new Date();
@@ -112,17 +120,14 @@ public class TestCacheEntry {
         Header[] headers = new Header[] { new BasicHeader("Date", DateUtils
                 .formatDate(sixSecondsAgo)) };
 
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
-        entry.setResponseDate(tenSecondsAgo);
-
+        CacheEntry entry  = getEntry(now,tenSecondsAgo,headers);
         Assert.assertEquals(0, entry.getApparentAgeSecs());
     }
 
     @Test
     public void testCorrectedReceivedAgeIsAgeHeaderIfLarger() {
         Header[] headers = new Header[] { new BasicHeader("Age", "10"), };
-        CacheEntry entry = new CacheEntry() {
+        CacheEntry entry = new CacheEntry(new Date(),new Date(),HTTP_1_1,headers, new byte[]{},200,"OK") {
             private static final long serialVersionUID = 1L;
 
             @Override
@@ -130,7 +135,7 @@ public class TestCacheEntry {
                 return 6;
             }
         };
-        entry.setResponseHeaders(headers);
+
 
         Assert.assertEquals(10, entry.getCorrectedReceivedAgeSecs());
     }
@@ -138,7 +143,7 @@ public class TestCacheEntry {
     @Test
     public void testCorrectedReceivedAgeIsApparentAgeIfLarger() {
         Header[] headers = new Header[] { new BasicHeader("Age", "6"), };
-        CacheEntry entry = new CacheEntry() {
+        CacheEntry entry = new CacheEntry(new Date(),new Date(),HTTP_1_1,headers, new byte[]{},200,"OK") {
             private static final long serialVersionUID = 1L;
 
             @Override
@@ -146,7 +151,6 @@ public class TestCacheEntry {
                 return 10;
             }
         };
-        entry.setResponseHeaders(headers);
 
         Assert.assertEquals(10, entry.getCorrectedReceivedAgeSecs());
     }
@@ -157,16 +161,17 @@ public class TestCacheEntry {
         Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
         Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
-        CacheEntry entry = new CacheEntry();
-        entry.setRequestDate(tenSecondsAgo);
-        entry.setResponseDate(sixSecondsAgo);
+        Header[] headers = new Header[]{};
+
+        CacheEntry entry = new CacheEntry(tenSecondsAgo,sixSecondsAgo,new ProtocolVersion("HTTP",1,1),headers,new byte[]{},200,"OK");
+
 
         Assert.assertEquals(4, entry.getResponseDelaySecs());
     }
 
     @Test
     public void testCorrectedInitialAgeIsCorrectedReceivedAgePlusResponseDelay() {
-        CacheEntry entry = new CacheEntry() {
+        CacheEntry entry = new CacheEntry(new Date(),new Date(),HTTP_1_1,new Header[]{}, new byte[]{},200,"OK") {
             private static final long serialVersionUID = 1L;
 
             @Override
@@ -187,7 +192,7 @@ public class TestCacheEntry {
         final Date now = new Date();
         Date sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
 
-        CacheEntry entry = new CacheEntry() {
+        CacheEntry entry = new CacheEntry(new Date(),sixSecondsAgo,HTTP_1_1,new Header[]{}, new byte[]{},200,"OK") {
             private static final long serialVersionUID = 1L;
 
             @Override
@@ -195,14 +200,13 @@ public class TestCacheEntry {
                 return now;
             }
         };
-        entry.setResponseDate(sixSecondsAgo);
 
         Assert.assertEquals(6, entry.getResidentTimeSecs());
     }
 
     @Test
     public void testCurrentAgeIsCorrectedInitialAgePlusResidentTime() {
-        CacheEntry entry = new CacheEntry() {
+        CacheEntry entry = new CacheEntry(new Date(),new Date(),HTTP_1_1,new Header[]{}, new byte[]{},200,"OK") {
             private static final long serialVersionUID = 1L;
 
             @Override
@@ -221,16 +225,14 @@ public class TestCacheEntry {
     @Test
     public void testFreshnessLifetimeIsSMaxAgeIfPresent() {
         Header[] headers = new Header[] { new BasicHeader("Cache-Control", "s-maxage=10") };
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
+        CacheEntry entry = getEntry(headers);
         Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
     }
 
     @Test
     public void testFreshnessLifetimeIsMaxAgeIfPresent() {
         Header[] headers = new Header[] { new BasicHeader("Cache-Control", "max-age=10") };
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
+        CacheEntry entry = getEntry(headers);
         Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
     }
 
@@ -238,14 +240,12 @@ public class TestCacheEntry {
     public void testFreshnessLifetimeIsMostRestrictiveOfMaxAgeAndSMaxAge() {
         Header[] headers = new Header[] { new BasicHeader("Cache-Control", "max-age=10"),
                 new BasicHeader("Cache-Control", "s-maxage=20") };
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
+        CacheEntry entry = getEntry(headers);
         Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
 
         headers = new Header[] { new BasicHeader("Cache-Control", "max-age=20"),
                 new BasicHeader("Cache-Control", "s-maxage=10") };
-        entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
+        entry = getEntry(headers);
         Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
     }
 
@@ -258,8 +258,7 @@ public class TestCacheEntry {
                 new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
                 new BasicHeader("Expires", DateUtils.formatDate(sixSecondsAgo)) };
 
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
+        CacheEntry entry = getEntry(headers);
         Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
     }
 
@@ -272,8 +271,7 @@ public class TestCacheEntry {
                 new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
                 new BasicHeader("Expires", DateUtils.formatDate(sixSecondsAgo)) };
 
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
+        CacheEntry entry = getEntry(headers);
         Assert.assertEquals(10, entry.getFreshnessLifetimeSecs());
     }
 
@@ -286,14 +284,13 @@ public class TestCacheEntry {
                 new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
                 new BasicHeader("Expires", DateUtils.formatDate(sixSecondsAgo)) };
 
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
+        CacheEntry entry = getEntry(headers);
         Assert.assertEquals(4, entry.getFreshnessLifetimeSecs());
     }
 
     @Test
     public void testResponseIsFreshIfFreshnessLifetimeExceedsCurrentAge() {
-        CacheEntry entry = new CacheEntry() {
+        CacheEntry entry = new CacheEntry(new Date(),new Date(),HTTP_1_1,new Header[]{}, new byte[]{},200,"OK") {
             private static final long serialVersionUID = 1L;
 
             @Override
@@ -312,7 +309,7 @@ public class TestCacheEntry {
 
     @Test
     public void testResponseIsNotFreshIfFreshnessLifetimeEqualsCurrentAge() {
-        CacheEntry entry = new CacheEntry() {
+        CacheEntry entry = new CacheEntry(new Date(),new Date(),HTTP_1_1,new Header[]{}, new byte[]{},200,"OK") {
             private static final long serialVersionUID = 1L;
 
             @Override
@@ -331,7 +328,7 @@ public class TestCacheEntry {
 
     @Test
     public void testResponseIsNotFreshIfCurrentAgeExceedsFreshnessLifetime() {
-        CacheEntry entry = new CacheEntry() {
+        CacheEntry entry = new CacheEntry(new Date(),new Date(),HTTP_1_1,new Header[]{}, new byte[]{},200,"OK") {
             private static final long serialVersionUID = 1L;
 
             @Override
@@ -350,46 +347,53 @@ public class TestCacheEntry {
 
     @Test
     public void testCacheEntryIsRevalidatableIfHeadersIncludeETag() {
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(new Header[] {
+
+        Header[] headers = {
                 new BasicHeader("Expires", DateUtils.formatDate(new Date())),
-                new BasicHeader("ETag", "somevalue") });
+                new BasicHeader("ETag", "somevalue")};
+
+        CacheEntry entry = getEntry(headers);
 
         Assert.assertTrue(entry.isRevalidatable());
     }
 
     @Test
     public void testCacheEntryIsRevalidatableIfHeadersIncludeLastModifiedDate() {
-        CacheEntry entry = new CacheEntry();
 
-        entry.setResponseHeaders(new Header[] {
+        Header[] headers = {
                 new BasicHeader("Expires", DateUtils.formatDate(new Date())),
-                new BasicHeader("Last-Modified", DateUtils.formatDate(new Date())) });
+                new BasicHeader("Last-Modified", DateUtils.formatDate(new Date())) };
 
+        CacheEntry entry = getEntry(headers);
         Assert.assertTrue(entry.isRevalidatable());
     }
 
     @Test
     public void testCacheEntryIsNotRevalidatableIfNoAppropriateHeaders() {
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(new Header[] {
+
+        Header[] headers =  {
                 new BasicHeader("Expires", DateUtils.formatDate(new Date())),
-                new BasicHeader("Cache-Control", "public") });
+                new BasicHeader("Cache-Control", "public") };
+
+        CacheEntry entry = getEntry(headers);
+
+        assertFalse(entry.isRevalidatable());
     }
 
+
+
     @Test
     public void testCacheEntryWithNoVaryHeaderDoesNotHaveVariants() {
         Header[] headers = new Header[0];
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
+
+        CacheEntry entry = getEntry(headers);
         Assert.assertFalse(entry.hasVariants());
     }
 
     @Test
     public void testCacheEntryWithOneVaryHeaderHasVariants() {
         Header[] headers = { new BasicHeader("Vary", "User-Agent") };
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
+        CacheEntry entry = getEntry(headers);
         Assert.assertTrue(entry.hasVariants());
     }
 
@@ -397,20 +401,27 @@ public class TestCacheEntry {
     public void testCacheEntryWithMultipleVaryHeadersHasVariants() {
         Header[] headers = { new BasicHeader("Vary", "User-Agent"),
                 new BasicHeader("Vary", "Accept-Encoding") };
-        CacheEntry entry = new CacheEntry();
-        entry.setResponseHeaders(headers);
+        CacheEntry entry = getEntry(headers);
+        Assert.assertTrue(entry.hasVariants());
+    }
+
+    @Test
+    public void testCacheEntryWithVaryStarHasVariants(){
+        Header[] headers = { new BasicHeader("Vary", "*") };
+        CacheEntry entry = getEntry(headers);
         Assert.assertTrue(entry.hasVariants());
     }
 
     @Test
     public void testCacheEntryCanStoreMultipleVariantUris() {
 
-        CacheEntry entry = new CacheEntry();
+        Header[] headers = new Header[]{};
+        CacheEntry entry = getEntry(headers);
 
-        entry.addVariantURI("foo");
-        entry.addVariantURI("bar");
+        CacheEntry addedOne = entry.addVariantURI("foo");
+        CacheEntry addedTwo = addedOne.addVariantURI("bar");
 
-        Set<String> variants = entry.getVariantURIs();
+        Set<String> variants = addedTwo.getVariantURIs();
 
         Assert.assertTrue(variants.contains("foo"));
         Assert.assertTrue(variants.contains("bar"));
@@ -419,76 +430,67 @@ public class TestCacheEntry {
     @Test
     public void testMalformedDateHeaderIsIgnored() {
 
-        Header[] h = new Header[] { new BasicHeader("Date", "asdf") };
-        CacheEntry e = new CacheEntry();
-        e.setResponseHeaders(h);
+        Header[] headers = new Header[] { new BasicHeader("Date", "asdf") };
+        CacheEntry entry = getEntry(headers);
 
-        Date d = e.getDateValue();
+        Date d = entry.getDateValue();
 
         Assert.assertNull(d);
-
     }
 
     @Test
     public void testMalformedContentLengthReturnsNegativeOne() {
 
-        Header[] h = new Header[] { new BasicHeader("Content-Length", "asdf") };
-        CacheEntry e = new CacheEntry();
-        e.setResponseHeaders(h);
+        Header[] headers = new Header[] { new BasicHeader("Content-Length", "asdf") };
+        CacheEntry entry = getEntry(headers);
 
-        long length = e.getContentLengthValue();
+        long length = entry.getContentLengthValue();
 
         Assert.assertEquals(-1, length);
-
     }
 
     @Test
     public void testNegativeAgeHeaderValueReturnsMaxAge() {
 
-        Header[] h = new Header[] { new BasicHeader("Age", "-100") };
-        CacheEntry e = new CacheEntry();
-        e.setResponseHeaders(h);
+        Header[] headers = new Header[] { new BasicHeader("Age", "-100") };
+        CacheEntry entry = getEntry(headers);
 
-        long length = e.getAgeValue();
+        long length = entry.getAgeValue();
 
         Assert.assertEquals(CacheEntry.MAX_AGE, length);
-
     }
 
     @Test
     public void testMalformedAgeHeaderValueReturnsMaxAge() {
 
-        Header[] h = new Header[] { new BasicHeader("Age", "asdf") };
-        CacheEntry e = new CacheEntry();
-        e.setResponseHeaders(h);
+        Header[] headers = new Header[] { new BasicHeader("Age", "asdf") };
+        CacheEntry entry = getEntry(headers);
 
-        long length = e.getAgeValue();
+        long length = entry.getAgeValue();
 
         Assert.assertEquals(CacheEntry.MAX_AGE, length);
-
     }
 
     @Test
     public void testMalformedCacheControlMaxAgeHeaderReturnsZero() {
 
-        Header[] h = new Header[] { new BasicHeader("Cache-Control", "max-age=asdf") };
-        CacheEntry e = new CacheEntry();
-        e.setResponseHeaders(h);
+        Header[] headers = new Header[] { new BasicHeader("Cache-Control", "max-age=asdf") };
+        CacheEntry entry = getEntry(headers);
 
-        long maxage = e.getMaxAge();
+        long maxage = entry.getMaxAge();
 
         Assert.assertEquals(0, maxage);
-
     }
 
     @Test
     public void testMalformedExpirationDateReturnsNull() {
-        Header[] h = new Header[] { new BasicHeader("Expires", "asdf") };
-        CacheEntry e = new CacheEntry();
-        e.setResponseHeaders(h);
+        Header[] headers = new Header[] { new BasicHeader("Expires", "asdf") };
+        CacheEntry entry = getEntry(headers);
 
-        Date expirationDate = e.getExpirationDate();
+        Date expirationDate = entry.getExpirationDate();
 
         Assert.assertNull(expirationDate);
     }
+
+
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCacheEntryGenerator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCacheEntryGenerator.java?rev=941886&r1=941885&r2=941886&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCacheEntryGenerator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/impl/TestCacheEntryGenerator.java Thu May  6 20:02:22 2010
@@ -33,8 +33,6 @@ import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.ProtocolVersion;
-import org.apache.http.client.cache.impl.CacheEntry;
-import org.apache.http.client.cache.impl.CacheEntryGenerator;
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.message.BasicHttpResponse;
 import org.junit.Assert;



Mime
View raw message