diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/CacheConfig.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/CacheConfig.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/CacheConfig.java 1969-12-31 19:00:00.000000000 -0500
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/CacheConfig.java 2010-09-30 12:55:28.000000000 -0400
@@ -0,0 +1,121 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.http.client.cache;
+
+/**
+ * Java Beans-style configuration for a
+ * {@link org.apache.http.impl.client.cache.CachingHttpClient}.
+ */
+public class CacheConfig {
+
+ /** Default setting for the maximum object size that will be
+ * cached, in bytes.
+ */
+ public final static int DEFAULT_MAX_OBJECT_SIZE_BYTES = 8192;
+
+ /** Default setting for the maximum number of cache entries
+ * that will be retained.
+ */
+ public final static int DEFAULT_MAX_CACHE_ENTRIES = 1000;
+
+ /** Default setting for the number of retries on a failed
+ * cache update
+ */
+ public final static int DEFAULT_MAX_UPDATE_RETRIES = 1;
+
+ private int maxObjectSizeBytes = DEFAULT_MAX_OBJECT_SIZE_BYTES;
+ private int maxCacheEntries = DEFAULT_MAX_CACHE_ENTRIES;
+ private int maxUpdateRetries = DEFAULT_MAX_UPDATE_RETRIES;
+
+ private boolean isSharedCache = true;
+
+ /**
+ * Returns the current maximum object size that will be cached.
+ * @return size in bytes
+ */
+ public int getMaxObjectSizeBytes() {
+ return maxObjectSizeBytes;
+ }
+
+ /**
+ * Specifies the maximum object size that will be eligible for caching.
+ * @param maxObjectSizeBytes size in bytes
+ */
+ public void setMaxObjectSizeBytes(int maxObjectSizeBytes) {
+ this.maxObjectSizeBytes = maxObjectSizeBytes;
+ }
+
+ /**
+ * Returns whether the cache will behave as a shared cache or not.
+ * @return true for a shared cache, false for a non-shared (private)
+ * cache
+ */
+ public boolean isSharedCache() {
+ return isSharedCache;
+ }
+
+ /**
+ * Sets whether the cache should behave as a shared cache or not.
+ * @param isSharedCache true to behave as a shared cache, false to
+ * behave as a non-shared (private) cache.
+ */
+ public void setSharedCache(boolean isSharedCache) {
+ this.isSharedCache = isSharedCache;
+ }
+
+ /**
+ * Returns the maximum number of cache entries the cache will retain.
+ * @return int
+ */
+ public int getMaxCacheEntries() {
+ return maxCacheEntries;
+ }
+
+ /**
+ * Sets the maximum number of cache entries the cache will retain.
+ * @param maxCacheEntries int
+ */
+ public void setMaxCacheEntries(int maxCacheEntries) {
+ this.maxCacheEntries = maxCacheEntries;
+ }
+
+ /**
+ * Returns the number of times to retry a cache update on failure
+ * @return int
+ */
+ public int getMaxUpdateRetries(){
+ return maxUpdateRetries;
+ }
+
+ /**
+ * Sets the number of times to retry a cache update on failure
+ * @param maxUpdateRetries int
+ */
+ public void setMaxUpdateRetries(int maxUpdateRetries){
+ this.maxUpdateRetries = maxUpdateRetries;
+ }
+}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HeaderConstants.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HeaderConstants.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HeaderConstants.java 2010-09-30 12:55:56.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HeaderConstants.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,74 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * .
- *
- */
-package org.apache.http.client.cache;
-
-import org.apache.http.annotation.Immutable;
-
-/**
- * @since 4.1
- */
-@Immutable
-public class HeaderConstants {
-
- public static final String GET_METHOD = "GET";
- public static final String HEAD_METHOD = "HEAD";
- public static final String OPTIONS_METHOD = "OPTIONS";
- public static final String PUT_METHOD = "PUT";
- public static final String DELETE_METHOD = "DELETE";
- 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";
-
- public static final String PRAGMA = "Pragma";
- public static final String MAX_FORWARDS = "Max-Forwards";
- public static final String ETAG = "ETag";
- public static final String EXPIRES = "Expires";
- public static final String AGE = "Age";
- public static final String VARY = "Vary";
- public static final String ALLOW = "Allow";
-
- public static final String CACHE_CONTROL = "Cache-Control";
- public static final String CACHE_CONTROL_NO_STORE = "no-store";
- public static final String CACHE_CONTROL_NO_CACHE = "no-cache";
- public static final String CACHE_CONTROL_MAX_AGE = "max-age";
- public static final String CACHE_CONTROL_MAX_STALE = "max-stale";
- public static final String CACHE_CONTROL_MIN_FRESH = "min-fresh";
- public static final String CACHE_CONTROL_MUST_REVALIDATE = "must-revalidate";
- public static final String CACHE_CONTROL_PROXY_REVALIDATE = "proxy-revalidate";
-
- public static final String WARNING = "Warning";
- public static final String RANGE = "Range";
- public static final String CONTENT_RANGE = "Content-Range";
- public static final String WWW_AUTHENTICATE = "WWW-Authenticate";
- public static final String PROXY_AUTHENTICATE = "Proxy-Authenticate";
-
-}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCache.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCache.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCache.java 2010-09-30 12:55:56.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCache.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,60 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * .
- *
- */
-package org.apache.http.client.cache;
-
-import java.io.IOException;
-import java.util.Date;
-
-import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpResponse;
-
-/**
- * @since 4.1
- */
-public interface HttpCache {
-
- void flushCacheEntriesFor(HttpHost host, HttpRequest request)
- throws IOException;
-
- void flushInvalidatedCacheEntriesFor(HttpHost host, HttpRequest request)
- throws IOException;
-
- HttpCacheEntry getCacheEntry(HttpHost host, HttpRequest request)
- throws IOException;
-
- HttpResponse cacheAndReturnResponse(
- HttpHost host, HttpRequest request, HttpResponse originResponse,
- Date requestSent, Date responseReceived)
- throws IOException;
-
- HttpResponse updateCacheEntry(
- HttpHost target, HttpRequest request, HttpCacheEntry stale, HttpResponse originResponse,
- Date requestSent, Date responseReceived)
- throws IOException;
-
-}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntry.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntry.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntry.java 2010-09-30 12:55:56.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntry.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,162 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * .
- *
- */
-package org.apache.http.client.cache;
-
-import java.io.Serializable;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.http.Header;
-import org.apache.http.HttpResponse;
-import org.apache.http.ProtocolVersion;
-import org.apache.http.StatusLine;
-import org.apache.http.annotation.Immutable;
-import org.apache.http.message.HeaderGroup;
-
-/**
- * Structure used to store an {@link HttpResponse} in a cache. Some entries can optionally depend
- * on system resources that may require explicit deallocation. In such a case {@link #getResource()}
- * should return a non-null instance of {@link Resource} that must be deallocated by calling
- * {@link Resource#dispose()} method when no longer used.
- *
- * @since 4.1
- */
-@Immutable
-public class HttpCacheEntry implements Serializable {
-
- private static final long serialVersionUID = -6300496422359477413L;
-
- private final Date requestDate;
- private final Date responseDate;
- private final StatusLine statusLine;
- private final HeaderGroup responseHeaders;
- private final Resource resource;
- private final Set variantURIs;
-
- /**
- * Create a new {@link HttpCacheEntry}
- *
- * @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
- * @param responseHeaders
- * Header[] from original HTTP Response
- */
- public HttpCacheEntry(
- final Date requestDate,
- final Date responseDate,
- final StatusLine statusLine,
- final Header[] responseHeaders,
- final Resource resource,
- final Set variants) {
- super();
- if (requestDate == null) {
- throw new IllegalArgumentException("Request date may not be null");
- }
- if (responseDate == null) {
- throw new IllegalArgumentException("Response date may not be null");
- }
- if (statusLine == null) {
- throw new IllegalArgumentException("Status line may not be null");
- }
- if (responseHeaders == null) {
- throw new IllegalArgumentException("Response headers may not be null");
- }
- if (resource == null) {
- throw new IllegalArgumentException("Resource may not be null");
- }
- this.requestDate = requestDate;
- this.responseDate = responseDate;
- this.statusLine = statusLine;
- this.responseHeaders = new HeaderGroup();
- this.responseHeaders.setHeaders(responseHeaders);
- this.resource = resource;
- this.variantURIs = variants != null ? new HashSet(variants) : new HashSet();
- }
-
- public StatusLine getStatusLine() {
- return this.statusLine;
- }
-
- public ProtocolVersion getProtocolVersion() {
- return this.statusLine.getProtocolVersion();
- }
-
- public String getReasonPhrase() {
- return this.statusLine.getReasonPhrase();
- }
-
- public int getStatusCode() {
- return this.statusLine.getStatusCode();
- }
-
- public Date getRequestDate() {
- return requestDate;
- }
-
- public Date getResponseDate() {
- return responseDate;
- }
-
- public Header[] getAllHeaders() {
- return responseHeaders.getAllHeaders();
- }
-
- public Header getFirstHeader(String name) {
- return responseHeaders.getFirstHeader(name);
- }
-
- public Header[] getHeaders(String name) {
- return responseHeaders.getHeaders(name);
- }
-
- public boolean hasVariants() {
- return getFirstHeader(HeaderConstants.VARY) != null;
- }
-
- public Set getVariantURIs() {
- return Collections.unmodifiableSet(this.variantURIs);
- }
-
- public Resource getResource() {
- return this.resource;
- }
-
- @Override
- public String toString() {
- return "[request date=" + this.requestDate + "; response date=" + this.responseDate
- + "; statusLine=" + this.statusLine + "]";
- }
-
-}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntrySerializationException.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntrySerializationException.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntrySerializationException.java 2010-09-30 12:55:56.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntrySerializationException.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,44 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * .
- *
- */
-package org.apache.http.client.cache;
-
-import java.io.IOException;
-
-public class HttpCacheEntrySerializationException extends IOException {
-
- private static final long serialVersionUID = 9219188365878433519L;
-
- public HttpCacheEntrySerializationException(final String message) {
- super();
- }
-
- public HttpCacheEntrySerializationException(final String message, final Throwable cause) {
- super(message);
- initCause(cause);
- }
-
-}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntrySerializer.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntrySerializer.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntrySerializer.java 2010-09-30 12:55:56.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheEntrySerializer.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,39 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * .
- *
- */
-package org.apache.http.client.cache;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-public interface HttpCacheEntrySerializer {
-
- public void writeTo(HttpCacheEntry entry, OutputStream os) throws IOException;
-
- public HttpCacheEntry readFrom(InputStream is) throws IOException;
-
-}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheStorage.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheStorage.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheStorage.java 2010-09-30 12:55:56.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheStorage.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,45 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * .
- *
- */
-package org.apache.http.client.cache;
-
-import java.io.IOException;
-
-/**
- * @since 4.1
- */
-public interface HttpCacheStorage {
-
- void putEntry(String key, HttpCacheEntry entry) throws IOException;
-
- HttpCacheEntry getEntry(String key) throws IOException;
-
- void removeEntry(String key) throws IOException;
-
- void updateEntry(
- String key, HttpCacheUpdateCallback callback) throws IOException, HttpCacheUpdateException;
-
-}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateCallback.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateCallback.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateCallback.java 2010-09-30 12:55:56.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateCallback.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,46 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * .
- *
- */
-package org.apache.http.client.cache;
-
-import java.io.IOException;
-
-public interface HttpCacheUpdateCallback {
-
- /**
- * Returns the new cache entry that should replace an existing one.
- *
- * @param existing
- * the cache entry current in-place in the cache, possibly
- * null if nonexistent
- * @return CacheEntry the cache entry that should replace it, again,
- * possible null
- *
- * @since 4.1
- */
- HttpCacheEntry update(HttpCacheEntry existing) throws IOException;
-
-}
\ No newline at end of file
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateException.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateException.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateException.java 2010-09-30 12:55:56.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateException.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,47 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * .
- *
- */
-package org.apache.http.client.cache;
-
-/**
- * Signals that {@link HttpCacheStorage} encountered an error performing an update operation.
- *
- * @since 4.1
- */
-public class HttpCacheUpdateException extends Exception {
-
- private static final long serialVersionUID = 823573584868632876L;
-
- public HttpCacheUpdateException(String message) {
- super(message);
- }
-
- public HttpCacheUpdateException(String message, Throwable cause) {
- super(message);
- initCause(cause);
- }
-
-}
\ No newline at end of file
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/InputLimit.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/InputLimit.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/InputLimit.java 2010-09-30 12:55:56.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/InputLimit.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,55 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * .
- *
- */
-package org.apache.http.client.cache;
-
-/**
- * @since 4.1
- */
-public class InputLimit {
-
- private final long value;
- private boolean reached;
-
- public InputLimit(long value) {
- super();
- this.value = value;
- this.reached = false;
- }
-
- public long getValue() {
- return this.value;
- }
-
- public void reached() {
- this.reached = true;
- }
-
- public boolean isReached() {
- return this.reached;
- }
-
-}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/Resource.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/Resource.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/Resource.java 2010-09-30 12:55:56.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/Resource.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,46 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * .
- *
- */
-package org.apache.http.client.cache;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Serializable;
-
-/**
- * Represents a disposable system resource.
- *
- * @since 4.1
- */
-public interface Resource extends Serializable {
-
- InputStream getInputStream() throws IOException;
-
- long length();
-
- void dispose();
-
-}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/ResourceFactory.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/ResourceFactory.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/client/cache/ResourceFactory.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/client/cache/ResourceFactory.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,43 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * .
- *
- */
-package org.apache.http.client.cache;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * Generates {@link Resource} instances.
- *
- * @since 4.1
- */
-public interface ResourceFactory {
-
- Resource generate(String requestId, InputStream instream, InputLimit limit) throws IOException;
-
- Resource copy(String requestId, Resource resource) throws IOException;
-
-}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java 2010-09-30 12:55:54.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java 2010-09-30 12:55:29.000000000 -0400
@@ -13,17 +13,11 @@
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
-import org.apache.http.client.cache.HttpCache;
-import org.apache.http.client.cache.HttpCacheEntry;
-import org.apache.http.client.cache.HttpCacheStorage;
-import org.apache.http.client.cache.HttpCacheUpdateCallback;
-import org.apache.http.client.cache.HttpCacheUpdateException;
-import org.apache.http.client.cache.Resource;
-import org.apache.http.client.cache.ResourceFactory;
+import org.apache.http.client.cache.CacheConfig;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.message.BasicHttpResponse;
-public class BasicHttpCache implements HttpCache {
+class BasicHttpCache implements HttpCache {
private final URIExtractor uriExtractor;
private final ResourceFactory resourceFactory;
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCacheStorage.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCacheStorage.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCacheStorage.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCacheStorage.java 2010-09-30 12:55:29.000000000 -0400
@@ -30,9 +30,7 @@
import java.util.LinkedHashMap;
import org.apache.http.annotation.ThreadSafe;
-import org.apache.http.client.cache.HttpCacheEntry;
-import org.apache.http.client.cache.HttpCacheStorage;
-import org.apache.http.client.cache.HttpCacheUpdateCallback;
+import org.apache.http.client.cache.CacheConfig;
/**
* Basic {@link HttpCacheStorage} implementation backed by an instance of {@link LinkedHashMap}.
@@ -42,11 +40,11 @@
* @since 4.1
*/
@ThreadSafe
-public class BasicHttpCacheStorage implements HttpCacheStorage {
+class BasicHttpCacheStorage implements HttpCacheStorage {
private final CacheMap entries;
- public BasicHttpCacheStorage(CacheConfig config) {
+ BasicHttpCacheStorage(CacheConfig config) {
super();
this.entries = new CacheMap(config.getMaxCacheEntries());
}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheConfig.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheConfig.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheConfig.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheConfig.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,121 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * .
- *
- */
-package org.apache.http.impl.client.cache;
-
-/**
- * Java Beans-style configuration for a
- * {@link org.apache.http.impl.client.cache.CachingHttpClient}.
- */
-public class CacheConfig {
-
- /** Default setting for the maximum object size that will be
- * cached, in bytes.
- */
- public final static int DEFAULT_MAX_OBJECT_SIZE_BYTES = 8192;
-
- /** Default setting for the maximum number of cache entries
- * that will be retained.
- */
- public final static int DEFAULT_MAX_CACHE_ENTRIES = 1000;
-
- /** Default setting for the number of retries on a failed
- * cache update
- */
- public final static int DEFAULT_MAX_UPDATE_RETRIES = 1;
-
- private int maxObjectSizeBytes = DEFAULT_MAX_OBJECT_SIZE_BYTES;
- private int maxCacheEntries = DEFAULT_MAX_CACHE_ENTRIES;
- private int maxUpdateRetries = DEFAULT_MAX_UPDATE_RETRIES;
-
- private boolean isSharedCache = true;
-
- /**
- * Returns the current maximum object size that will be cached.
- * @return size in bytes
- */
- public int getMaxObjectSizeBytes() {
- return maxObjectSizeBytes;
- }
-
- /**
- * Specifies the maximum object size that will be eligible for caching.
- * @param maxObjectSizeBytes size in bytes
- */
- public void setMaxObjectSizeBytes(int maxObjectSizeBytes) {
- this.maxObjectSizeBytes = maxObjectSizeBytes;
- }
-
- /**
- * Returns whether the cache will behave as a shared cache or not.
- * @return true for a shared cache, false for a non-shared (private)
- * cache
- */
- public boolean isSharedCache() {
- return isSharedCache;
- }
-
- /**
- * Sets whether the cache should behave as a shared cache or not.
- * @param isSharedCache true to behave as a shared cache, false to
- * behave as a non-shared (private) cache.
- */
- public void setSharedCache(boolean isSharedCache) {
- this.isSharedCache = isSharedCache;
- }
-
- /**
- * Returns the maximum number of cache entries the cache will retain.
- * @return int
- */
- public int getMaxCacheEntries() {
- return maxCacheEntries;
- }
-
- /**
- * Sets the maximum number of cache entries the cache will retain.
- * @param maxCacheEntries int
- */
- public void setMaxCacheEntries(int maxCacheEntries) {
- this.maxCacheEntries = maxCacheEntries;
- }
-
- /**
- * Returns the number of times to retry a cache update on failure
- * @return int
- */
- public int getMaxUpdateRetries(){
- return maxUpdateRetries;
- }
-
- /**
- * Sets the number of times to retry a cache update on failure
- * @param maxUpdateRetries int
- */
- public void setMaxUpdateRetries(int maxUpdateRetries){
- this.maxUpdateRetries = maxUpdateRetries;
- }
-}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntity.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntity.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntity.java 2010-09-30 12:55:54.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntity.java 2010-09-30 12:55:29.000000000 -0400
@@ -34,7 +34,6 @@
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.annotation.Immutable;
-import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.protocol.HTTP;
@Immutable
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java 2010-09-30 12:55:54.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java 2010-09-30 12:55:29.000000000 -0400
@@ -36,10 +36,6 @@
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.annotation.Immutable;
-import org.apache.http.client.cache.HeaderConstants;
-import org.apache.http.client.cache.HttpCacheEntry;
-import org.apache.http.client.cache.Resource;
-import org.apache.http.client.cache.ResourceFactory;
import org.apache.http.impl.cookie.DateParseException;
import org.apache.http.impl.cookie.DateUtils;
import org.apache.http.protocol.HTTP;
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheInvalidator.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheInvalidator.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheInvalidator.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheInvalidator.java 2010-09-30 12:55:29.000000000 -0400
@@ -36,10 +36,6 @@
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.annotation.ThreadSafe;
-import org.apache.http.client.cache.HeaderConstants;
-import org.apache.http.client.cache.HttpCache;
-import org.apache.http.client.cache.HttpCacheEntry;
-import org.apache.http.client.cache.HttpCacheStorage;
/**
* Given a particular HttpRequest, flush any cache entries that this request
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheMap.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheMap.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheMap.java 2010-09-30 12:55:54.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheMap.java 2010-09-30 12:55:29.000000000 -0400
@@ -29,7 +29,6 @@
import java.util.LinkedHashMap;
import java.util.Map;
-import org.apache.http.client.cache.HttpCacheEntry;
final class CacheMap extends LinkedHashMap {
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheValidityPolicy.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheValidityPolicy.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheValidityPolicy.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheValidityPolicy.java 2010-09-30 12:55:29.000000000 -0400
@@ -31,8 +31,6 @@
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.annotation.Immutable;
-import org.apache.http.client.cache.HeaderConstants;
-import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.impl.cookie.DateParseException;
import org.apache.http.impl.cookie.DateUtils;
import org.apache.http.protocol.HTTP;
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheableRequestPolicy.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheableRequestPolicy.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheableRequestPolicy.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheableRequestPolicy.java 2010-09-30 12:55:29.000000000 -0400
@@ -34,7 +34,6 @@
import org.apache.http.HttpVersion;
import org.apache.http.ProtocolVersion;
import org.apache.http.annotation.Immutable;
-import org.apache.http.client.cache.HeaderConstants;
/**
* Determines if an HttpRequest is allowed to be served from the cache.
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHttpResponseGenerator.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHttpResponseGenerator.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHttpResponseGenerator.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHttpResponseGenerator.java 2010-09-30 12:55:29.000000000 -0400
@@ -34,8 +34,6 @@
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.annotation.Immutable;
-import org.apache.http.client.cache.HeaderConstants;
-import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.protocol.HTTP;
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedResponseSuitabilityChecker.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedResponseSuitabilityChecker.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedResponseSuitabilityChecker.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedResponseSuitabilityChecker.java 2010-09-30 12:55:29.000000000 -0400
@@ -35,8 +35,7 @@
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.annotation.Immutable;
-import org.apache.http.client.cache.HeaderConstants;
-import org.apache.http.client.cache.HttpCacheEntry;
+import org.apache.http.client.cache.CacheConfig;
import org.apache.http.impl.cookie.DateParseException;
import org.apache.http.impl.cookie.DateUtils;
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java 2010-09-30 12:55:29.000000000 -0400
@@ -49,13 +49,10 @@
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.cache.CacheConfig;
import org.apache.http.client.cache.CacheResponseStatus;
-import org.apache.http.client.cache.HeaderConstants;
-import org.apache.http.client.cache.HttpCache;
-import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.cookie.DateParseException;
import org.apache.http.impl.cookie.DateUtils;
import org.apache.http.message.BasicHttpResponse;
@@ -67,7 +64,7 @@
* @since 4.1
*/
@ThreadSafe // So long as the responseCache implementation is threadsafe
-public class CachingHttpClient implements HttpClient {
+class CachingHttpClient implements HttpClient {
public static final String CACHE_RESPONSE_STATUS = "http.cache.response.status";
@@ -95,7 +92,7 @@
private final Log log = LogFactory.getLog(getClass());
- public CachingHttpClient(
+ CachingHttpClient(
HttpClient client,
HttpCache cache,
CacheConfig config) {
@@ -124,53 +121,7 @@
this.requestCompliance = new RequestProtocolCompliance();
}
- public CachingHttpClient() {
- this(new DefaultHttpClient(),
- new BasicHttpCache(),
- new CacheConfig());
- }
-
- public CachingHttpClient(CacheConfig config) {
- this(new DefaultHttpClient(),
- new BasicHttpCache(config),
- config);
- }
-
- public CachingHttpClient(HttpClient client) {
- this(client,
- new BasicHttpCache(),
- new CacheConfig());
- }
-
- public CachingHttpClient(HttpClient client, CacheConfig config) {
- this(client,
- new BasicHttpCache(config),
- config);
- }
-
- public CachingHttpClient(
- HttpCache cache) {
- this(new DefaultHttpClient(),
- cache,
- new CacheConfig());
- }
-
- public CachingHttpClient(
- HttpCache cache,
- CacheConfig config) {
- this(new DefaultHttpClient(),
- cache,
- config);
- }
-
- public CachingHttpClient(
- HttpClient client,
- HttpCache cache) {
- this(client,
- cache,
- new CacheConfig());
- }
-
+
CachingHttpClient(
HttpClient backend,
CacheValidityPolicy validityPolicy,
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CombinedEntity.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CombinedEntity.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CombinedEntity.java 2010-09-30 12:55:54.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CombinedEntity.java 2010-09-30 12:55:29.000000000 -0400
@@ -33,7 +33,6 @@
import java.io.SequenceInputStream;
import org.apache.http.annotation.NotThreadSafe;
-import org.apache.http.client.cache.Resource;
import org.apache.http.entity.AbstractHttpEntity;
@NotThreadSafe
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ConditionalRequestBuilder.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ConditionalRequestBuilder.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ConditionalRequestBuilder.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ConditionalRequestBuilder.java 2010-09-30 12:55:29.000000000 -0400
@@ -31,8 +31,6 @@
import org.apache.http.HttpRequest;
import org.apache.http.ProtocolException;
import org.apache.http.annotation.Immutable;
-import org.apache.http.client.cache.HeaderConstants;
-import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.impl.client.RequestWrapper;
/**
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/DefaultCachingHttpClient.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/DefaultCachingHttpClient.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/DefaultCachingHttpClient.java 1969-12-31 19:00:00.000000000 -0500
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/DefaultCachingHttpClient.java 2010-09-30 12:55:29.000000000 -0400
@@ -0,0 +1,27 @@
+package org.apache.http.impl.client.cache;
+
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.cache.CacheConfig;
+import org.apache.http.impl.client.DefaultHttpClient;
+
+public class DefaultCachingHttpClient extends CachingHttpClient {
+
+ public DefaultCachingHttpClient(HttpClient client, CacheConfig config) {
+ super(client,
+ new BasicHttpCache(config),
+ config);
+ }
+
+ public DefaultCachingHttpClient() {
+ this(new DefaultHttpClient(), new CacheConfig());
+ }
+
+ public DefaultCachingHttpClient(HttpClient client) {
+ this(client, new CacheConfig());
+ }
+
+ public DefaultCachingHttpClient(CacheConfig config) {
+ this(new DefaultHttpClient(), config);
+ }
+
+}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/DefaultHttpCacheEntrySerializer.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/DefaultHttpCacheEntrySerializer.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/DefaultHttpCacheEntrySerializer.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/DefaultHttpCacheEntrySerializer.java 2010-09-30 12:55:29.000000000 -0400
@@ -33,9 +33,6 @@
import java.io.OutputStream;
import org.apache.http.annotation.Immutable;
-import org.apache.http.client.cache.HttpCacheEntry;
-import org.apache.http.client.cache.HttpCacheEntrySerializationException;
-import org.apache.http.client.cache.HttpCacheEntrySerializer;
/**
* {@link HttpCacheEntrySerializer} implementation that uses the default (native)
@@ -46,7 +43,7 @@
* @since 4.1
*/
@Immutable
-public class DefaultHttpCacheEntrySerializer implements HttpCacheEntrySerializer {
+class DefaultHttpCacheEntrySerializer implements HttpCacheEntrySerializer {
public void writeTo(HttpCacheEntry cacheEntry, OutputStream os) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(os);
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/EhcacheCachingHttpClient.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/EhcacheCachingHttpClient.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/EhcacheCachingHttpClient.java 1969-12-31 19:00:00.000000000 -0500
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/EhcacheCachingHttpClient.java 2010-09-30 12:55:29.000000000 -0400
@@ -0,0 +1,30 @@
+package org.apache.http.impl.client.cache;
+
+import net.sf.ehcache.Ehcache;
+
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.cache.CacheConfig;
+import org.apache.http.impl.client.DefaultHttpClient;
+
+public class EhcacheCachingHttpClient extends CachingHttpClient {
+
+ public EhcacheCachingHttpClient(HttpClient client, Ehcache storage, CacheConfig config) {
+ super(client,
+ new BasicHttpCache(new HeapResourceFactory(),
+ new EhcacheHttpCacheStorage(storage, config),
+ config),
+ config);
+ }
+
+ public EhcacheCachingHttpClient(Ehcache storage, CacheConfig config) {
+ this(new DefaultHttpClient(), storage, config);
+ }
+
+ public EhcacheCachingHttpClient(Ehcache storage) {
+ this(new DefaultHttpClient(), storage, new CacheConfig());
+ }
+
+ public EhcacheCachingHttpClient(HttpClient client, Ehcache storage) {
+ this(client, storage, new CacheConfig());
+ }
+}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/EhcacheHttpCacheStorage.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/EhcacheHttpCacheStorage.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/EhcacheHttpCacheStorage.java 1969-12-31 19:00:00.000000000 -0500
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/EhcacheHttpCacheStorage.java 2010-09-30 12:55:29.000000000 -0400
@@ -0,0 +1,112 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.apache.http.client.cache.CacheConfig;
+
+import net.sf.ehcache.Ehcache;
+import net.sf.ehcache.Element;
+
+class EhcacheHttpCacheStorage implements HttpCacheStorage {
+
+ private final Ehcache cache;
+ private final HttpCacheEntrySerializer serializer;
+ private final int maxUpdateRetries;
+
+ public EhcacheHttpCacheStorage(Ehcache cache) {
+ this(cache, new CacheConfig(), new DefaultHttpCacheEntrySerializer());
+ }
+
+ public EhcacheHttpCacheStorage(Ehcache cache, CacheConfig config){
+ this(cache, config, new DefaultHttpCacheEntrySerializer());
+ }
+
+ public EhcacheHttpCacheStorage(Ehcache cache, CacheConfig config, HttpCacheEntrySerializer serializer){
+ this.cache = cache;
+ this.maxUpdateRetries = config.getMaxUpdateRetries();
+ this.serializer = serializer;
+ }
+
+
+ public synchronized void putEntry(String key, HttpCacheEntry entry) throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ serializer.writeTo(entry, bos);
+ cache.put(new Element(key, bos.toByteArray()));
+ }
+
+ public synchronized HttpCacheEntry getEntry(String key) throws IOException {
+ Element e = cache.get(key);
+ if(e == null){
+ return null;
+ }
+
+ byte[] data = (byte[])e.getValue();
+ return serializer.readFrom(new ByteArrayInputStream(data));
+ }
+
+ public synchronized void removeEntry(String key) {
+ cache.remove(key);
+ }
+
+ public synchronized void updateEntry(String key, HttpCacheUpdateCallback callback)
+ throws IOException, HttpCacheUpdateException {
+ int numRetries = 0;
+ do{
+ Element oldElement = cache.get(key);
+
+ HttpCacheEntry existingEntry = null;
+ if(oldElement != null){
+ byte[] data = (byte[])oldElement.getValue();
+ existingEntry = serializer.readFrom(new ByteArrayInputStream(data));
+ }
+
+ HttpCacheEntry updatedEntry = callback.update(existingEntry);
+
+ if (existingEntry == null) {
+ putEntry(key, updatedEntry);
+ return;
+ } else {
+ // Attempt to do a CAS replace, if we fail then retry
+ // While this operation should work fine within this instance, multiple instances
+ // could trample each others' data
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ serializer.writeTo(updatedEntry, bos);
+ Element newElement = new Element(key, bos.toByteArray());
+ if (cache.replace(oldElement, newElement)) {
+ return;
+ }else{
+ numRetries++;
+ }
+ }
+ }while(numRetries <= maxUpdateRetries);
+ throw new HttpCacheUpdateException("Failed to update");
+ }
+}
\ No newline at end of file
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResource.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResource.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResource.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResource.java 2010-09-30 12:55:29.000000000 -0400
@@ -32,7 +32,6 @@
import java.io.InputStream;
import org.apache.http.annotation.ThreadSafe;
-import org.apache.http.client.cache.Resource;
/**
* Cache resource backed by a file.
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResourceFactory.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResourceFactory.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResourceFactory.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/FileResourceFactory.java 2010-09-30 12:55:29.000000000 -0400
@@ -32,9 +32,6 @@
import java.io.InputStream;
import org.apache.http.annotation.Immutable;
-import org.apache.http.client.cache.InputLimit;
-import org.apache.http.client.cache.Resource;
-import org.apache.http.client.cache.ResourceFactory;
/**
* Generates {@link Resource} instances whose body is stored in a temporary file.
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeaderConstants.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeaderConstants.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeaderConstants.java 1969-12-31 19:00:00.000000000 -0500
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeaderConstants.java 2010-09-30 12:55:29.000000000 -0400
@@ -0,0 +1,74 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import org.apache.http.annotation.Immutable;
+
+/**
+ * @since 4.1
+ */
+@Immutable
+class HeaderConstants {
+
+ public static final String GET_METHOD = "GET";
+ public static final String HEAD_METHOD = "HEAD";
+ public static final String OPTIONS_METHOD = "OPTIONS";
+ public static final String PUT_METHOD = "PUT";
+ public static final String DELETE_METHOD = "DELETE";
+ 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";
+
+ public static final String PRAGMA = "Pragma";
+ public static final String MAX_FORWARDS = "Max-Forwards";
+ public static final String ETAG = "ETag";
+ public static final String EXPIRES = "Expires";
+ public static final String AGE = "Age";
+ public static final String VARY = "Vary";
+ public static final String ALLOW = "Allow";
+
+ public static final String CACHE_CONTROL = "Cache-Control";
+ public static final String CACHE_CONTROL_NO_STORE = "no-store";
+ public static final String CACHE_CONTROL_NO_CACHE = "no-cache";
+ public static final String CACHE_CONTROL_MAX_AGE = "max-age";
+ public static final String CACHE_CONTROL_MAX_STALE = "max-stale";
+ public static final String CACHE_CONTROL_MIN_FRESH = "min-fresh";
+ public static final String CACHE_CONTROL_MUST_REVALIDATE = "must-revalidate";
+ public static final String CACHE_CONTROL_PROXY_REVALIDATE = "proxy-revalidate";
+
+ public static final String WARNING = "Warning";
+ public static final String RANGE = "Range";
+ public static final String CONTENT_RANGE = "Content-Range";
+ public static final String WWW_AUTHENTICATE = "WWW-Authenticate";
+ public static final String PROXY_AUTHENTICATE = "Proxy-Authenticate";
+
+}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResource.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResource.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResource.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResource.java 2010-09-30 12:55:29.000000000 -0400
@@ -30,7 +30,6 @@
import java.io.InputStream;
import org.apache.http.annotation.Immutable;
-import org.apache.http.client.cache.Resource;
/**
* Cache resource backed by a byte array on the heap.
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResourceFactory.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResourceFactory.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResourceFactory.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HeapResourceFactory.java 2010-09-30 12:55:30.000000000 -0400
@@ -31,9 +31,6 @@
import java.io.InputStream;
import org.apache.http.annotation.Immutable;
-import org.apache.http.client.cache.InputLimit;
-import org.apache.http.client.cache.Resource;
-import org.apache.http.client.cache.ResourceFactory;
/**
* Generates {@link Resource} instances stored entirely in heap.
@@ -41,7 +38,7 @@
* @since 4.1
*/
@Immutable
-public class HeapResourceFactory implements ResourceFactory {
+class HeapResourceFactory implements ResourceFactory {
public Resource generate(
final String requestId,
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCache.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCache.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCache.java 1969-12-31 19:00:00.000000000 -0500
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCache.java 2010-09-30 12:55:30.000000000 -0400
@@ -0,0 +1,60 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import java.io.IOException;
+import java.util.Date;
+
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+
+/**
+ * @since 4.1
+ */
+interface HttpCache {
+
+ void flushCacheEntriesFor(HttpHost host, HttpRequest request)
+ throws IOException;
+
+ void flushInvalidatedCacheEntriesFor(HttpHost host, HttpRequest request)
+ throws IOException;
+
+ HttpCacheEntry getCacheEntry(HttpHost host, HttpRequest request)
+ throws IOException;
+
+ HttpResponse cacheAndReturnResponse(
+ HttpHost host, HttpRequest request, HttpResponse originResponse,
+ Date requestSent, Date responseReceived)
+ throws IOException;
+
+ HttpResponse updateCacheEntry(
+ HttpHost target, HttpRequest request, HttpCacheEntry stale, HttpResponse originResponse,
+ Date requestSent, Date responseReceived)
+ throws IOException;
+
+}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheEntry.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheEntry.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheEntry.java 1969-12-31 19:00:00.000000000 -0500
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheEntry.java 2010-09-30 12:55:30.000000000 -0400
@@ -0,0 +1,162 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.http.Header;
+import org.apache.http.HttpResponse;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.StatusLine;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.message.HeaderGroup;
+
+/**
+ * Structure used to store an {@link HttpResponse} in a cache. Some entries can optionally depend
+ * on system resources that may require explicit deallocation. In such a case {@link #getResource()}
+ * should return a non-null instance of {@link Resource} that must be deallocated by calling
+ * {@link Resource#dispose()} method when no longer used.
+ *
+ * @since 4.1
+ */
+@Immutable
+class HttpCacheEntry implements Serializable {
+
+ private static final long serialVersionUID = -6300496422359477413L;
+
+ private final Date requestDate;
+ private final Date responseDate;
+ private final StatusLine statusLine;
+ private final HeaderGroup responseHeaders;
+ private final Resource resource;
+ private final Set variantURIs;
+
+ /**
+ * Create a new {@link HttpCacheEntry}
+ *
+ * @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
+ * @param responseHeaders
+ * Header[] from original HTTP Response
+ */
+ public HttpCacheEntry(
+ final Date requestDate,
+ final Date responseDate,
+ final StatusLine statusLine,
+ final Header[] responseHeaders,
+ final Resource resource,
+ final Set variants) {
+ super();
+ if (requestDate == null) {
+ throw new IllegalArgumentException("Request date may not be null");
+ }
+ if (responseDate == null) {
+ throw new IllegalArgumentException("Response date may not be null");
+ }
+ if (statusLine == null) {
+ throw new IllegalArgumentException("Status line may not be null");
+ }
+ if (responseHeaders == null) {
+ throw new IllegalArgumentException("Response headers may not be null");
+ }
+ if (resource == null) {
+ throw new IllegalArgumentException("Resource may not be null");
+ }
+ this.requestDate = requestDate;
+ this.responseDate = responseDate;
+ this.statusLine = statusLine;
+ this.responseHeaders = new HeaderGroup();
+ this.responseHeaders.setHeaders(responseHeaders);
+ this.resource = resource;
+ this.variantURIs = variants != null ? new HashSet(variants) : new HashSet();
+ }
+
+ public StatusLine getStatusLine() {
+ return this.statusLine;
+ }
+
+ public ProtocolVersion getProtocolVersion() {
+ return this.statusLine.getProtocolVersion();
+ }
+
+ public String getReasonPhrase() {
+ return this.statusLine.getReasonPhrase();
+ }
+
+ public int getStatusCode() {
+ return this.statusLine.getStatusCode();
+ }
+
+ public Date getRequestDate() {
+ return requestDate;
+ }
+
+ public Date getResponseDate() {
+ return responseDate;
+ }
+
+ public Header[] getAllHeaders() {
+ return responseHeaders.getAllHeaders();
+ }
+
+ public Header getFirstHeader(String name) {
+ return responseHeaders.getFirstHeader(name);
+ }
+
+ public Header[] getHeaders(String name) {
+ return responseHeaders.getHeaders(name);
+ }
+
+ public boolean hasVariants() {
+ return getFirstHeader(HeaderConstants.VARY) != null;
+ }
+
+ public Set getVariantURIs() {
+ return Collections.unmodifiableSet(this.variantURIs);
+ }
+
+ public Resource getResource() {
+ return this.resource;
+ }
+
+ @Override
+ public String toString() {
+ return "[request date=" + this.requestDate + "; response date=" + this.responseDate
+ + "; statusLine=" + this.statusLine + "]";
+ }
+
+}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheEntrySerializationException.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheEntrySerializationException.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheEntrySerializationException.java 1969-12-31 19:00:00.000000000 -0500
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheEntrySerializationException.java 2010-09-30 12:55:30.000000000 -0400
@@ -0,0 +1,44 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import java.io.IOException;
+
+class HttpCacheEntrySerializationException extends IOException {
+
+ private static final long serialVersionUID = 9219188365878433519L;
+
+ public HttpCacheEntrySerializationException(final String message) {
+ super();
+ }
+
+ public HttpCacheEntrySerializationException(final String message, final Throwable cause) {
+ super(message);
+ initCause(cause);
+ }
+
+}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheEntrySerializer.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheEntrySerializer.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheEntrySerializer.java 1969-12-31 19:00:00.000000000 -0500
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheEntrySerializer.java 2010-09-30 12:55:30.000000000 -0400
@@ -0,0 +1,40 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+
+interface HttpCacheEntrySerializer {
+
+ public void writeTo(HttpCacheEntry entry, OutputStream os) throws IOException;
+
+ public HttpCacheEntry readFrom(InputStream is) throws IOException;
+
+}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheStorage.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheStorage.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheStorage.java 1969-12-31 19:00:00.000000000 -0500
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheStorage.java 2010-09-30 12:55:30.000000000 -0400
@@ -0,0 +1,46 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import java.io.IOException;
+
+
+/**
+ * @since 4.1
+ */
+interface HttpCacheStorage {
+
+ void putEntry(String key, HttpCacheEntry entry) throws IOException;
+
+ HttpCacheEntry getEntry(String key) throws IOException;
+
+ void removeEntry(String key) throws IOException;
+
+ void updateEntry(
+ String key, HttpCacheUpdateCallback callback) throws IOException, HttpCacheUpdateException;
+
+}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheUpdateCallback.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheUpdateCallback.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheUpdateCallback.java 1969-12-31 19:00:00.000000000 -0500
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheUpdateCallback.java 2010-09-30 12:55:30.000000000 -0400
@@ -0,0 +1,47 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import java.io.IOException;
+
+
+interface HttpCacheUpdateCallback {
+
+ /**
+ * Returns the new cache entry that should replace an existing one.
+ *
+ * @param existing
+ * the cache entry current in-place in the cache, possibly
+ * null if nonexistent
+ * @return CacheEntry the cache entry that should replace it, again,
+ * possible null
+ *
+ * @since 4.1
+ */
+ HttpCacheEntry update(HttpCacheEntry existing) throws IOException;
+
+}
\ No newline at end of file
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheUpdateException.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheUpdateException.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheUpdateException.java 1969-12-31 19:00:00.000000000 -0500
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCacheUpdateException.java 2010-09-30 12:55:30.000000000 -0400
@@ -0,0 +1,48 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+
+/**
+ * Signals that {@link HttpCacheStorage} encountered an error performing an update operation.
+ *
+ * @since 4.1
+ */
+class HttpCacheUpdateException extends Exception {
+
+ private static final long serialVersionUID = 823573584868632876L;
+
+ public HttpCacheUpdateException(String message) {
+ super(message);
+ }
+
+ public HttpCacheUpdateException(String message, Throwable cause) {
+ super(message);
+ initCause(cause);
+ }
+
+}
\ No newline at end of file
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/InputLimit.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/InputLimit.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/InputLimit.java 1969-12-31 19:00:00.000000000 -0500
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/InputLimit.java 2010-09-30 12:55:30.000000000 -0400
@@ -0,0 +1,55 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+/**
+ * @since 4.1
+ */
+class InputLimit {
+
+ private final long value;
+ private boolean reached;
+
+ public InputLimit(long value) {
+ super();
+ this.value = value;
+ this.reached = false;
+ }
+
+ public long getValue() {
+ return this.value;
+ }
+
+ public void reached() {
+ this.reached = true;
+ }
+
+ public boolean isReached() {
+ return this.reached;
+ }
+
+}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ManagedHttpCacheStorage.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ManagedHttpCacheStorage.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ManagedHttpCacheStorage.java 2010-09-30 12:55:55.000000000 -0400
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ManagedHttpCacheStorage.java 2010-09-30 12:55:30.000000000 -0400
@@ -33,10 +33,7 @@
import java.util.Set;
import org.apache.http.annotation.ThreadSafe;
-import org.apache.http.client.cache.HttpCacheEntry;
-import org.apache.http.client.cache.HttpCacheStorage;
-import org.apache.http.client.cache.HttpCacheUpdateCallback;
-import org.apache.http.client.cache.Resource;
+import org.apache.http.client.cache.CacheConfig;
/**
* {@link HttpCacheStorage} implementation capable of deallocating resources associated with
@@ -53,7 +50,7 @@
* @since 4.1
*/
@ThreadSafe
-public class ManagedHttpCacheStorage implements HttpCacheStorage {
+class ManagedHttpCacheStorage implements HttpCacheStorage {
private final CacheMap entries;
private final ReferenceQueue morque;
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/MemcachedCachingHttpClient.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/MemcachedCachingHttpClient.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/MemcachedCachingHttpClient.java 1969-12-31 19:00:00.000000000 -0500
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/MemcachedCachingHttpClient.java 2010-09-30 12:55:30.000000000 -0400
@@ -0,0 +1,30 @@
+package org.apache.http.impl.client.cache;
+
+import net.spy.memcached.MemcachedClientIF;
+
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.cache.CacheConfig;
+import org.apache.http.impl.client.DefaultHttpClient;
+
+public class MemcachedCachingHttpClient extends CachingHttpClient {
+
+ public MemcachedCachingHttpClient(HttpClient client, MemcachedClientIF storage, CacheConfig config) {
+ super(client,
+ new BasicHttpCache(new HeapResourceFactory(),
+ new MemcachedHttpCacheStorage(storage, config),
+ config),
+ config);
+ }
+
+ public MemcachedCachingHttpClient(MemcachedClientIF storage, CacheConfig config) {
+ this(new DefaultHttpClient(), storage, config);
+ }
+
+ public MemcachedCachingHttpClient(MemcachedClientIF storage) {
+ this(new DefaultHttpClient(), storage, new CacheConfig());
+ }
+
+ public MemcachedCachingHttpClient(HttpClient client, MemcachedClientIF storage) {
+ this(client, storage, new CacheConfig());
+ }
+}
diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/MemcachedHttpCacheStorage.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/MemcachedHttpCacheStorage.java
--- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/MemcachedHttpCacheStorage.java 1969-12-31 19:00:00.000000000 -0500
+++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/MemcachedHttpCacheStorage.java 2010-09-30 12:55:30.000000000 -0400
@@ -0,0 +1,117 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.http.impl.client.cache;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+
+import org.apache.http.client.cache.CacheConfig;
+
+import net.spy.memcached.CASResponse;
+import net.spy.memcached.CASValue;
+import net.spy.memcached.MemcachedClient;
+import net.spy.memcached.MemcachedClientIF;
+
+
+class MemcachedHttpCacheStorage implements HttpCacheStorage {
+
+ private MemcachedClientIF client;
+ private HttpCacheEntrySerializer serializer;
+ private final int maxUpdateRetries;
+
+ public MemcachedHttpCacheStorage(InetSocketAddress address) throws IOException {
+ this(new MemcachedClient(address));
+ }
+
+ public MemcachedHttpCacheStorage(MemcachedClientIF cache) {
+ this(cache, new CacheConfig(), new DefaultHttpCacheEntrySerializer());
+ }
+
+ public MemcachedHttpCacheStorage(MemcachedClientIF client, CacheConfig config) {
+ this(client, config, new DefaultHttpCacheEntrySerializer());
+ }
+
+ public MemcachedHttpCacheStorage(MemcachedClientIF client, CacheConfig config,
+ HttpCacheEntrySerializer serializer) {
+ this.client = client;
+ this.maxUpdateRetries = config.getMaxUpdateRetries();
+ this.serializer = serializer;
+ }
+
+ public void putEntry(String url, HttpCacheEntry entry) throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ serializer.writeTo(entry, bos);
+ client.set(url, 0, bos.toByteArray());
+ }
+
+ public HttpCacheEntry getEntry(String url) throws IOException {
+ byte[] data = (byte[]) client.get(url);
+ if (null == data)
+ return null;
+ InputStream bis = new ByteArrayInputStream(data);
+ return (HttpCacheEntry) serializer.readFrom(bis);
+ }
+
+ public void removeEntry(String url) throws IOException {
+ client.delete(url);
+ }
+
+ public void updateEntry(String url, HttpCacheUpdateCallback callback)
+ throws HttpCacheUpdateException, IOException {
+ int numRetries = 0;
+ do{
+
+ CASValue