You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by jo...@apache.org on 2011/01/12 15:21:33 UTC

svn commit: r1058153 - in /httpcomponents/httpclient/trunk: ./ httpclient-cache/src/main/java/org/apache/http/client/cache/ httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ httpclient-cache/src/test/java/org/apache/http/client/cache/ h...

Author: jonm
Date: Wed Jan 12 14:21:32 2011
New Revision: 1058153

URL: http://svn.apache.org/viewvc?rev=1058153&view=rev
Log:
Removed deprecated HttpCacheEntry#getVariantURIs and associated
constructors and fields. Also removed code in surrounding classes
that was providing backwards compatibility for the deprecated
Set-based variant data structure. Made a note in the ChangeLog
about the change to the public API between 4.1-beta and 4.1.

Removed:
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestProtocolRequirementsWithDeprecatedSerializer.java
Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntry.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/CacheInvalidator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/TestHttpCacheEntry.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntrySerializers.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1058153&r1=1058152&r2=1058153&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Wed Jan 12 14:21:32 2011
@@ -32,6 +32,9 @@ maintained and supported by Apache HttpC
 
 Changelog
 -------------------
+* The public API for the caching module had a minor change between 4.1-beta and 4.1-GA to the
+  HttpCacheEntry class. This will likely not affect you unless you are implementing new
+  storage backends and/or implementing custom serializers for cache entries.
 
 * Changed Browser-Compatibility and Best-Match cookie policies to emulate the behaviour of FireFox
   more closely when parsing Netscape style cookies. Comma will no longer be treated as a header
@@ -43,7 +46,7 @@ Changelog
   to US-ASCII)
   Contributed by Sebastian Bazley <sebb at apache.org>
 
-* [HTTPCLIENT-975] Support stale-if-error extension directive (RFC5861).
+* [HTTPCLIENT-975] Support stale-if-error and stale-while-revalidate extension directive (RFC5861).
   Contributed by Mohammed Azeem Uddin <mohammedazeem_uddin at comcast.com>,
   Michajlo Matijkiw <michajlo_matijkiw at comcast.com>, and
   Matthew Hawthorne <matthew_hawthorne at comcast.com>.

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntry.java?rev=1058153&r1=1058152&r2=1058153&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntry.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntry.java Wed Jan 12 14:21:32 2011
@@ -30,10 +30,7 @@ import java.io.Serializable;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
-
 import org.apache.http.Header;
 import org.apache.http.HttpResponse;
 import org.apache.http.ProtocolVersion;
@@ -60,16 +57,32 @@ public class HttpCacheEntry implements S
     private final StatusLine statusLine;
     private final HeaderGroup responseHeaders;
     private final Resource resource;
-    private final Set<String> variantURIs;
     private final Map<String,String> variantMap;
 
-    private HttpCacheEntry(
+    /**
+     * Create a new {@link HttpCacheEntry} with variants.
+     * @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 statusLine
+     *          HTTP status line from origin response
+     * @param responseHeaders
+     *          Header[] from original HTTP Response
+     * @param resource representing origin response body
+     * @param variantMap describing cache entries that are variants
+     *   of this parent entry; this maps a "variant key" (derived
+     *   from the varying request headers) to a "cache key" (where
+     *   in the cache storage the particular variant is located)
+     */
+    public HttpCacheEntry(
             final Date requestDate,
             final Date responseDate,
             final StatusLine statusLine,
             final Header[] responseHeaders,
             final Resource resource,
-            final Set<String> variants,
             final Map<String,String> variantMap) {
         super();
         if (requestDate == null) {
@@ -93,44 +106,12 @@ public class HttpCacheEntry implements S
         this.responseHeaders = new HeaderGroup();
         this.responseHeaders.setHeaders(responseHeaders);
         this.resource = resource;
-        this.variantURIs = variants != null
-            ? new HashSet<String>(variants) : null;
         this.variantMap = variantMap != null
             ? new HashMap<String,String>(variantMap)
             : null;
     }
     
     /**
-     * Create a new {@link HttpCacheEntry} with a set of variant
-     * URIs.
-     *
-     * @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 statusLine
-     *          HTTP status line from origin response
-     * @param responseHeaders
-     *          Header[] from original HTTP Response
-     * @param resource representing origin response body
-     * @param variants set of cache keys that are variants of this
-     *   "parent" entry
-     */
-    @Deprecated
-    public HttpCacheEntry(
-            final Date requestDate,
-            final Date responseDate,
-            final StatusLine statusLine,
-            final Header[] responseHeaders,
-            final Resource resource,
-            final Set<String> variants) {
-        this(requestDate, responseDate, statusLine, responseHeaders,
-                resource, variants, null);
-    }
-
-    /**
      * Create a new {@link HttpCacheEntry}.
      *
      * @param requestDate
@@ -147,36 +128,11 @@ public class HttpCacheEntry implements S
      */
     public HttpCacheEntry(Date requestDate, Date responseDate, StatusLine statusLine,
             Header[] responseHeaders, Resource resource) {
-        this(requestDate, responseDate, statusLine, responseHeaders, resource, null,
+        this(requestDate, responseDate, statusLine, responseHeaders, resource,
                 new HashMap<String,String>());
     }
 
     /**
-     * Create a new {@link HttpCacheEntry} with variants.
-     * @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 statusLine
-     *          HTTP status line from origin response
-     * @param responseHeaders
-     *          Header[] from original HTTP Response
-     * @param resource representing origin response body
-     * @param variantMap describing cache entries that are variants
-     *   of this parent entry; this maps a "variant key" (derived
-     *   from the varying request headers) to a "cache key" (where
-     *   in the cache storage the particular variant is located)
-     */
-    public HttpCacheEntry(Date requestDate, Date responseDate,
-            StatusLine statusLine, Header[] responseHeaders,
-            Resource resource, Map<String, String> variantMap) {
-        this(requestDate, responseDate, statusLine, responseHeaders,
-             resource, null, variantMap);
-    }
-
-    /**
      * Returns the {@link StatusLine} from the origin {@link HttpResponse}.
      */
     public StatusLine getStatusLine() {
@@ -262,14 +218,6 @@ public class HttpCacheEntry implements S
         return getFirstHeader(HeaderConstants.VARY) != null;
     }
 
-    @Deprecated
-    public Set<String> getVariantURIs() {
-        if (variantMap != null) {
-            return Collections.unmodifiableSet(new HashSet<String>(variantMap.values()));
-        }
-        return Collections.unmodifiableSet(variantURIs);
-    }
-
     /**
      * Returns an index about where in the cache different variants for
      * a given resource are stored. This maps "variant keys" to "cache keys",
@@ -280,10 +228,6 @@ public class HttpCacheEntry implements S
      * the "parent" entry to hold this index of the other variants.
      */
     public Map<String, String> getVariantMap() {
-        if (variantMap == null) {
-            throw new UnsupportedOperationException("variant maps not" +
-                    "supported if constructed with deprecated variant set");
-        }
         return Collections.unmodifiableMap(variantMap);
     }
 

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=1058153&r1=1058152&r2=1058153&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 Wed Jan 12 14:21:32 2011
@@ -29,10 +29,7 @@ package org.apache.http.impl.client.cach
 import java.io.IOException;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.Header;
@@ -53,14 +50,6 @@ import org.apache.http.message.BasicHttp
 
 class BasicHttpCache implements HttpCache {
 
-    static final String DEPRECATED_VARIANT_SET_MSG =
-        "It looks like you have a custom HttpCacheEntrySerializer " +
-        "that was written against the 4.1-beta API and is using the " +
-        "old (and deprecated) variant tracking mechanism of a Set " +
-        "instead of a Map. Everything is still working, just not as " +
-        "efficiently as possible. Please update your serializer" +
-        "appropriately to use the non-deprecated API for HttpCacheEntry.";
-    
     private final CacheKeyGenerator uriExtractor;
     private final ResourceFactory resourceFactory;
     private final int maxObjectSizeBytes;
@@ -194,7 +183,6 @@ class BasicHttpCache implements HttpCach
         return error;
     }
 
-    @SuppressWarnings("deprecation")
     HttpCacheEntry doGetUpdatedParentEntry(
             final String requestId,
             final HttpCacheEntry existing,
@@ -207,29 +195,15 @@ class BasicHttpCache implements HttpCach
         }
         
         Resource resource = resourceFactory.copy(requestId, src.getResource());
-        try {
-            Map<String,String> variantMap = new HashMap<String,String>(src.getVariantMap());
-            variantMap.put(variantKey, variantCacheKey);
-            return new HttpCacheEntry(
-                    src.getRequestDate(),
-                    src.getResponseDate(),
-                    src.getStatusLine(),
-                    src.getAllHeaders(),
-                    resource,
-                    variantMap);
-        } catch (UnsupportedOperationException uoe) {
-            // TODO: to be removed once HttpCacheEntry#getVariantURIs is removed
-            log.warn(DEPRECATED_VARIANT_SET_MSG);
-            Set<String> variantURIs = new HashSet<String>(src.getVariantURIs());
-            variantURIs.add(variantCacheKey);
-            return new HttpCacheEntry(
-                    src.getRequestDate(),
-                    src.getResponseDate(),
-                    src.getStatusLine(),
-                    src.getAllHeaders(),
-                    resource,
-                    variantURIs);
-        }
+        Map<String,String> variantMap = new HashMap<String,String>(src.getVariantMap());
+        variantMap.put(variantKey, variantCacheKey);
+        return new HttpCacheEntry(
+                src.getRequestDate(),
+                src.getResponseDate(),
+                src.getStatusLine(),
+                src.getAllHeaders(),
+                resource,
+                variantMap);
     }
 
     public HttpCacheEntry updateCacheEntry(HttpHost target, HttpRequest request,
@@ -293,14 +267,7 @@ class BasicHttpCache implements HttpCach
         HttpCacheEntry root = storage.getEntry(uriExtractor.getURI(host, request));
         if (root == null) return null;
         if (!root.hasVariants()) return root;
-        String variantCacheKey = null;
-        try {
-            variantCacheKey = root.getVariantMap().get(uriExtractor.getVariantKey(request, root));
-        } catch (UnsupportedOperationException uoe) {
-            // TODO: to be removed once HttpCacheEntry#getVariantURIs is removed
-            log.warn(DEPRECATED_VARIANT_SET_MSG);
-            variantCacheKey = uriExtractor.getVariantURI(host, request, root); 
-        }
+        String variantCacheKey = root.getVariantMap().get(uriExtractor.getVariantKey(request, root));
         if (variantCacheKey == null) return null;
         return storage.getEntry(variantCacheKey);
     }
@@ -310,25 +277,15 @@ class BasicHttpCache implements HttpCach
         cacheInvalidator.flushInvalidatedCacheEntries(host, request);
     }
 
-    @SuppressWarnings("deprecation")
     public Map<String, Variant> getVariantCacheEntriesWithEtags(HttpHost host, HttpRequest request)
             throws IOException {
         Map<String,Variant> variants = new HashMap<String,Variant>();
         HttpCacheEntry root = storage.getEntry(uriExtractor.getURI(host, request));
         if (root == null || !root.hasVariants()) return variants;
-        try {
-            for(Map.Entry<String, String> variant : root.getVariantMap().entrySet()) {
-                String variantKey = variant.getKey();
-                String variantCacheKey = variant.getValue();
-                addVariantWithEtag(variantKey, variantCacheKey, variants);
-            }
-        } catch (UnsupportedOperationException uoe) {
-            // TODO: to be removed once HttpCacheEntry#getVariantURIs is removed
-            log.warn(DEPRECATED_VARIANT_SET_MSG);
-            for(String variantCacheKey : root.getVariantURIs()) {
-                String variantKey = uriExtractor.getVariantKey(request, root);
-                addVariantWithEtag(variantKey, variantCacheKey, variants);
-            }
+        for(Map.Entry<String, String> variant : root.getVariantMap().entrySet()) {
+            String variantKey = variant.getKey();
+            String variantCacheKey = variant.getValue();
+            addVariantWithEtag(variantKey, variantCacheKey, variants);
         }
         return variants;
     }

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=1058153&r1=1058152&r2=1058153&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 Wed Jan 12 14:21:32 2011
@@ -29,7 +29,6 @@ package org.apache.http.impl.client.cach
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.Collection;
 import java.util.Date;
 
 import org.apache.commons.logging.Log;
@@ -80,7 +79,6 @@ class CacheInvalidator {
      * @param host The backend host we are talking to
      * @param req The HttpRequest to that host
      */
-    @SuppressWarnings("deprecation")
     public void flushInvalidatedCacheEntries(HttpHost host, HttpRequest req)  {
         if (requestShouldNotBeCached(req)) {
             log.debug("Request should not be cached");
@@ -92,15 +90,7 @@ class CacheInvalidator {
             log.debug("parent entry: " + parent);
 
             if (parent != null) {
-                Collection<String> variantURIs = null;
-                try {
-                    variantURIs = parent.getVariantMap().values();
-                } catch (UnsupportedOperationException uoe) {
-                    // TODO: to be removed once HttpCacheEntry#getVariantURIs is removed
-                    log.warn(BasicHttpCache.DEPRECATED_VARIANT_SET_MSG);
-                    variantURIs = parent.getVariantURIs();
-                }
-                for (String variantURI : variantURIs) {
+                for (String variantURI : parent.getVariantMap().values()) {
                     flushEntry(variantURI);
                 }
                 flushEntry(theUri);

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/TestHttpCacheEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/TestHttpCacheEntry.java?rev=1058153&r1=1058152&r2=1058153&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/TestHttpCacheEntry.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/client/cache/TestHttpCacheEntry.java Wed Jan 12 14:21:32 2011
@@ -31,10 +31,7 @@ import static org.junit.Assert.*;
 
 import java.util.Date;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
-
 import org.apache.http.Header;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
@@ -256,58 +253,7 @@ public class TestHttpCacheEntry {
             assertEquals(headers[i], result[i]);
         }
     }
-
-    @SuppressWarnings("deprecation")
-    @Test
-    public void canRetrieveOriginalVariantSet() {
-        Set<String> variants = new HashSet<String>();
-        variants.add("variant1");
-        variants.add("variant2");
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
-                new Header[]{}, mockResource, variants);
-        Set<String> result = entry.getVariantURIs();
-        assertEquals(variants.size(), result.size());
-        for(String variant : variants) {
-            assertTrue(result.contains(variant));
-        }
-    }
-
-    @SuppressWarnings("deprecation")
-    @Test
-    public void throwsExceptionWhenRetrievingVariantMapIfConstructedWithVariantSet() {
-        Set<String> variants = new HashSet<String>();
-        variants.add("variant1");
-        variants.add("variant2");
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
-                new Header[]{}, mockResource, variants);
-        try {
-            entry.getVariantMap();
-            fail("should have thrown exception");
-        } catch (UnsupportedOperationException expected) {
-        }
-    }
-    
-    @SuppressWarnings("deprecation")
-    @Test
-    public void variantSetIsNotModifiable() {
-        Set<String> variants = new HashSet<String>();
-        variants.add("variant1");
-        variants.add("variant2");
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
-                new Header[]{}, mockResource, variants);
-        Set<String> result = entry.getVariantURIs();
-        try {
-            result.remove("variant1");
-            fail("Should have thrown exception");
-        } catch (UnsupportedOperationException expected) {
-        }
-        try {
-            result.add("variant3");
-            fail("Should have thrown exception");
-        } catch (UnsupportedOperationException expected) {
-        }
-    }
-    
+        
     @Test
     public void canConstructWithoutVariants() {
         new HttpCacheEntry(new Date(), new Date(), statusLine,
@@ -334,21 +280,6 @@ public class TestHttpCacheEntry {
         assertEquals("B", result.get("A"));
         assertEquals("D", result.get("C"));
     }
-
-    @SuppressWarnings("deprecation")
-    @Test
-    public void returnsVariantMapValuesForVariantSet() {
-        Map<String,String> variantMap = new HashMap<String,String>();
-        variantMap.put("A","B");
-        variantMap.put("C","D");
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
-                new Header[]{}, mockResource,
-                variantMap);
-        Set<String> result = entry.getVariantURIs();
-        assertEquals(2, result.size());
-        assertTrue(result.contains("B"));
-        assertTrue(result.contains("D"));
-    }
     
     @Test
     public void retrievedVariantMapIsNotModifiable() {

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntrySerializers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntrySerializers.java?rev=1058153&r1=1058152&r2=1058153&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntrySerializers.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntrySerializers.java Wed Jan 12 14:21:32 2011
@@ -35,10 +35,7 @@ import java.nio.charset.Charset;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
-
 import org.apache.commons.codec.binary.Base64;
 import org.apache.http.Header;
 import org.apache.http.ProtocolVersion;
@@ -64,11 +61,6 @@ public class TestHttpCacheEntrySerialize
     }
     
     @Test
-    public void canSerializeOldEntriesWithVariantSets() throws Exception {
-        readWriteVerify(makeCacheEntryWithOldVariantSet());
-    }
-
-    @Test
     public void canSerializeEntriesWithVariantMaps() throws Exception {
         readWriteVerify(makeCacheEntryWithVariantMap());
     }
@@ -86,26 +78,6 @@ public class TestHttpCacheEntrySerialize
         assertTrue(areEqual(readEntry, writeEntry));
     }
 
-    @SuppressWarnings("deprecation")
-    private HttpCacheEntry makeCacheEntryWithOldVariantSet() throws UnsupportedEncodingException {
-        Header[] headers = new Header[5];
-        for (int i = 0; i < headers.length; i++) {
-            headers[i] = new BasicHeader("header" + i, "value" + i);
-        }
-        String body = "Lorem ipsum dolor sit amet";
-
-        ProtocolVersion pvObj = new ProtocolVersion("HTTP", 1, 1);
-        StatusLine slObj = new BasicStatusLine(pvObj, 200, "ok");
-        Set<String> variants = new HashSet<String>();
-        variants.add("test variant 1");
-        variants.add("test variant 2");
-        HttpCacheEntry cacheEntry = new HttpCacheEntry(new Date(), new Date(),
-                slObj, headers, new HeapResource(Base64.decodeBase64(body
-                        .getBytes(UTF8.name()))), variants);
-
-        return cacheEntry;
-    }
-
     private HttpCacheEntry makeCacheEntryWithVariantMap() throws UnsupportedEncodingException {
         Header[] headers = new Header[5];
         for (int i = 0; i < headers.length; i++) {