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 v = client.gets(url); + byte[] oldBytes = (v != null) ? (byte[]) v.getValue() : null; + HttpCacheEntry existingEntry = null; + if (oldBytes != null) { + ByteArrayInputStream bis = new ByteArrayInputStream(oldBytes); + existingEntry = serializer.readFrom(bis); + } + HttpCacheEntry updatedEntry = callback.update(existingEntry); + + if (v == null) { + putEntry(url, updatedEntry); + return; + + } else { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + serializer.writeTo(updatedEntry, bos); + CASResponse casResult = client.cas(url, v.getCas(), bos.toByteArray()); + if (casResult != CASResponse.OK) { + numRetries++; + } + else return; + } + + } 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/RequestProtocolCompliance.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java --- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java 2010-09-30 12:55:54.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java 2010-09-30 12:55:30.000000000 -0400 @@ -39,7 +39,6 @@ import org.apache.http.ProtocolException; import org.apache.http.ProtocolVersion; import org.apache.http.annotation.Immutable; -import org.apache.http.client.cache.HeaderConstants; import org.apache.http.entity.AbstractHttpEntity; import org.apache.http.impl.client.RequestWrapper; import org.apache.http.message.BasicHeader; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolError.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolError.java --- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolError.java 2010-09-30 12:55:55.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolError.java 2010-09-30 12:55:30.000000000 -0400 @@ -29,7 +29,7 @@ /** * @since 4.1 */ -public enum RequestProtocolError { +enum RequestProtocolError { UNKNOWN, BODY_BUT_NO_LENGTH_ERROR, diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/Resource.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/Resource.java --- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/Resource.java 1969-12-31 19:00:00.000000000 -0500 +++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/Resource.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; +import java.io.InputStream; +import java.io.Serializable; + +/** + * Represents a disposable system resource. + * + * @since 4.1 + */ +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/impl/client/cache/ResourceFactory.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResourceFactory.java --- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResourceFactory.java 1969-12-31 19:00:00.000000000 -0500 +++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResourceFactory.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; +import java.io.InputStream; + + +/** + * Generates {@link Resource} instances. + * + * @since 4.1 + */ +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/ResourceReference.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResourceReference.java --- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResourceReference.java 2010-09-30 12:55:55.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResourceReference.java 2010-09-30 12:55:30.000000000 -0400 @@ -30,8 +30,6 @@ import java.lang.ref.ReferenceQueue; import org.apache.http.annotation.Immutable; -import org.apache.http.client.cache.HttpCacheEntry; -import org.apache.http.client.cache.Resource; @Immutable class ResourceReference extends PhantomReference { diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseCachingPolicy.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseCachingPolicy.java --- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseCachingPolicy.java 2010-09-30 12:55:55.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseCachingPolicy.java 2010-09-30 12:55:30.000000000 -0400 @@ -36,7 +36,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.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/ResponseProtocolCompliance.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseProtocolCompliance.java --- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseProtocolCompliance.java 2010-09-30 12:55:55.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseProtocolCompliance.java 2010-09-30 12:55:30.000000000 -0400 @@ -40,7 +40,6 @@ import org.apache.http.ProtocolVersion; import org.apache.http.annotation.Immutable; import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.cache.HeaderConstants; import org.apache.http.impl.client.RequestWrapper; import org.apache.http.impl.cookie.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/SizeLimitedResponseReader.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/SizeLimitedResponseReader.java --- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/SizeLimitedResponseReader.java 2010-09-30 12:55:55.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/SizeLimitedResponseReader.java 2010-09-30 12:55:30.000000000 -0400 @@ -33,9 +33,6 @@ import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; import org.apache.http.annotation.NotThreadSafe; -import org.apache.http.client.cache.InputLimit; -import org.apache.http.client.cache.Resource; -import org.apache.http.client.cache.ResourceFactory; import org.apache.http.message.BasicHttpResponse; /** diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/URIExtractor.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/URIExtractor.java --- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/URIExtractor.java 2010-09-30 12:55:55.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/URIExtractor.java 2010-09-30 12:55:30.000000000 -0400 @@ -42,8 +42,6 @@ import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.annotation.Immutable; -import org.apache.http.client.cache.HeaderConstants; -import org.apache.http.client.cache.HttpCacheEntry; import org.apache.http.protocol.HTTP; /** diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ehcache/EhcacheHttpCacheStorage.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ehcache/EhcacheHttpCacheStorage.java --- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ehcache/EhcacheHttpCacheStorage.java 2010-09-30 12:55:55.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ehcache/EhcacheHttpCacheStorage.java 1969-12-31 19:00:00.000000000 -0500 @@ -1,118 +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.ehcache; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import net.sf.ehcache.Ehcache; -import net.sf.ehcache.Element; - -import org.apache.http.client.cache.HttpCacheEntry; -import org.apache.http.client.cache.HttpCacheEntrySerializer; -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.impl.client.cache.CacheConfig; -import org.apache.http.impl.client.cache.DefaultHttpCacheEntrySerializer; - -public 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/memcached/MemcachedHttpCacheStorage.java httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java --- httpcomponents-client/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java 2010-09-30 12:55:55.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java 1969-12-31 19:00:00.000000000 -0500 @@ -1,118 +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.memcached; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.InetSocketAddress; - -import net.spy.memcached.CASResponse; -import net.spy.memcached.CASValue; -import net.spy.memcached.MemcachedClient; -import net.spy.memcached.MemcachedClientIF; - -import org.apache.http.client.cache.HttpCacheEntry; -import org.apache.http.client.cache.HttpCacheEntrySerializer; -import org.apache.http.client.cache.HttpCacheUpdateException; -import org.apache.http.client.cache.HttpCacheStorage; -import org.apache.http.client.cache.HttpCacheUpdateCallback; -import org.apache.http.impl.client.cache.CacheConfig; -import org.apache.http.impl.client.cache.DefaultHttpCacheEntrySerializer; - -public 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, - 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 v = client.gets(url); - byte[] oldBytes = (v != null) ? (byte[]) v.getValue() : null; - HttpCacheEntry existingEntry = null; - if (oldBytes != null) { - ByteArrayInputStream bis = new ByteArrayInputStream(oldBytes); - existingEntry = serializer.readFrom(bis); - } - HttpCacheEntry updatedEntry = callback.update(existingEntry); - - if (v == null) { - putEntry(url, updatedEntry); - return; - - } else { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - serializer.writeTo(updatedEntry, bos); - CASResponse casResult = client.cas(url, v.getCas(), bos.toByteArray()); - if (casResult != CASResponse.OK) { - numRetries++; - } - else return; - } - - } 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/test/java/org/apache/http/client/cache/TestHttpCacheEntry.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/client/cache/TestHttpCacheEntry.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/client/cache/TestHttpCacheEntry.java 2010-09-30 12:55:54.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/client/cache/TestHttpCacheEntry.java 1969-12-31 19:00:00.000000000 -0500 @@ -1,138 +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 static org.easymock.classextension.EasyMock.*; -import java.util.Date; - -import org.apache.http.Header; -import org.apache.http.HttpStatus; -import org.apache.http.HttpVersion; -import org.apache.http.StatusLine; -import org.apache.http.client.cache.HttpCacheEntry; -import org.apache.http.message.BasicHeader; -import org.apache.http.message.BasicStatusLine; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class TestHttpCacheEntry { - - private Date now; - private Date elevenSecondsAgo; - private Date nineSecondsAgo; - private Resource mockResource; - private StatusLine statusLine; - - @Before - public void setUp() { - now = new Date(); - elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L); - nineSecondsAgo = new Date(now.getTime() - 9 * 1000L); - statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, - HttpStatus.SC_OK, "OK"); - mockResource = createMock(Resource.class); - } - - private HttpCacheEntry makeEntry(Header[] headers) { - return new HttpCacheEntry(elevenSecondsAgo, nineSecondsAgo, - statusLine, headers, mockResource, null); - } - - @Test - public void testGetHeadersReturnsCorrectHeaders() { - Header[] headers = { new BasicHeader("foo", "fooValue"), - new BasicHeader("bar", "barValue1"), - new BasicHeader("bar", "barValue2") - }; - HttpCacheEntry entry = makeEntry(headers); - Assert.assertEquals(2, entry.getHeaders("bar").length); - } - - @Test - public void testGetFirstHeaderReturnsCorrectHeader() { - Header[] headers = { new BasicHeader("foo", "fooValue"), - new BasicHeader("bar", "barValue1"), - new BasicHeader("bar", "barValue2") - }; - HttpCacheEntry entry = makeEntry(headers); - Assert.assertEquals("barValue1", entry.getFirstHeader("bar").getValue()); - } - - @Test - public void testGetHeadersReturnsEmptyArrayIfNoneMatch() { - Header[] headers = { new BasicHeader("foo", "fooValue"), - new BasicHeader("bar", "barValue1"), - new BasicHeader("bar", "barValue2") - }; - HttpCacheEntry entry = makeEntry(headers); - - Assert.assertEquals(0, entry.getHeaders("baz").length); - } - - @Test - public void testGetFirstHeaderReturnsNullIfNoneMatch() { - Header[] headers = { new BasicHeader("foo", "fooValue"), - new BasicHeader("bar", "barValue1"), - new BasicHeader("bar", "barValue2") - }; - HttpCacheEntry entry = makeEntry(headers); - - Assert.assertEquals(null, entry.getFirstHeader("quux")); - } - - @Test - public void testCacheEntryWithNoVaryHeaderDoesNotHaveVariants() { - Header[] headers = new Header[0]; - HttpCacheEntry entry = makeEntry(headers); - Assert.assertFalse(entry.hasVariants()); - } - - @Test - public void testCacheEntryWithOneVaryHeaderHasVariants() { - Header[] headers = { new BasicHeader("Vary", "User-Agent") }; - HttpCacheEntry entry = makeEntry(headers); - Assert.assertTrue(entry.hasVariants()); - } - - @Test - public void testCacheEntryWithMultipleVaryHeadersHasVariants() { - Header[] headers = { new BasicHeader("Vary", "User-Agent"), - new BasicHeader("Vary", "Accept-Encoding") - }; - HttpCacheEntry entry = makeEntry(headers); - Assert.assertTrue(entry.hasVariants()); - } - - @Test - public void testCacheEntryWithVaryStarHasVariants(){ - Header[] headers = { new BasicHeader("Vary", "*") }; - HttpCacheEntry entry = makeEntry(headers); - Assert.assertTrue(entry.hasVariants()); - } - -} diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java 2010-09-30 12:55:52.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java 2010-09-30 12:55:32.000000000 -0400 @@ -7,7 +7,7 @@ import org.apache.http.HttpResponse; import org.apache.http.HttpVersion; import org.apache.http.client.HttpClient; -import org.apache.http.client.cache.HttpCache; +import org.apache.http.client.cache.CacheConfig; import org.apache.http.message.BasicHttpRequest; import org.apache.http.protocol.HttpContext; import org.easymock.IExpectationSetters; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java 2010-09-30 12:55:54.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/DoNotTestProtocolRequirements.java 2010-09-30 12:55:32.000000000 -0400 @@ -40,7 +40,7 @@ import org.apache.http.ProtocolVersion; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; -import org.apache.http.client.cache.HttpCache; +import org.apache.http.client.cache.CacheConfig; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.impl.cookie.DateUtils; import org.apache.http.message.BasicHttpRequest; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/HttpTestUtils.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/HttpTestUtils.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/HttpTestUtils.java 2010-09-30 12:55:54.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/HttpTestUtils.java 2010-09-30 12:55:32.000000000 -0400 @@ -40,7 +40,6 @@ import org.apache.http.HttpVersion; import org.apache.http.RequestLine; import org.apache.http.StatusLine; -import org.apache.http.client.cache.HttpCacheEntry; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.impl.cookie.DateUtils; import org.apache.http.message.BasicHeader; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/SimpleHttpCacheStorage.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/SimpleHttpCacheStorage.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/SimpleHttpCacheStorage.java 2010-09-30 12:55:54.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/SimpleHttpCacheStorage.java 2010-09-30 12:55:32.000000000 -0400 @@ -30,9 +30,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.http.client.cache.HttpCacheEntry; -import org.apache.http.client.cache.HttpCacheStorage; -import org.apache.http.client.cache.HttpCacheUpdateCallback; class SimpleHttpCacheStorage implements HttpCacheStorage { diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java 2010-09-30 12:55:51.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java 2010-09-30 12:55:32.000000000 -0400 @@ -45,8 +45,7 @@ import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.HttpVersion; -import org.apache.http.client.cache.HttpCacheEntry; -import org.apache.http.client.cache.Resource; +import org.apache.http.client.cache.CacheConfig; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.entity.ByteArrayEntity; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryUpdater.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryUpdater.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryUpdater.java 2010-09-30 12:55:51.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryUpdater.java 2010-09-30 12:55:32.000000000 -0400 @@ -31,7 +31,6 @@ import org.apache.http.HttpStatus; import org.apache.http.HttpVersion; import org.apache.http.ProtocolVersion; -import org.apache.http.client.cache.HttpCacheEntry; import org.apache.http.impl.cookie.DateUtils; import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicHttpResponse; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheInvalidator.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheInvalidator.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheInvalidator.java 2010-09-30 12:55:54.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheInvalidator.java 2010-09-30 12:55:32.000000000 -0400 @@ -34,8 +34,6 @@ import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.ProtocolVersion; -import org.apache.http.client.cache.HttpCacheEntry; -import org.apache.http.client.cache.HttpCacheStorage; import org.apache.http.message.BasicHttpEntityEnclosingRequest; import org.apache.http.message.BasicHttpRequest; import org.easymock.classextension.EasyMock; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheValidityPolicy.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheValidityPolicy.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheValidityPolicy.java 2010-09-30 12:55:53.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheValidityPolicy.java 2010-09-30 12:55:32.000000000 -0400 @@ -29,7 +29,6 @@ import java.util.Date; import org.apache.http.Header; -import org.apache.http.client.cache.HttpCacheEntry; import org.apache.http.impl.cookie.DateUtils; import org.apache.http.message.BasicHeader; import org.junit.Assert; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedHttpResponseGenerator.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedHttpResponseGenerator.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedHttpResponseGenerator.java 2010-09-30 12:55:54.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedHttpResponseGenerator.java 2010-09-30 12:55:32.000000000 -0400 @@ -30,7 +30,6 @@ import org.apache.http.Header; import org.apache.http.HttpResponse; -import org.apache.http.client.cache.HttpCacheEntry; import org.apache.http.impl.cookie.DateUtils; import org.apache.http.message.BasicHeader; import org.easymock.classextension.EasyMock; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedResponseSuitabilityChecker.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedResponseSuitabilityChecker.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedResponseSuitabilityChecker.java 2010-09-30 12:55:54.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedResponseSuitabilityChecker.java 2010-09-30 12:55:32.000000000 -0400 @@ -32,7 +32,7 @@ import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpVersion; -import org.apache.http.client.cache.HttpCacheEntry; +import org.apache.http.client.cache.CacheConfig; import org.apache.http.impl.cookie.DateUtils; import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicHttpRequest; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClient.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClient.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClient.java 2010-09-30 12:55:53.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClient.java 2010-09-30 12:55:32.000000000 -0400 @@ -44,8 +44,6 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.ResponseHandler; import org.apache.http.client.cache.CacheResponseStatus; -import org.apache.http.client.cache.HttpCache; -import org.apache.http.client.cache.HttpCacheEntry; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.conn.ClientConnectionManager; @@ -882,7 +880,7 @@ @Test public void testSetsModuleGeneratedResponseContextForCacheOptionsResponse() throws Exception { - impl = new CachingHttpClient(mockBackend); + impl = new DefaultCachingHttpClient(mockBackend); HttpRequest req = new BasicHttpRequest("OPTIONS","*",HttpVersion.HTTP_1_1); req.setHeader("Max-Forwards","0"); @@ -894,7 +892,7 @@ @Test public void testSetsModuleGeneratedResponseContextForFatallyNoncompliantRequest() throws Exception { - impl = new CachingHttpClient(mockBackend); + impl = new DefaultCachingHttpClient(mockBackend); HttpRequest req = new HttpGet("http://foo.example.com/"); req.setHeader("Range","bytes=0-50"); req.setHeader("If-Range","W/\"weak-etag\""); @@ -907,7 +905,7 @@ @Test public void testRecordsClientProtocolInViaHeaderIfRequestNotServableFromCache() throws Exception { - impl = new CachingHttpClient(mockBackend); + impl = new DefaultCachingHttpClient(mockBackend); HttpRequest req = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_0); req.setHeader("Cache-Control","no-cache"); HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NO_CONTENT, "No Content"); @@ -931,7 +929,7 @@ @Test public void testSetsCacheMissContextIfRequestNotServableFromCache() throws Exception { - impl = new CachingHttpClient(mockBackend); + impl = new DefaultCachingHttpClient(mockBackend); HttpRequest req = new HttpGet("http://foo.example.com/"); req.setHeader("Cache-Control","no-cache"); HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NO_CONTENT, "No Content"); @@ -950,7 +948,7 @@ @Test public void testSetsViaHeaderOnResponseIfRequestNotServableFromCache() throws Exception { - impl = new CachingHttpClient(mockBackend); + impl = new DefaultCachingHttpClient(mockBackend); HttpRequest req = new HttpGet("http://foo.example.com/"); req.setHeader("Cache-Control","no-cache"); HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NO_CONTENT, "No Content"); @@ -968,7 +966,7 @@ @Test public void testSetsViaHeaderOnResponseForCacheMiss() throws Exception { - impl = new CachingHttpClient(mockBackend); + impl = new DefaultCachingHttpClient(mockBackend); HttpRequest req1 = new HttpGet("http://foo.example.com/"); HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"); resp1.setEntity(HttpTestUtils.makeBody(128)); @@ -990,7 +988,7 @@ @Test public void testSetsCacheHitContextIfRequestServedFromCache() throws Exception { - impl = new CachingHttpClient(mockBackend); + impl = new DefaultCachingHttpClient(mockBackend); HttpRequest req1 = new HttpGet("http://foo.example.com/"); HttpRequest req2 = new HttpGet("http://foo.example.com/"); HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"); @@ -1015,7 +1013,7 @@ @Test public void testSetsViaHeaderOnResponseIfRequestServedFromCache() throws Exception { - impl = new CachingHttpClient(mockBackend); + impl = new DefaultCachingHttpClient(mockBackend); HttpRequest req1 = new HttpGet("http://foo.example.com/"); HttpRequest req2 = new HttpGet("http://foo.example.com/"); HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"); @@ -1042,7 +1040,7 @@ Date now = new Date(); Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L); - impl = new CachingHttpClient(mockBackend); + impl = new DefaultCachingHttpClient(mockBackend); HttpRequest req1 = new HttpGet("http://foo.example.com/"); HttpRequest req2 = new HttpGet("http://foo.example.com/"); @@ -1081,7 +1079,7 @@ Date now = new Date(); Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L); - impl = new CachingHttpClient(mockBackend); + impl = new DefaultCachingHttpClient(mockBackend); HttpRequest req1 = new HttpGet("http://foo.example.com/"); HttpRequest req2 = new HttpGet("http://foo.example.com/"); @@ -1120,7 +1118,7 @@ Date now = new Date(); Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L); - impl = new CachingHttpClient(mockBackend); + impl = new DefaultCachingHttpClient(mockBackend); HttpRequest req1 = new HttpGet("http://foo.example.com/"); HttpRequest req2 = new HttpGet("http://foo.example.com/"); @@ -1152,7 +1150,7 @@ Date now = new Date(); Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L); - impl = new CachingHttpClient(mockBackend); + impl = new DefaultCachingHttpClient(mockBackend); HttpRequest req1 = new HttpGet("http://foo.example.com/"); HttpRequest req2 = new HttpGet("http://foo.example.com/"); @@ -1184,7 +1182,7 @@ Date now = new Date(); Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L); - impl = new CachingHttpClient(mockBackend); + impl = new DefaultCachingHttpClient(mockBackend); HttpRequest req1 = new HttpGet("http://foo.example.com/"); HttpRequest req2 = new HttpGet("http://foo.example.com/"); diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCombinedEntity.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCombinedEntity.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCombinedEntity.java 2010-09-30 12:55:51.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCombinedEntity.java 2010-09-30 12:55:32.000000000 -0400 @@ -28,7 +28,6 @@ import java.io.ByteArrayInputStream; -import org.apache.http.client.cache.Resource; import org.apache.http.util.EntityUtils; import org.easymock.classextension.EasyMock; import org.junit.Assert; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestConditionalRequestBuilder.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestConditionalRequestBuilder.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestConditionalRequestBuilder.java 2010-09-30 12:55:51.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestConditionalRequestBuilder.java 2010-09-30 12:55:32.000000000 -0400 @@ -33,7 +33,6 @@ import org.apache.http.HttpRequest; import org.apache.http.HttpVersion; import org.apache.http.ProtocolException; -import org.apache.http.client.cache.HttpCacheEntry; import org.apache.http.impl.cookie.DateUtils; import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicHttpRequest; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestEhcacheHttpCacheStorage.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestEhcacheHttpCacheStorage.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestEhcacheHttpCacheStorage.java 1969-12-31 19:00:00.000000000 -0500 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestEhcacheHttpCacheStorage.java 2010-09-30 12:55:32.000000000 -0400 @@ -0,0 +1,241 @@ +/* + * ==================================================================== + * 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; + +import junit.framework.TestCase; +import net.sf.ehcache.Ehcache; +import net.sf.ehcache.Element; + +import org.apache.http.client.cache.CacheConfig; +import org.apache.http.impl.client.cache.EhcacheHttpCacheStorage; +import org.easymock.EasyMock; +import org.junit.Test; + +public class TestEhcacheHttpCacheStorage extends TestCase { + + private Ehcache mockCache; + private EhcacheHttpCacheStorage impl; + private HttpCacheEntrySerializer mockSerializer; + + public void setUp() { + mockCache = EasyMock.createMock(Ehcache.class); + CacheConfig config = new CacheConfig(); + config.setMaxUpdateRetries(1); + mockSerializer = EasyMock.createMock(HttpCacheEntrySerializer.class); + impl = new EhcacheHttpCacheStorage(mockCache, config, mockSerializer); + } + + private void replayMocks(){ + EasyMock.replay(mockCache); + EasyMock.replay(mockSerializer); + } + + private void verifyMocks(){ + EasyMock.verify(mockCache); + EasyMock.verify(mockSerializer); + } + + @Test + public void testCachePut() throws IOException { + final String key = "foo"; + final HttpCacheEntry value = HttpTestUtils.makeCacheEntry(); + + Element e = new Element(key, new byte[]{}); + + mockSerializer.writeTo(EasyMock.same(value), EasyMock.isA(OutputStream.class)); + mockCache.put(e); + + replayMocks(); + impl.putEntry(key, value); + verifyMocks(); + } + + @Test + public void testCacheGetNullEntry() throws IOException { + final String key = "foo"; + + EasyMock.expect(mockCache.get(key)).andReturn(null); + + replayMocks(); + HttpCacheEntry resultingEntry = impl.getEntry(key); + verifyMocks(); + + assertNull(resultingEntry); + } + + @Test + public void testCacheGet() throws IOException { + final String key = "foo"; + final HttpCacheEntry cachedValue = HttpTestUtils.makeCacheEntry(); + + Element element = new Element(key, new byte[]{}); + + EasyMock.expect(mockCache.get(key)) + .andReturn(element); + EasyMock.expect(mockSerializer.readFrom(EasyMock.isA(InputStream.class))) + .andReturn(cachedValue); + + replayMocks(); + HttpCacheEntry resultingEntry = impl.getEntry(key); + verifyMocks(); + + assertSame(cachedValue, resultingEntry); + } + + @Test + public void testCacheRemove() { + final String key = "foo"; + + EasyMock.expect(mockCache.remove(key)).andReturn(true); + + replayMocks(); + impl.removeEntry(key); + verifyMocks(); + } + + @Test + public void testCacheUpdateNullEntry() throws IOException, HttpCacheUpdateException { + final String key = "foo"; + final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); + + Element element = new Element(key, new byte[]{}); + + HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback(){ + public HttpCacheEntry update(HttpCacheEntry old){ + assertNull(old); + return updatedValue; + } + }; + + // get empty old entry + EasyMock.expect(mockCache.get(key)).andReturn(null); + + // put new entry + mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock.isA(OutputStream.class)); + mockCache.put(element); + + replayMocks(); + impl.updateEntry(key, callback); + verifyMocks(); + } + + @Test + public void testCacheUpdate() throws IOException, HttpCacheUpdateException { + final String key = "foo"; + final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry(); + final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); + + Element existingElement = new Element(key, new byte[]{}); + + HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback(){ + public HttpCacheEntry update(HttpCacheEntry old){ + assertEquals(existingValue, old); + return updatedValue; + } + }; + + // get existing old entry + EasyMock.expect(mockCache.get(key)).andReturn(existingElement); + EasyMock.expect(mockSerializer.readFrom(EasyMock.isA(InputStream.class))).andReturn(existingValue); + + // update + mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock.isA(OutputStream.class)); + EasyMock.expect(mockCache.replace(EasyMock.same(existingElement), EasyMock.isA(Element.class))).andReturn(true); + + replayMocks(); + impl.updateEntry(key, callback); + verifyMocks(); + } + + @Test + public void testSingleCacheUpdateRetry() throws IOException, HttpCacheUpdateException { + final String key = "foo"; + final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry(); + final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); + + Element existingElement = new Element(key, new byte[]{}); + + HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback(){ + public HttpCacheEntry update(HttpCacheEntry old){ + assertEquals(existingValue, old); + return updatedValue; + } + }; + + // get existing old entry, will happen twice + EasyMock.expect(mockCache.get(key)).andReturn(existingElement).times(2); + EasyMock.expect(mockSerializer.readFrom(EasyMock.isA(InputStream.class))).andReturn(existingValue).times(2); + + // update but fail + mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock.isA(OutputStream.class)); + EasyMock.expectLastCall().times(2); + EasyMock.expect(mockCache.replace(EasyMock.same(existingElement), EasyMock.isA(Element.class))).andReturn(false); + + // update again and succeed + EasyMock.expect(mockCache.replace(EasyMock.same(existingElement), EasyMock.isA(Element.class))).andReturn(true); + + replayMocks(); + impl.updateEntry(key, callback); + verifyMocks(); + } + + @Test + public void testCacheUpdateFail() throws IOException, HttpCacheUpdateException { + final String key = "foo"; + final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry(); + final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); + + Element existingElement = new Element(key, new byte[]{}); + + HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback(){ + public HttpCacheEntry update(HttpCacheEntry old){ + assertEquals(existingValue, old); + return updatedValue; + } + }; + + // get existing old entry + EasyMock.expect(mockCache.get(key)).andReturn(existingElement).times(2); + EasyMock.expect(mockSerializer.readFrom(EasyMock.isA(InputStream.class))).andReturn(existingValue).times(2); + + // update but fail + mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock.isA(OutputStream.class)); + EasyMock.expectLastCall().times(2); + EasyMock.expect(mockCache.replace(EasyMock.same(existingElement), EasyMock.isA(Element.class))).andReturn(false).times(2); + + replayMocks(); + try{ + impl.updateEntry(key, callback); + fail("Expected HttpCacheUpdateException"); + } catch (HttpCacheUpdateException e) { } + verifyMocks(); + } +} diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestEhcacheProtocolRequirements.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestEhcacheProtocolRequirements.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestEhcacheProtocolRequirements.java 1969-12-31 19:00:00.000000000 -0500 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestEhcacheProtocolRequirements.java 2010-09-30 12:55:32.000000000 -0400 @@ -0,0 +1,101 @@ +/* + * ==================================================================== + * 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 net.sf.ehcache.CacheManager; +import net.sf.ehcache.config.CacheConfiguration; +import net.sf.ehcache.config.Configuration; +import net.sf.ehcache.store.MemoryStoreEvictionPolicy; + +import org.apache.http.HttpHost; +import org.apache.http.HttpVersion; +import org.apache.http.client.HttpClient; +import org.apache.http.client.cache.CacheConfig; +import org.apache.http.impl.client.cache.BasicHttpCache; +import org.apache.http.impl.client.cache.CachingHttpClient; +import org.apache.http.impl.client.cache.EhcacheHttpCacheStorage; +import org.apache.http.impl.client.cache.HeapResourceFactory; +import org.apache.http.message.BasicHttpRequest; +import org.easymock.classextension.EasyMock; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; + +public class TestEhcacheProtocolRequirements extends TestProtocolRequirements{ + + private final String TEST_EHCACHE_NAME = "TestEhcacheProtocolRequirements-cache"; + + private static CacheManager CACHE_MANAGER; + + @BeforeClass + public static void setUpGlobal() { + Configuration config = new Configuration(); + config.addDefaultCache( + new CacheConfiguration("default", Integer.MAX_VALUE) + .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU) + .overflowToDisk(false)); + CACHE_MANAGER = CacheManager.create(config); + } + + @Override + @Before + public void setUp() { + host = new HttpHost("foo.example.com"); + + body = HttpTestUtils.makeBody(entityLength); + + request = new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1); + + originResponse = HttpTestUtils.make200Response(); + + params = new CacheConfig(); + params.setMaxObjectSizeBytes(MAX_BYTES); + + if (CACHE_MANAGER.cacheExists(TEST_EHCACHE_NAME)){ + CACHE_MANAGER.removeCache(TEST_EHCACHE_NAME); + } + CACHE_MANAGER.addCache(TEST_EHCACHE_NAME); + HttpCacheStorage storage = new EhcacheHttpCacheStorage(CACHE_MANAGER.getCache(TEST_EHCACHE_NAME)); + cache = new BasicHttpCache(new HeapResourceFactory(), storage, params); + mockBackend = EasyMock.createMock(HttpClient.class); + mockCache = EasyMock.createMock(HttpCache.class); + + impl = new CachingHttpClient(mockBackend, cache, params); + } + + @After + public void tearDown(){ + CACHE_MANAGER.removeCache(TEST_EHCACHE_NAME); + } + + @AfterClass + public static void tearDownGlobal(){ + CACHE_MANAGER.shutdown(); + } + +} diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntry.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntry.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntry.java 1969-12-31 19:00:00.000000000 -0500 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntry.java 2010-09-30 12:55:32.000000000 -0400 @@ -0,0 +1,139 @@ +/* + * ==================================================================== + * 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 static org.easymock.classextension.EasyMock.*; +import java.util.Date; + +import org.apache.http.Header; +import org.apache.http.HttpStatus; +import org.apache.http.HttpVersion; +import org.apache.http.StatusLine; +import org.apache.http.impl.client.cache.HttpCacheEntry; +import org.apache.http.impl.client.cache.Resource; +import org.apache.http.message.BasicHeader; +import org.apache.http.message.BasicStatusLine; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class TestHttpCacheEntry { + + private Date now; + private Date elevenSecondsAgo; + private Date nineSecondsAgo; + private Resource mockResource; + private StatusLine statusLine; + + @Before + public void setUp() { + now = new Date(); + elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L); + nineSecondsAgo = new Date(now.getTime() - 9 * 1000L); + statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, + HttpStatus.SC_OK, "OK"); + mockResource = createMock(Resource.class); + } + + private HttpCacheEntry makeEntry(Header[] headers) { + return new HttpCacheEntry(elevenSecondsAgo, nineSecondsAgo, + statusLine, headers, mockResource, null); + } + + @Test + public void testGetHeadersReturnsCorrectHeaders() { + Header[] headers = { new BasicHeader("foo", "fooValue"), + new BasicHeader("bar", "barValue1"), + new BasicHeader("bar", "barValue2") + }; + HttpCacheEntry entry = makeEntry(headers); + Assert.assertEquals(2, entry.getHeaders("bar").length); + } + + @Test + public void testGetFirstHeaderReturnsCorrectHeader() { + Header[] headers = { new BasicHeader("foo", "fooValue"), + new BasicHeader("bar", "barValue1"), + new BasicHeader("bar", "barValue2") + }; + HttpCacheEntry entry = makeEntry(headers); + Assert.assertEquals("barValue1", entry.getFirstHeader("bar").getValue()); + } + + @Test + public void testGetHeadersReturnsEmptyArrayIfNoneMatch() { + Header[] headers = { new BasicHeader("foo", "fooValue"), + new BasicHeader("bar", "barValue1"), + new BasicHeader("bar", "barValue2") + }; + HttpCacheEntry entry = makeEntry(headers); + + Assert.assertEquals(0, entry.getHeaders("baz").length); + } + + @Test + public void testGetFirstHeaderReturnsNullIfNoneMatch() { + Header[] headers = { new BasicHeader("foo", "fooValue"), + new BasicHeader("bar", "barValue1"), + new BasicHeader("bar", "barValue2") + }; + HttpCacheEntry entry = makeEntry(headers); + + Assert.assertEquals(null, entry.getFirstHeader("quux")); + } + + @Test + public void testCacheEntryWithNoVaryHeaderDoesNotHaveVariants() { + Header[] headers = new Header[0]; + HttpCacheEntry entry = makeEntry(headers); + Assert.assertFalse(entry.hasVariants()); + } + + @Test + public void testCacheEntryWithOneVaryHeaderHasVariants() { + Header[] headers = { new BasicHeader("Vary", "User-Agent") }; + HttpCacheEntry entry = makeEntry(headers); + Assert.assertTrue(entry.hasVariants()); + } + + @Test + public void testCacheEntryWithMultipleVaryHeadersHasVariants() { + Header[] headers = { new BasicHeader("Vary", "User-Agent"), + new BasicHeader("Vary", "Accept-Encoding") + }; + HttpCacheEntry entry = makeEntry(headers); + Assert.assertTrue(entry.hasVariants()); + } + + @Test + public void testCacheEntryWithVaryStarHasVariants(){ + Header[] headers = { new BasicHeader("Vary", "*") }; + HttpCacheEntry entry = makeEntry(headers); + Assert.assertTrue(entry.hasVariants()); + } + +} diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntrySerializers.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntrySerializers.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntrySerializers.java 2010-09-30 12:55:54.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntrySerializers.java 2010-09-30 12:55:32.000000000 -0400 @@ -17,9 +17,6 @@ import org.apache.http.Header; import org.apache.http.ProtocolVersion; import org.apache.http.StatusLine; -import org.apache.http.client.cache.HttpCacheEntry; -import org.apache.http.client.cache.HttpCacheEntrySerializer; -import org.apache.http.client.cache.Resource; import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicStatusLine; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestMemcachedHttpCacheStorage.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestMemcachedHttpCacheStorage.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestMemcachedHttpCacheStorage.java 1969-12-31 19:00:00.000000000 -0500 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestMemcachedHttpCacheStorage.java 2010-09-30 12:55:32.000000000 -0400 @@ -0,0 +1,263 @@ +/* + * ==================================================================== + * 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; +import java.io.UnsupportedEncodingException; + +import junit.framework.TestCase; +import net.spy.memcached.CASResponse; +import net.spy.memcached.CASValue; +import net.spy.memcached.MemcachedClientIF; + +import org.apache.http.client.cache.CacheConfig; +import org.apache.http.impl.client.cache.MemcachedHttpCacheStorage; +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; + +public class TestMemcachedHttpCacheStorage extends TestCase { + private MemcachedHttpCacheStorage impl; + private MemcachedClientIF mockMemcachedClient; + private HttpCacheEntrySerializer mockSerializer; + + @Before + public void setUp() throws Exception { + mockMemcachedClient = EasyMock.createMock(MemcachedClientIF.class); + mockSerializer = EasyMock.createMock(HttpCacheEntrySerializer.class); + CacheConfig config = new CacheConfig(); + config.setMaxUpdateRetries(1); + impl = new MemcachedHttpCacheStorage(mockMemcachedClient, config, + mockSerializer); + } + + private void replayMocks() { + EasyMock.replay(mockMemcachedClient); + EasyMock.replay(mockSerializer); + } + + private void verifyMocks() { + EasyMock.verify(mockMemcachedClient); + EasyMock.verify(mockSerializer); + } + + @Test + public void testCachePut() throws IOException, HttpCacheUpdateException { + final String url = "foo"; + final HttpCacheEntry value = HttpTestUtils.makeCacheEntry(); + mockSerializer.writeTo(EasyMock.isA(HttpCacheEntry.class), EasyMock + .isA(OutputStream.class)); + EasyMock.expect( + mockMemcachedClient.set(EasyMock.eq(url), EasyMock.eq(0), + EasyMock.aryEq(new byte[0]))).andReturn(null); + replayMocks(); + impl.putEntry(url, value); + verifyMocks(); + } + + @Test + public void testCacheGet() throws UnsupportedEncodingException, + IOException, HttpCacheUpdateException { + final String url = "foo"; + final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(); + EasyMock.expect(mockMemcachedClient.get(url)).andReturn(new byte[] {}); + EasyMock.expect( + mockSerializer.readFrom(EasyMock.isA(InputStream.class))) + .andReturn(cacheEntry); + replayMocks(); + HttpCacheEntry resultingEntry = impl.getEntry(url); + verifyMocks(); + assertSame(cacheEntry, resultingEntry); + } + + @Test + public void testCacheGetNullEntry() throws IOException { + final String url = "foo"; + + EasyMock.expect(mockMemcachedClient.get(url)).andReturn(null); + + replayMocks(); + HttpCacheEntry resultingEntry = impl.getEntry(url); + verifyMocks(); + + assertNull(resultingEntry); + } + + @Test + public void testCacheRemove() throws IOException, HttpCacheUpdateException { + final String url = "foo"; + EasyMock.expect(mockMemcachedClient.delete(url)).andReturn(null); + replayMocks(); + impl.removeEntry(url); + verifyMocks(); + } + + @Test + public void testCacheUpdateNullEntry() throws IOException, + HttpCacheUpdateException { + final String url = "foo"; + final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); + + HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback() { + public HttpCacheEntry update(HttpCacheEntry old) { + assertNull(old); + return updatedValue; + } + }; + + // get empty old entry + EasyMock.expect(mockMemcachedClient.gets(url)).andReturn(null); + // EasyMock.expect(mockCache.get(key)).andReturn(null); + + // put new entry + mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock + .isA(OutputStream.class)); + EasyMock.expect( + mockMemcachedClient.set(EasyMock.eq(url), EasyMock.eq(0), + EasyMock.aryEq(new byte[0]))).andReturn(null); + + replayMocks(); + impl.updateEntry(url, callback); + verifyMocks(); + } + + @Test + public void testCacheUpdate() throws IOException, HttpCacheUpdateException { + final String url = "foo"; + final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry(); + final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); + + CASValue v = new CASValue(1234, new byte[] {}); + + HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback() { + public HttpCacheEntry update(HttpCacheEntry old) { + assertEquals(existingValue, old); + return updatedValue; + } + }; + + // get existing old entry + EasyMock.expect(mockMemcachedClient.gets(url)).andReturn(v); + EasyMock.expect( + mockSerializer.readFrom(EasyMock.isA(InputStream.class))) + .andReturn(existingValue); + + // update + EasyMock.expect( + mockMemcachedClient.cas(EasyMock.eq(url), EasyMock.eq(v + .getCas()), EasyMock.aryEq(new byte[0]))).andReturn( + CASResponse.OK); + mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock + .isA(OutputStream.class)); + + replayMocks(); + impl.updateEntry(url, callback); + verifyMocks(); + } + + @Test + public void testSingleCacheUpdateRetry() throws IOException, + HttpCacheUpdateException { + final String url = "foo"; + final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry(); + final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); + CASValue v = new CASValue(1234, new byte[] {}); + + HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback() { + public HttpCacheEntry update(HttpCacheEntry old) { + assertEquals(existingValue, old); + return updatedValue; + } + }; + // get existing old entry, will happen twice + EasyMock.expect(mockMemcachedClient.gets(url)).andReturn(v).times(2); + EasyMock.expect( + mockSerializer.readFrom(EasyMock.isA(InputStream.class))) + .andReturn(existingValue).times(2); + + // update but fail + mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock + .isA(OutputStream.class)); + EasyMock.expectLastCall().times(2); + EasyMock.expect( + mockMemcachedClient.cas(EasyMock.eq(url), EasyMock.eq(v + .getCas()), EasyMock.aryEq(new byte[0]))).andReturn( + CASResponse.NOT_FOUND); + + // update again and succeed + EasyMock.expect( + mockMemcachedClient.cas(EasyMock.eq(url), EasyMock.eq(v + .getCas()), EasyMock.aryEq(new byte[0]))).andReturn( + CASResponse.OK); + + replayMocks(); + impl.updateEntry(url, callback); + verifyMocks(); + } + + @Test + public void testCacheUpdateFail() throws IOException, + HttpCacheUpdateException { + final String url = "foo"; + final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry(); + final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); + CASValue v = new CASValue(1234, new byte[] {}); + + HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback() { + public HttpCacheEntry update(HttpCacheEntry old) { + assertEquals(existingValue, old); + return updatedValue; + } + }; + + // get existing old entry + EasyMock.expect(mockMemcachedClient.gets(url)).andReturn(v).times(2); + EasyMock.expect( + mockSerializer.readFrom(EasyMock.isA(InputStream.class))) + .andReturn(existingValue).times(2); + + // update but fail + mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock + .isA(OutputStream.class)); + EasyMock.expectLastCall().times(2); + EasyMock.expect( + mockMemcachedClient.cas(EasyMock.eq(url), EasyMock.eq(v + .getCas()), EasyMock.aryEq(new byte[0]))).andReturn( + CASResponse.NOT_FOUND).times(2); + + replayMocks(); + try { + impl.updateEntry(url, callback); + fail("Expected HttpCacheUpdateException"); + } catch (HttpCacheUpdateException e) { + } + verifyMocks(); + } + +} diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java 2010-09-30 12:55:53.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java 2010-09-30 12:55:32.000000000 -0400 @@ -38,7 +38,7 @@ import org.apache.http.ProtocolVersion; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; -import org.apache.http.client.cache.HttpCache; +import org.apache.http.client.cache.CacheConfig; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.impl.cookie.DateUtils; import org.apache.http.message.BasicHttpEntityEnclosingRequest; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java 2010-09-30 12:55:51.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java 2010-09-30 12:55:32.000000000 -0400 @@ -44,7 +44,6 @@ import org.apache.http.HttpVersion; import org.apache.http.ProtocolVersion; import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.cache.HttpCacheEntry; import org.apache.http.entity.BasicHttpEntity; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.impl.client.RequestWrapper; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestURIExtractor.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestURIExtractor.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestURIExtractor.java 2010-09-30 12:55:54.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestURIExtractor.java 2010-09-30 12:55:32.000000000 -0400 @@ -30,7 +30,6 @@ import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpVersion; -import org.apache.http.client.cache.HttpCacheEntry; import org.apache.http.client.methods.HttpGet; import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicHttpRequest; diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheHttpCacheStorage.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheHttpCacheStorage.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheHttpCacheStorage.java 2010-09-30 12:55:54.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheHttpCacheStorage.java 1969-12-31 19:00:00.000000000 -0500 @@ -1,245 +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.ehcache; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import junit.framework.TestCase; -import net.sf.ehcache.Ehcache; -import net.sf.ehcache.Element; - -import org.apache.http.client.cache.HttpCacheEntry; -import org.apache.http.client.cache.HttpCacheEntrySerializer; -import org.apache.http.client.cache.HttpCacheUpdateCallback; -import org.apache.http.client.cache.HttpCacheUpdateException; -import org.apache.http.impl.client.cache.CacheConfig; -import org.apache.http.impl.client.cache.HttpTestUtils; -import org.easymock.EasyMock; -import org.junit.Test; - -public class TestEhcacheHttpCacheStorage extends TestCase { - - private Ehcache mockCache; - private EhcacheHttpCacheStorage impl; - private HttpCacheEntrySerializer mockSerializer; - - public void setUp() { - mockCache = EasyMock.createMock(Ehcache.class); - CacheConfig config = new CacheConfig(); - config.setMaxUpdateRetries(1); - mockSerializer = EasyMock.createMock(HttpCacheEntrySerializer.class); - impl = new EhcacheHttpCacheStorage(mockCache, config, mockSerializer); - } - - private void replayMocks(){ - EasyMock.replay(mockCache); - EasyMock.replay(mockSerializer); - } - - private void verifyMocks(){ - EasyMock.verify(mockCache); - EasyMock.verify(mockSerializer); - } - - @Test - public void testCachePut() throws IOException { - final String key = "foo"; - final HttpCacheEntry value = HttpTestUtils.makeCacheEntry(); - - Element e = new Element(key, new byte[]{}); - - mockSerializer.writeTo(EasyMock.same(value), EasyMock.isA(OutputStream.class)); - mockCache.put(e); - - replayMocks(); - impl.putEntry(key, value); - verifyMocks(); - } - - @Test - public void testCacheGetNullEntry() throws IOException { - final String key = "foo"; - - EasyMock.expect(mockCache.get(key)).andReturn(null); - - replayMocks(); - HttpCacheEntry resultingEntry = impl.getEntry(key); - verifyMocks(); - - assertNull(resultingEntry); - } - - @Test - public void testCacheGet() throws IOException { - final String key = "foo"; - final HttpCacheEntry cachedValue = HttpTestUtils.makeCacheEntry(); - - Element element = new Element(key, new byte[]{}); - - EasyMock.expect(mockCache.get(key)) - .andReturn(element); - EasyMock.expect(mockSerializer.readFrom(EasyMock.isA(InputStream.class))) - .andReturn(cachedValue); - - replayMocks(); - HttpCacheEntry resultingEntry = impl.getEntry(key); - verifyMocks(); - - assertSame(cachedValue, resultingEntry); - } - - @Test - public void testCacheRemove() { - final String key = "foo"; - - EasyMock.expect(mockCache.remove(key)).andReturn(true); - - replayMocks(); - impl.removeEntry(key); - verifyMocks(); - } - - @Test - public void testCacheUpdateNullEntry() throws IOException, HttpCacheUpdateException { - final String key = "foo"; - final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); - - Element element = new Element(key, new byte[]{}); - - HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback(){ - public HttpCacheEntry update(HttpCacheEntry old){ - assertNull(old); - return updatedValue; - } - }; - - // get empty old entry - EasyMock.expect(mockCache.get(key)).andReturn(null); - - // put new entry - mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock.isA(OutputStream.class)); - mockCache.put(element); - - replayMocks(); - impl.updateEntry(key, callback); - verifyMocks(); - } - - @Test - public void testCacheUpdate() throws IOException, HttpCacheUpdateException { - final String key = "foo"; - final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry(); - final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); - - Element existingElement = new Element(key, new byte[]{}); - - HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback(){ - public HttpCacheEntry update(HttpCacheEntry old){ - assertEquals(existingValue, old); - return updatedValue; - } - }; - - // get existing old entry - EasyMock.expect(mockCache.get(key)).andReturn(existingElement); - EasyMock.expect(mockSerializer.readFrom(EasyMock.isA(InputStream.class))).andReturn(existingValue); - - // update - mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock.isA(OutputStream.class)); - EasyMock.expect(mockCache.replace(EasyMock.same(existingElement), EasyMock.isA(Element.class))).andReturn(true); - - replayMocks(); - impl.updateEntry(key, callback); - verifyMocks(); - } - - @Test - public void testSingleCacheUpdateRetry() throws IOException, HttpCacheUpdateException { - final String key = "foo"; - final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry(); - final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); - - Element existingElement = new Element(key, new byte[]{}); - - HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback(){ - public HttpCacheEntry update(HttpCacheEntry old){ - assertEquals(existingValue, old); - return updatedValue; - } - }; - - // get existing old entry, will happen twice - EasyMock.expect(mockCache.get(key)).andReturn(existingElement).times(2); - EasyMock.expect(mockSerializer.readFrom(EasyMock.isA(InputStream.class))).andReturn(existingValue).times(2); - - // update but fail - mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock.isA(OutputStream.class)); - EasyMock.expectLastCall().times(2); - EasyMock.expect(mockCache.replace(EasyMock.same(existingElement), EasyMock.isA(Element.class))).andReturn(false); - - // update again and succeed - EasyMock.expect(mockCache.replace(EasyMock.same(existingElement), EasyMock.isA(Element.class))).andReturn(true); - - replayMocks(); - impl.updateEntry(key, callback); - verifyMocks(); - } - - @Test - public void testCacheUpdateFail() throws IOException, HttpCacheUpdateException { - final String key = "foo"; - final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry(); - final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); - - Element existingElement = new Element(key, new byte[]{}); - - HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback(){ - public HttpCacheEntry update(HttpCacheEntry old){ - assertEquals(existingValue, old); - return updatedValue; - } - }; - - // get existing old entry - EasyMock.expect(mockCache.get(key)).andReturn(existingElement).times(2); - EasyMock.expect(mockSerializer.readFrom(EasyMock.isA(InputStream.class))).andReturn(existingValue).times(2); - - // update but fail - mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock.isA(OutputStream.class)); - EasyMock.expectLastCall().times(2); - EasyMock.expect(mockCache.replace(EasyMock.same(existingElement), EasyMock.isA(Element.class))).andReturn(false).times(2); - - replayMocks(); - try{ - impl.updateEntry(key, callback); - fail("Expected HttpCacheUpdateException"); - } catch (HttpCacheUpdateException e) { } - verifyMocks(); - } -} diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheProtocolRequirements.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheProtocolRequirements.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheProtocolRequirements.java 2010-09-30 12:55:54.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheProtocolRequirements.java 1969-12-31 19:00:00.000000000 -0500 @@ -1,104 +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.ehcache; - -import net.sf.ehcache.CacheManager; -import net.sf.ehcache.config.CacheConfiguration; -import net.sf.ehcache.config.Configuration; -import net.sf.ehcache.store.MemoryStoreEvictionPolicy; - -import org.apache.http.HttpHost; -import org.apache.http.HttpVersion; -import org.apache.http.client.HttpClient; -import org.apache.http.client.cache.HttpCache; -import org.apache.http.client.cache.HttpCacheStorage; -import org.apache.http.impl.client.cache.BasicHttpCache; -import org.apache.http.impl.client.cache.CacheConfig; -import org.apache.http.impl.client.cache.CachingHttpClient; -import org.apache.http.impl.client.cache.HeapResourceFactory; -import org.apache.http.impl.client.cache.HttpTestUtils; -import org.apache.http.impl.client.cache.TestProtocolRequirements; -import org.apache.http.message.BasicHttpRequest; -import org.easymock.classextension.EasyMock; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; - -public class TestEhcacheProtocolRequirements extends TestProtocolRequirements{ - - private final String TEST_EHCACHE_NAME = "TestEhcacheProtocolRequirements-cache"; - - private static CacheManager CACHE_MANAGER; - - @BeforeClass - public static void setUpGlobal() { - Configuration config = new Configuration(); - config.addDefaultCache( - new CacheConfiguration("default", Integer.MAX_VALUE) - .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU) - .overflowToDisk(false)); - CACHE_MANAGER = CacheManager.create(config); - } - - @Override - @Before - public void setUp() { - host = new HttpHost("foo.example.com"); - - body = HttpTestUtils.makeBody(entityLength); - - request = new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1); - - originResponse = HttpTestUtils.make200Response(); - - params = new CacheConfig(); - params.setMaxObjectSizeBytes(MAX_BYTES); - - if (CACHE_MANAGER.cacheExists(TEST_EHCACHE_NAME)){ - CACHE_MANAGER.removeCache(TEST_EHCACHE_NAME); - } - CACHE_MANAGER.addCache(TEST_EHCACHE_NAME); - HttpCacheStorage storage = new EhcacheHttpCacheStorage(CACHE_MANAGER.getCache(TEST_EHCACHE_NAME)); - cache = new BasicHttpCache(new HeapResourceFactory(), storage, params); - mockBackend = EasyMock.createMock(HttpClient.class); - mockCache = EasyMock.createMock(HttpCache.class); - - impl = new CachingHttpClient(mockBackend, cache, params); - } - - @After - public void tearDown(){ - CACHE_MANAGER.removeCache(TEST_EHCACHE_NAME); - } - - @AfterClass - public static void tearDownGlobal(){ - CACHE_MANAGER.shutdown(); - } - -} diff -r -u -N -x .svn httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/TestMemcachedHttpCacheStorage.java httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/TestMemcachedHttpCacheStorage.java --- httpcomponents-client/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/TestMemcachedHttpCacheStorage.java 2010-09-30 12:55:52.000000000 -0400 +++ httpcomponents-client-modified/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/memcached/TestMemcachedHttpCacheStorage.java 1969-12-31 19:00:00.000000000 -0500 @@ -1,267 +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.memcached; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; - -import junit.framework.TestCase; -import net.spy.memcached.CASResponse; -import net.spy.memcached.CASValue; -import net.spy.memcached.MemcachedClientIF; - -import org.apache.http.client.cache.HttpCacheEntry; -import org.apache.http.client.cache.HttpCacheEntrySerializer; -import org.apache.http.client.cache.HttpCacheUpdateCallback; -import org.apache.http.client.cache.HttpCacheUpdateException; -import org.apache.http.impl.client.cache.CacheConfig; -import org.apache.http.impl.client.cache.HttpTestUtils; -import org.easymock.EasyMock; -import org.junit.Before; -import org.junit.Test; - -public class TestMemcachedHttpCacheStorage extends TestCase { - private MemcachedHttpCacheStorage impl; - private MemcachedClientIF mockMemcachedClient; - private HttpCacheEntrySerializer mockSerializer; - - @Before - public void setUp() throws Exception { - mockMemcachedClient = EasyMock.createMock(MemcachedClientIF.class); - mockSerializer = EasyMock.createMock(HttpCacheEntrySerializer.class); - CacheConfig config = new CacheConfig(); - config.setMaxUpdateRetries(1); - impl = new MemcachedHttpCacheStorage(mockMemcachedClient, config, - mockSerializer); - } - - private void replayMocks() { - EasyMock.replay(mockMemcachedClient); - EasyMock.replay(mockSerializer); - } - - private void verifyMocks() { - EasyMock.verify(mockMemcachedClient); - EasyMock.verify(mockSerializer); - } - - @Test - public void testCachePut() throws IOException, HttpCacheUpdateException { - final String url = "foo"; - final HttpCacheEntry value = HttpTestUtils.makeCacheEntry(); - mockSerializer.writeTo(EasyMock.isA(HttpCacheEntry.class), EasyMock - .isA(OutputStream.class)); - EasyMock.expect( - mockMemcachedClient.set(EasyMock.eq(url), EasyMock.eq(0), - EasyMock.aryEq(new byte[0]))).andReturn(null); - replayMocks(); - impl.putEntry(url, value); - verifyMocks(); - } - - @Test - public void testCacheGet() throws UnsupportedEncodingException, - IOException, HttpCacheUpdateException { - final String url = "foo"; - final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(); - EasyMock.expect(mockMemcachedClient.get(url)).andReturn(new byte[] {}); - EasyMock.expect( - mockSerializer.readFrom(EasyMock.isA(InputStream.class))) - .andReturn(cacheEntry); - replayMocks(); - HttpCacheEntry resultingEntry = impl.getEntry(url); - verifyMocks(); - assertSame(cacheEntry, resultingEntry); - } - - @Test - public void testCacheGetNullEntry() throws IOException { - final String url = "foo"; - - EasyMock.expect(mockMemcachedClient.get(url)).andReturn(null); - - replayMocks(); - HttpCacheEntry resultingEntry = impl.getEntry(url); - verifyMocks(); - - assertNull(resultingEntry); - } - - @Test - public void testCacheRemove() throws IOException, HttpCacheUpdateException { - final String url = "foo"; - EasyMock.expect(mockMemcachedClient.delete(url)).andReturn(null); - replayMocks(); - impl.removeEntry(url); - verifyMocks(); - } - - @Test - public void testCacheUpdateNullEntry() throws IOException, - HttpCacheUpdateException { - final String url = "foo"; - final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); - - HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback() { - public HttpCacheEntry update(HttpCacheEntry old) { - assertNull(old); - return updatedValue; - } - }; - - // get empty old entry - EasyMock.expect(mockMemcachedClient.gets(url)).andReturn(null); - // EasyMock.expect(mockCache.get(key)).andReturn(null); - - // put new entry - mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock - .isA(OutputStream.class)); - EasyMock.expect( - mockMemcachedClient.set(EasyMock.eq(url), EasyMock.eq(0), - EasyMock.aryEq(new byte[0]))).andReturn(null); - - replayMocks(); - impl.updateEntry(url, callback); - verifyMocks(); - } - - @Test - public void testCacheUpdate() throws IOException, HttpCacheUpdateException { - final String url = "foo"; - final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry(); - final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); - - CASValue v = new CASValue(1234, new byte[] {}); - - HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback() { - public HttpCacheEntry update(HttpCacheEntry old) { - assertEquals(existingValue, old); - return updatedValue; - } - }; - - // get existing old entry - EasyMock.expect(mockMemcachedClient.gets(url)).andReturn(v); - EasyMock.expect( - mockSerializer.readFrom(EasyMock.isA(InputStream.class))) - .andReturn(existingValue); - - // update - EasyMock.expect( - mockMemcachedClient.cas(EasyMock.eq(url), EasyMock.eq(v - .getCas()), EasyMock.aryEq(new byte[0]))).andReturn( - CASResponse.OK); - mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock - .isA(OutputStream.class)); - - replayMocks(); - impl.updateEntry(url, callback); - verifyMocks(); - } - - @Test - public void testSingleCacheUpdateRetry() throws IOException, - HttpCacheUpdateException { - final String url = "foo"; - final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry(); - final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); - CASValue v = new CASValue(1234, new byte[] {}); - - HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback() { - public HttpCacheEntry update(HttpCacheEntry old) { - assertEquals(existingValue, old); - return updatedValue; - } - }; - // get existing old entry, will happen twice - EasyMock.expect(mockMemcachedClient.gets(url)).andReturn(v).times(2); - EasyMock.expect( - mockSerializer.readFrom(EasyMock.isA(InputStream.class))) - .andReturn(existingValue).times(2); - - // update but fail - mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock - .isA(OutputStream.class)); - EasyMock.expectLastCall().times(2); - EasyMock.expect( - mockMemcachedClient.cas(EasyMock.eq(url), EasyMock.eq(v - .getCas()), EasyMock.aryEq(new byte[0]))).andReturn( - CASResponse.NOT_FOUND); - - // update again and succeed - EasyMock.expect( - mockMemcachedClient.cas(EasyMock.eq(url), EasyMock.eq(v - .getCas()), EasyMock.aryEq(new byte[0]))).andReturn( - CASResponse.OK); - - replayMocks(); - impl.updateEntry(url, callback); - verifyMocks(); - } - - @Test - public void testCacheUpdateFail() throws IOException, - HttpCacheUpdateException { - final String url = "foo"; - final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry(); - final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry(); - CASValue v = new CASValue(1234, new byte[] {}); - - HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback() { - public HttpCacheEntry update(HttpCacheEntry old) { - assertEquals(existingValue, old); - return updatedValue; - } - }; - - // get existing old entry - EasyMock.expect(mockMemcachedClient.gets(url)).andReturn(v).times(2); - EasyMock.expect( - mockSerializer.readFrom(EasyMock.isA(InputStream.class))) - .andReturn(existingValue).times(2); - - // update but fail - mockSerializer.writeTo(EasyMock.same(updatedValue), EasyMock - .isA(OutputStream.class)); - EasyMock.expectLastCall().times(2); - EasyMock.expect( - mockMemcachedClient.cas(EasyMock.eq(url), EasyMock.eq(v - .getCas()), EasyMock.aryEq(new byte[0]))).andReturn( - CASResponse.NOT_FOUND).times(2); - - replayMocks(); - try { - impl.updateEntry(url, callback); - fail("Expected HttpCacheUpdateException"); - } catch (HttpCacheUpdateException e) { - } - verifyMocks(); - } - -}