You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/05/01 11:11:11 UTC
svn commit: r1793308 [1/11] - in /httpcomponents/httpclient/trunk:
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/
httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/
httpclient5-cache/src/test/java/org/apache/...
Author: olegk
Date: Mon May 1 11:11:09 2017
New Revision: 1793308
URL: http://svn.apache.org/viewvc?rev=1793308&view=rev
Log:
Initial redesign of the classic request execution chain
Added:
httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientInterceptors.java (with props)
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/CancellableAware.java
- copied, changed from r1793305, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/CredentialsStore.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/StandardMethods.java (with props)
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/util/CredentialSupport.java (with props)
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java (with props)
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/NamedElementChain.java (with props)
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ChainElements.java
- copied, changed from r1793305, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/CredentialsStore.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ExecChainElement.java
- copied, changed from r1793305, httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/DummyBackend.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ExecRuntimeImpl.java (with props)
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RequestFailedException.java
- copied, changed from r1793305, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/CredentialsStore.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/sync/ExecChain.java
- copied, changed from r1793305, httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/DummyBackend.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/sync/ExecChainHandler.java (contents, props changed)
- copied, changed from r1793305, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ClientExecChain.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/sync/ExecRuntime.java
- copied, changed from r1793305, httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/DummyBackend.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestNamedElementChain.java (with props)
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestExecRuntimeImpl.java (with props)
Removed:
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ClientExecChain.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/EndpointHolder.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RoutedHttpRequest.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestEndpointHolder.java
Modified:
httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsynchronousValidationRequest.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsynchronousValidator.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingHttpClientBuilder.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/RequestProtocolCompliance.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseProtocolCompliance.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/DummyBackend.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidationRequest.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidator.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachedHttpResponseGenerator.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestExponentialBackingOffSchedulingStrategy.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpCacheJiraNumber1147.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolAllowedBehavior.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolRecommendations.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolRequirements.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRFC5861Compliance.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRequestProtocolCompliance.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java
httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/ehcache/TestEhcacheProtocolRequirements.java
httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientFormLogin.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AsyncRequestBuilder.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/CredentialsStore.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/IdleConnectionEvictor.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultRedirectStrategy.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/BackoffStrategyExec.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpResponse.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/DefaultHttpRequestRetryHandler.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/FutureRequestExecutionService.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClients.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpRequestFutureTask.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpRequestTaskCallable.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/InternalHttpClient.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MainClientExec.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalClientExec.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalHttpClient.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ProtocolExec.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RedirectExec.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ResponseEntityProxy.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RetryExec.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ServiceUnavailableRetryExec.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RedirectStrategy.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/sync/methods/HttpUriRequestBase.java
httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/sync/methods/RequestBuilder.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestClientRequestExecution.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestIdleConnectionEviction.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestStatefulConnManagement.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/protocol/TestDefaultRedirectStrategy.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestDefaultHttpRequestRetryHandler.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestInternalHttpClient.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestMainClientExec.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestMinimalClientExec.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestProtocolExec.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestRedirectExec.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestResponseEntityWrapper.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestRetryExec.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestServiceUnavailableRetryExec.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/sync/methods/TestRequestBuilder.java
httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestRequestBuilder.java
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsynchronousValidationRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsynchronousValidationRequest.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsynchronousValidationRequest.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsynchronousValidationRequest.java Mon May 1 11:11:09 2017
@@ -32,12 +32,12 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hc.client5.http.cache.HeaderConstants;
import org.apache.hc.client5.http.cache.HttpCacheEntry;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.sync.methods.HttpExecutionAware;
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
+import org.apache.hc.client5.http.sync.ExecChain;
+import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpResponse;
/**
@@ -47,9 +47,10 @@ import org.apache.hc.core5.http.HttpResp
public class AsynchronousValidationRequest implements Runnable {
private final AsynchronousValidator parent;
private final CachingExec cachingExec;
- private final RoutedHttpRequest request;
- private final HttpClientContext context;
- private final HttpExecutionAware execAware;
+ private final HttpHost target;
+ private final ClassicHttpRequest request;
+ private final ExecChain.Scope scope;
+ private final ExecChain chain;
private final HttpCacheEntry cacheEntry;
private final String identifier;
private final int consecutiveFailedAttempts;
@@ -58,27 +59,23 @@ public class AsynchronousValidationReque
/**
* Used internally by {@link AsynchronousValidator} to schedule a
- * revalidation.
- * @param request
- * @param context
- * @param cacheEntry
- * @param identifier
- * @param consecutiveFailedAttempts
*/
AsynchronousValidationRequest(
final AsynchronousValidator parent,
final CachingExec cachingExec,
- final RoutedHttpRequest request,
- final HttpClientContext context,
- final HttpExecutionAware execAware,
+ final HttpHost target,
+ final ClassicHttpRequest request,
+ final ExecChain.Scope scope,
+ final ExecChain chain,
final HttpCacheEntry cacheEntry,
final String identifier,
final int consecutiveFailedAttempts) {
this.parent = parent;
this.cachingExec = cachingExec;
+ this.target = target;
this.request = request;
- this.context = context;
- this.execAware = execAware;
+ this.scope = scope;
+ this.chain = chain;
this.cacheEntry = cacheEntry;
this.identifier = identifier;
this.consecutiveFailedAttempts = consecutiveFailedAttempts;
@@ -106,7 +103,7 @@ public class AsynchronousValidationReque
*/
private boolean revalidateCacheEntry() {
try {
- try (ClassicHttpResponse httpResponse = cachingExec.revalidateCacheEntry(request, context, execAware, cacheEntry)) {
+ try (ClassicHttpResponse httpResponse = cachingExec.revalidateCacheEntry(target, request, scope, chain, cacheEntry)) {
final int statusCode = httpResponse.getCode();
return isNotServerError(statusCode) && isNotStale(httpResponse);
}
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsynchronousValidator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsynchronousValidator.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsynchronousValidator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsynchronousValidator.java Mon May 1 11:11:09 2017
@@ -36,9 +36,9 @@ import java.util.concurrent.RejectedExec
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hc.client5.http.cache.HttpCacheEntry;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.sync.methods.HttpExecutionAware;
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
+import org.apache.hc.client5.http.sync.ExecChain;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.HttpHost;
/**
* Class used for asynchronous revalidations to be used when the "stale-
@@ -90,18 +90,19 @@ class AsynchronousValidator implements C
*/
public synchronized void revalidateCacheEntry(
final CachingExec cachingExec,
- final RoutedHttpRequest request,
- final HttpClientContext context,
- final HttpExecutionAware execAware,
+ final HttpHost target,
+ final ClassicHttpRequest request,
+ final ExecChain.Scope scope,
+ final ExecChain chain,
final HttpCacheEntry entry) {
// getVariantURI will fall back on getURI if no variants exist
- final String uri = cacheKeyGenerator.generateVariantURI(request.getTargetHost(), request, entry);
+ final String uri = cacheKeyGenerator.generateVariantURI(target, request, entry);
if (!queued.contains(uri)) {
final int consecutiveFailedAttempts = failureCache.getErrorCount(uri);
final AsynchronousValidationRequest revalidationRequest =
new AsynchronousValidationRequest(
- this, cachingExec, request, context, execAware, entry, uri, consecutiveFailedAttempts);
+ this, cachingExec, target, request, scope, chain, entry, uri, consecutiveFailedAttempts);
try {
schedulingStrategy.schedule(revalidationRequest);
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java Mon May 1 11:11:09 2017
@@ -43,13 +43,13 @@ import org.apache.hc.client5.http.cache.
import org.apache.hc.client5.http.cache.HttpCacheEntry;
import org.apache.hc.client5.http.cache.HttpCacheStorage;
import org.apache.hc.client5.http.cache.ResourceFactory;
-import org.apache.hc.client5.http.impl.sync.ClientExecChain;
import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.sync.methods.HttpExecutionAware;
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
+import org.apache.hc.client5.http.sync.ExecChain;
+import org.apache.hc.client5.http.sync.ExecChainHandler;
import org.apache.hc.client5.http.utils.DateUtils;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HeaderElement;
@@ -66,6 +66,7 @@ import org.apache.hc.core5.http.message.
import org.apache.hc.core5.http.message.MessageSupport;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.http.protocol.HttpCoreContext;
+import org.apache.hc.core5.net.URIAuthority;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.VersionInfo;
@@ -98,7 +99,7 @@ import org.apache.hc.core5.util.VersionI
* @since 4.3
*/
@Contract(threading = ThreadingBehavior.SAFE) // So long as the responseCache implementation is threadsafe
-public class CachingExec implements ClientExecChain {
+public class CachingExec implements ExecChainHandler {
private final static boolean SUPPORTS_RANGE_AND_CONTENT_RANGE_HEADERS = false;
@@ -109,7 +110,6 @@ public class CachingExec implements Clie
private final Map<ProtocolVersion, String> viaHeaders = new HashMap<>(4);
private final CacheConfig cacheConfig;
- private final ClientExecChain backend;
private final HttpCache responseCache;
private final CacheValidityPolicy validityPolicy;
private final CachedHttpResponseGenerator responseGenerator;
@@ -125,22 +125,18 @@ public class CachingExec implements Clie
private final Log log = LogFactory.getLog(getClass());
public CachingExec(
- final ClientExecChain backend,
final HttpCache cache,
final CacheConfig config) {
- this(backend, cache, config, null);
+ this(cache, config, null);
}
public CachingExec(
- final ClientExecChain backend,
final HttpCache cache,
final CacheConfig config,
final AsynchronousValidator asynchRevalidator) {
super();
- Args.notNull(backend, "HTTP backend");
Args.notNull(cache, "HttpCache");
this.cacheConfig = config != null ? config : CacheConfig.DEFAULT;
- this.backend = backend;
this.responseCache = cache;
this.validityPolicy = new CacheValidityPolicy();
this.responseGenerator = new CachedHttpResponseGenerator(this.validityPolicy);
@@ -156,19 +152,17 @@ public class CachingExec implements Clie
}
public CachingExec(
- final ClientExecChain backend,
final ResourceFactory resourceFactory,
final HttpCacheStorage storage,
final CacheConfig config) {
- this(backend, new BasicHttpCache(resourceFactory, storage, config), config);
+ this(new BasicHttpCache(resourceFactory, storage, config), config);
}
- public CachingExec(final ClientExecChain backend) {
- this(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
+ public CachingExec() {
+ this(new BasicHttpCache(), CacheConfig.DEFAULT);
}
CachingExec(
- final ClientExecChain backend,
final HttpCache responseCache,
final CacheValidityPolicy validityPolicy,
final ResponseCachingPolicy responseCachingPolicy,
@@ -181,7 +175,6 @@ public class CachingExec implements Clie
final CacheConfig config,
final AsynchronousValidator asynchRevalidator) {
this.cacheConfig = config != null ? config : CacheConfig.DEFAULT;
- this.backend = backend;
this.responseCache = responseCache;
this.validityPolicy = validityPolicy;
this.responseCachingPolicy = responseCachingPolicy;
@@ -221,24 +214,21 @@ public class CachingExec implements Clie
return cacheUpdates.get();
}
- public ClassicHttpResponse execute(final RoutedHttpRequest request) throws IOException, HttpException {
- return execute(request, HttpClientContext.create(), null);
- }
-
- public ClassicHttpResponse execute(
- final RoutedHttpRequest request,
- final HttpClientContext context) throws IOException, HttpException {
- return execute(request, context, null);
- }
-
@Override
public ClassicHttpResponse execute(
- final RoutedHttpRequest request,
- final HttpClientContext context,
- final HttpExecutionAware execAware) throws IOException, HttpException {
-
- final HttpHost target = request.getTargetHost();
- final String via = generateViaHeader(request.getOriginal());
+ final ClassicHttpRequest request,
+ final ExecChain.Scope scope,
+ final ExecChain chain) throws IOException, HttpException {
+ Args.notNull(request, "HTTP request");
+ Args.notNull(scope, "Scope");
+
+ final HttpRoute route = scope.route;
+ final HttpClientContext context = scope.clientContext;
+
+ final URIAuthority authority = request.getAuthority();
+ final String scheme = request.getScheme();
+ final HttpHost target = authority != null ? new HttpHost(authority, scheme) : route.getTargetHost();;
+ final String via = generateViaHeader(request);
// default response context
setResponseStatus(context, CacheResponseStatus.CACHE_MISS);
@@ -260,24 +250,26 @@ public class CachingExec implements Clie
if (!cacheableRequestPolicy.isServableFromCache(request)) {
log.debug("Request is not servable from cache");
- return callBackend(request, context, execAware);
+ return callBackend(target, request, scope, chain);
}
final HttpCacheEntry entry = satisfyFromCache(target, request);
if (entry == null) {
log.debug("Cache miss");
- return handleCacheMiss(request, context, execAware);
+ return handleCacheMiss(target, request, scope, chain);
} else {
- return handleCacheHit(request, context, execAware, entry);
+ return handleCacheHit(target, request, scope, chain, entry);
}
}
private ClassicHttpResponse handleCacheHit(
- final RoutedHttpRequest request,
- final HttpClientContext context,
- final HttpExecutionAware execAware,
+ final HttpHost target,
+ final ClassicHttpRequest request,
+ final ExecChain.Scope scope,
+ final ExecChain chain,
final HttpCacheEntry entry) throws IOException, HttpException {
- final HttpHost target = request.getTargetHost();
+ final HttpRoute route = scope.route;
+ final HttpClientContext context = scope.clientContext;
recordCacheHit(target, request);
ClassicHttpResponse out;
final Date now = getCurrentDate();
@@ -290,12 +282,11 @@ public class CachingExec implements Clie
} else if (!(entry.getStatus() == HttpStatus.SC_NOT_MODIFIED
&& !suitabilityChecker.isConditional(request))) {
log.debug("Revalidating cache entry");
- return revalidateCacheEntry(request, context, execAware, entry, now);
+ return revalidateCacheEntry(target, request, scope, chain, entry, now);
} else {
log.debug("Cache entry not usable; calling backend");
- return callBackend(request, context, execAware);
+ return callBackend(target, request, scope, chain);
}
- final HttpRoute route = request.getRoute();
context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
context.setAttribute(HttpCoreContext.HTTP_RESPONSE, out);
@@ -303,32 +294,34 @@ public class CachingExec implements Clie
}
private ClassicHttpResponse revalidateCacheEntry(
- final RoutedHttpRequest request,
- final HttpClientContext context,
- final HttpExecutionAware execAware,
+ final HttpHost target,
+ final ClassicHttpRequest request,
+ final ExecChain.Scope scope,
+ final ExecChain chain,
final HttpCacheEntry entry,
final Date now) throws HttpException {
+ final HttpClientContext context = scope.clientContext;
try {
if (asynchRevalidator != null
&& !staleResponseNotAllowed(request, entry, now)
&& validityPolicy.mayReturnStaleWhileRevalidating(entry, now)) {
log.trace("Serving stale with asynchronous revalidation");
final ClassicHttpResponse resp = generateCachedResponse(request, context, entry, now);
- asynchRevalidator.revalidateCacheEntry(this, request, context, execAware, entry);
+ asynchRevalidator.revalidateCacheEntry(this, target, request, scope, chain, entry);
return resp;
}
- return revalidateCacheEntry(request, context, execAware, entry);
+ return revalidateCacheEntry(target, request, scope, chain, entry);
} catch (final IOException ioex) {
return handleRevalidationFailure(request, context, entry, now);
}
}
private ClassicHttpResponse handleCacheMiss(
- final RoutedHttpRequest request,
- final HttpClientContext context,
- final HttpExecutionAware execAware) throws IOException, HttpException {
- final HttpHost target = request.getTargetHost();
+ final HttpHost target,
+ final ClassicHttpRequest request,
+ final ExecChain.Scope scope,
+ final ExecChain chain) throws IOException, HttpException {
recordCacheMiss(target, request);
if (!mayCallBackend(request)) {
@@ -337,14 +330,14 @@ public class CachingExec implements Clie
final Map<String, Variant> variants = getExistingCacheVariants(target, request);
if (variants != null && !variants.isEmpty()) {
- return negotiateResponseFromVariants(request, context, execAware, variants);
+ return negotiateResponseFromVariants(target, request, scope, chain, variants);
}
- return callBackend(request, context, execAware);
+ return callBackend(target, request, scope, chain);
}
private HttpCacheEntry satisfyFromCache(
- final HttpHost target, final RoutedHttpRequest request) {
+ final HttpHost target, final ClassicHttpRequest request) {
HttpCacheEntry entry = null;
try {
entry = responseCache.getCacheEntry(target, request);
@@ -355,7 +348,7 @@ public class CachingExec implements Clie
}
private ClassicHttpResponse getFatallyNoncompliantResponse(
- final RoutedHttpRequest request,
+ final ClassicHttpRequest request,
final HttpContext context) {
ClassicHttpResponse fatalErrorResponse = null;
final List<RequestProtocolError> fatalError = requestCompliance.requestIsFatallyNonCompliant(request);
@@ -369,7 +362,7 @@ public class CachingExec implements Clie
private Map<String, Variant> getExistingCacheVariants(
final HttpHost target,
- final RoutedHttpRequest request) {
+ final ClassicHttpRequest request) {
Map<String,Variant> variants = null;
try {
variants = responseCache.getVariantCacheEntriesWithEtags(target, request);
@@ -379,14 +372,14 @@ public class CachingExec implements Clie
return variants;
}
- private void recordCacheMiss(final HttpHost target, final RoutedHttpRequest request) {
+ private void recordCacheMiss(final HttpHost target, final ClassicHttpRequest request) {
cacheMisses.getAndIncrement();
if (log.isTraceEnabled()) {
log.trace("Cache miss [host: " + target + "; uri: " + request.getRequestUri() + "]");
}
}
- private void recordCacheHit(final HttpHost target, final RoutedHttpRequest request) {
+ private void recordCacheHit(final HttpHost target, final ClassicHttpRequest request) {
cacheHits.getAndIncrement();
if (log.isTraceEnabled()) {
log.trace("Cache hit [host: " + target + "; uri: " + request.getRequestUri() + "]");
@@ -400,7 +393,7 @@ public class CachingExec implements Clie
private void flushEntriesInvalidatedByRequest(
final HttpHost target,
- final RoutedHttpRequest request) {
+ final ClassicHttpRequest request) {
try {
responseCache.flushInvalidatedCacheEntriesFor(target, request);
} catch (final IOException ioe) {
@@ -408,8 +401,11 @@ public class CachingExec implements Clie
}
}
- private ClassicHttpResponse generateCachedResponse(final RoutedHttpRequest request,
- final HttpContext context, final HttpCacheEntry entry, final Date now) {
+ private ClassicHttpResponse generateCachedResponse(
+ final ClassicHttpRequest request,
+ final HttpContext context,
+ final HttpCacheEntry entry,
+ final Date now) {
final ClassicHttpResponse cachedResponse;
if (request.containsHeader(HeaderConstants.IF_NONE_MATCH)
|| request.containsHeader(HeaderConstants.IF_MODIFIED_SINCE)) {
@@ -425,7 +421,7 @@ public class CachingExec implements Clie
}
private ClassicHttpResponse handleRevalidationFailure(
- final RoutedHttpRequest request,
+ final ClassicHttpRequest request,
final HttpContext context,
final HttpCacheEntry entry,
final Date now) {
@@ -443,7 +439,7 @@ public class CachingExec implements Clie
}
private ClassicHttpResponse unvalidatedCacheHit(
- final RoutedHttpRequest request,
+ final ClassicHttpRequest request,
final HttpContext context,
final HttpCacheEntry entry) {
final ClassicHttpResponse cachedResponse = responseGenerator.generateResponse(request, entry);
@@ -453,7 +449,7 @@ public class CachingExec implements Clie
}
private boolean staleResponseNotAllowed(
- final RoutedHttpRequest request,
+ final ClassicHttpRequest request,
final HttpCacheEntry entry,
final Date now) {
return validityPolicy.mustRevalidate(entry)
@@ -461,7 +457,7 @@ public class CachingExec implements Clie
|| explicitFreshnessRequest(request, entry, now);
}
- private boolean mayCallBackend(final RoutedHttpRequest request) {
+ private boolean mayCallBackend(final ClassicHttpRequest request) {
final Iterator<HeaderElement> it = MessageSupport.iterate(request, HeaderConstants.CACHE_CONTROL);
while (it.hasNext()) {
final HeaderElement elt = it.next();
@@ -474,7 +470,7 @@ public class CachingExec implements Clie
}
private boolean explicitFreshnessRequest(
- final RoutedHttpRequest request,
+ final ClassicHttpRequest request,
final HttpCacheEntry entry,
final Date now) {
final Iterator<HeaderElement> it = MessageSupport.iterate(request, HeaderConstants.CACHE_CONTROL);
@@ -501,8 +497,11 @@ public class CachingExec implements Clie
private String generateViaHeader(final HttpMessage msg) {
- final ProtocolVersion pv = msg.getVersion() != null ? msg.getVersion() : HttpVersion.DEFAULT;
- final String existingEntry = viaHeaders.get(pv);
+ if (msg.getVersion() == null) {
+ msg.setVersion(HttpVersion.DEFAULT);
+ }
+ final ProtocolVersion pv = msg.getVersion();
+ final String existingEntry = viaHeaders.get(msg.getVersion());
if (existingEntry != null) {
return existingEntry;
}
@@ -562,18 +561,18 @@ public class CachingExec implements Clie
}
ClassicHttpResponse callBackend(
- final RoutedHttpRequest request,
- final HttpClientContext context,
- final HttpExecutionAware execAware) throws IOException, HttpException {
+ final HttpHost target,
+ final ClassicHttpRequest request,
+ final ExecChain.Scope scope,
+ final ExecChain chain) throws IOException, HttpException {
final Date requestDate = getCurrentDate();
log.trace("Calling the backend");
- final ClassicHttpResponse backendResponse = backend.execute(request, context, execAware);
+ final ClassicHttpResponse backendResponse = chain.proceed(request, scope);
try {
backendResponse.addHeader("Via", generateViaHeader(backendResponse));
- return handleBackendResponse(request, context, requestDate, getCurrentDate(),
- backendResponse);
+ return handleBackendResponse(target, request, scope, requestDate, getCurrentDate(), backendResponse);
} catch (final IOException | RuntimeException ex) {
backendResponse.close();
throw ex;
@@ -602,23 +601,23 @@ public class CachingExec implements Clie
}
ClassicHttpResponse negotiateResponseFromVariants(
- final RoutedHttpRequest request,
- final HttpClientContext context,
- final HttpExecutionAware execAware,
+ final HttpHost target,
+ final ClassicHttpRequest request,
+ final ExecChain.Scope scope,
+ final ExecChain chain,
final Map<String, Variant> variants) throws IOException, HttpException {
- final RoutedHttpRequest conditionalRequest = conditionalRequestBuilder
- .buildConditionalRequestFromVariants(request, variants);
+ final ClassicHttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequestFromVariants(
+ request, variants);
final Date requestDate = getCurrentDate();
- final ClassicHttpResponse backendResponse = backend.execute(conditionalRequest, context, execAware);
+ final ClassicHttpResponse backendResponse = chain.proceed(conditionalRequest, scope);
try {
final Date responseDate = getCurrentDate();
backendResponse.addHeader("Via", generateViaHeader(backendResponse));
if (backendResponse.getCode() != HttpStatus.SC_NOT_MODIFIED) {
- return handleBackendResponse(request, context, requestDate, responseDate,
- backendResponse);
+ return handleBackendResponse(target, request, scope, requestDate, responseDate, backendResponse);
}
final Header resultEtagHeader = backendResponse.getFirstHeader(HeaderConstants.ETAG);
@@ -626,7 +625,7 @@ public class CachingExec implements Clie
log.warn("304 response did not contain ETag");
IOUtils.consume(backendResponse.getEntity());
backendResponse.close();
- return callBackend(request, context, execAware);
+ return callBackend(target, request, scope, chain);
}
final String resultEtag = resultEtagHeader.getValue();
@@ -635,7 +634,7 @@ public class CachingExec implements Clie
log.debug("304 response did not contain ETag matching one sent in If-None-Match");
IOUtils.consume(backendResponse.getEntity());
backendResponse.close();
- return callBackend(request, context, execAware);
+ return callBackend(target, request, scope, chain);
}
final HttpCacheEntry matchedEntry = matchingVariant.getEntry();
@@ -643,18 +642,18 @@ public class CachingExec implements Clie
if (revalidationResponseIsTooOld(backendResponse, matchedEntry)) {
IOUtils.consume(backendResponse.getEntity());
backendResponse.close();
- return retryRequestUnconditionally(request, context, execAware);
+ return retryRequestUnconditionally(target, request, scope, chain);
}
- recordCacheUpdate(context);
+ recordCacheUpdate(scope.clientContext);
final HttpCacheEntry responseEntry = getUpdatedVariantEntry(
- request.getTargetHost(), conditionalRequest, requestDate, responseDate,
+ target, conditionalRequest, requestDate, responseDate,
backendResponse, matchingVariant, matchedEntry);
backendResponse.close();
final ClassicHttpResponse resp = responseGenerator.generateResponse(request, responseEntry);
- tryToUpdateVariantMap(request.getTargetHost(), request, matchingVariant);
+ tryToUpdateVariantMap(target, request, matchingVariant);
if (shouldSendNotModifiedResponse(request, responseEntry)) {
return responseGenerator.generateNotModifiedResponse(responseEntry);
@@ -667,16 +666,17 @@ public class CachingExec implements Clie
}
private ClassicHttpResponse retryRequestUnconditionally(
- final RoutedHttpRequest request,
- final HttpClientContext context,
- final HttpExecutionAware execAware) throws IOException, HttpException {
- final RoutedHttpRequest unconditional = conditionalRequestBuilder.buildUnconditionalRequest(request);
- return callBackend(unconditional, context, execAware);
+ final HttpHost target,
+ final ClassicHttpRequest request,
+ final ExecChain.Scope scope,
+ final ExecChain chain) throws IOException, HttpException {
+ final ClassicHttpRequest unconditional = conditionalRequestBuilder.buildUnconditionalRequest(request);
+ return callBackend(target, unconditional, scope, chain);
}
private HttpCacheEntry getUpdatedVariantEntry(
final HttpHost target,
- final RoutedHttpRequest conditionalRequest,
+ final ClassicHttpRequest conditionalRequest,
final Date requestDate,
final Date responseDate,
final ClassicHttpResponse backendResponse,
@@ -696,7 +696,7 @@ public class CachingExec implements Clie
private void tryToUpdateVariantMap(
final HttpHost target,
- final RoutedHttpRequest request,
+ final ClassicHttpRequest request,
final Variant matchingVariant) {
try {
responseCache.reuseVariantEntryFor(target, request, matchingVariant);
@@ -706,29 +706,32 @@ public class CachingExec implements Clie
}
private boolean shouldSendNotModifiedResponse(
- final RoutedHttpRequest request,
+ final ClassicHttpRequest request,
final HttpCacheEntry responseEntry) {
return (suitabilityChecker.isConditional(request)
&& suitabilityChecker.allConditionalsMatch(request, responseEntry, new Date()));
}
ClassicHttpResponse revalidateCacheEntry(
- final RoutedHttpRequest request,
- final HttpClientContext context,
- final HttpExecutionAware execAware,
+ final HttpHost target,
+ final ClassicHttpRequest request,
+ final ExecChain.Scope scope,
+ final ExecChain chain,
final HttpCacheEntry cacheEntry) throws IOException, HttpException {
- final RoutedHttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequest(request, cacheEntry);
+ final ClassicHttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequest(
+ scope.originalRequest, cacheEntry);
Date requestDate = getCurrentDate();
- ClassicHttpResponse backendResponse = backend.execute(conditionalRequest, context, execAware);
+ ClassicHttpResponse backendResponse = chain.proceed(conditionalRequest, scope);
Date responseDate = getCurrentDate();
if (revalidationResponseIsTooOld(backendResponse, cacheEntry)) {
backendResponse.close();
- final RoutedHttpRequest unconditional = conditionalRequestBuilder.buildUnconditionalRequest(request);
+ final ClassicHttpRequest unconditional = conditionalRequestBuilder.buildUnconditionalRequest(
+ scope.originalRequest);
requestDate = getCurrentDate();
- backendResponse = backend.execute(unconditional, context, execAware);
+ backendResponse = chain.proceed(unconditional, scope);
responseDate = getCurrentDate();
}
@@ -736,12 +739,12 @@ public class CachingExec implements Clie
final int statusCode = backendResponse.getCode();
if (statusCode == HttpStatus.SC_NOT_MODIFIED || statusCode == HttpStatus.SC_OK) {
- recordCacheUpdate(context);
+ recordCacheUpdate(scope.clientContext);
}
if (statusCode == HttpStatus.SC_NOT_MODIFIED) {
final HttpCacheEntry updatedEntry = responseCache.updateCacheEntry(
- request.getTargetHost(), request, cacheEntry,
+ target, request, cacheEntry,
backendResponse, requestDate, responseDate);
if (suitabilityChecker.isConditional(request)
&& suitabilityChecker.allConditionalsMatch(request, updatedEntry, new Date())) {
@@ -762,8 +765,7 @@ public class CachingExec implements Clie
backendResponse.close();
}
}
- return handleBackendResponse(conditionalRequest, context, requestDate, responseDate,
- backendResponse);
+ return handleBackendResponse(target, conditionalRequest, scope, requestDate, responseDate, backendResponse);
}
private boolean staleIfErrorAppliesTo(final int statusCode) {
@@ -774,16 +776,16 @@ public class CachingExec implements Clie
}
ClassicHttpResponse handleBackendResponse(
- final RoutedHttpRequest request,
- final HttpClientContext context,
+ final HttpHost target,
+ final ClassicHttpRequest request,
+ final ExecChain.Scope scope,
final Date requestDate,
final Date responseDate,
final ClassicHttpResponse backendResponse) throws IOException {
log.trace("Handling Backend response");
- responseCompliance.ensureProtocolCompliance(request, backendResponse);
+ responseCompliance.ensureProtocolCompliance(scope.originalRequest, request, backendResponse);
- final HttpHost target = request.getTargetHost();
final boolean cacheable = responseCachingPolicy.isResponseCacheable(request, backendResponse);
responseCache.flushInvalidatedCacheEntriesFor(target, request, backendResponse);
if (cacheable && !alreadyHaveNewerCacheEntry(target, request, backendResponse)) {
@@ -818,7 +820,7 @@ public class CachingExec implements Clie
}
}
- private boolean alreadyHaveNewerCacheEntry(final HttpHost target, final RoutedHttpRequest request,
+ private boolean alreadyHaveNewerCacheEntry(final HttpHost target, final ClassicHttpRequest request,
final HttpResponse backendResponse) {
HttpCacheEntry existing = null;
try {
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingHttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingHttpClientBuilder.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingHttpClientBuilder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingHttpClientBuilder.java Mon May 1 11:11:09 2017
@@ -33,8 +33,10 @@ import java.io.IOException;
import org.apache.hc.client5.http.cache.HttpCacheInvalidator;
import org.apache.hc.client5.http.cache.HttpCacheStorage;
import org.apache.hc.client5.http.cache.ResourceFactory;
-import org.apache.hc.client5.http.impl.sync.ClientExecChain;
+import org.apache.hc.client5.http.impl.NamedElementChain;
+import org.apache.hc.client5.http.impl.sync.ChainElements;
import org.apache.hc.client5.http.impl.sync.HttpClientBuilder;
+import org.apache.hc.client5.http.sync.ExecChainHandler;
/**
* Builder for {@link org.apache.hc.client5.http.impl.sync.CloseableHttpClient}
@@ -103,7 +105,7 @@ public class CachingHttpClientBuilder ex
}
@Override
- protected ClientExecChain decorateMainExec(final ClientExecChain mainExec) {
+ protected void customizeExecChain(final NamedElementChain<ExecChainHandler> execChainDefinition) {
final CacheConfig config = this.cacheConfig != null ? this.cacheConfig : CacheConfig.DEFAULT;
// We copy the instance fields to avoid changing them, and rename to avoid accidental use of the wrong version
ResourceFactory resourceFactoryCopy = this.resourceFactory;
@@ -135,35 +137,22 @@ public class CachingHttpClientBuilder ex
storageCopy = managedStorage;
}
}
- final AsynchronousValidator revalidator = createAsynchronousRevalidator(config);
- final CacheKeyGenerator uriExtractor = new CacheKeyGenerator();
-
- HttpCacheInvalidator cacheInvalidator = this.httpCacheInvalidator;
- if (cacheInvalidator == null) {
- cacheInvalidator = new CacheInvalidator(uriExtractor, storageCopy);
- }
-
- return new CachingExec(mainExec,
- new BasicHttpCache(
- resourceFactoryCopy,
- storageCopy, config,
- uriExtractor,
- cacheInvalidator), config, revalidator);
- }
-
- private AsynchronousValidator createAsynchronousRevalidator(final CacheConfig config) {
+ final AsynchronousValidator revalidator;
if (config.getAsynchronousWorkersMax() > 0) {
- final SchedulingStrategy configuredSchedulingStrategy = createSchedulingStrategy(config);
- final AsynchronousValidator revalidator = new AsynchronousValidator(
- configuredSchedulingStrategy);
+ revalidator = new AsynchronousValidator(schedulingStrategy != null ? schedulingStrategy : new ImmediateSchedulingStrategy(config));
addCloseable(revalidator);
- return revalidator;
+ } else {
+ revalidator = null;
}
- return null;
- }
+ final CacheKeyGenerator uriExtractor = new CacheKeyGenerator();
+ final HttpCache httpCache = new BasicHttpCache(
+ resourceFactoryCopy,
+ storageCopy, config,
+ uriExtractor,
+ this.httpCacheInvalidator != null ? this.httpCacheInvalidator : new CacheInvalidator(uriExtractor, storageCopy));
- private SchedulingStrategy createSchedulingStrategy(final CacheConfig config) {
- return schedulingStrategy != null ? schedulingStrategy : new ImmediateSchedulingStrategy(config);
+ final CachingExec cachingExec = new CachingExec(httpCache, config, revalidator);
+ execChainDefinition.addAfter(ChainElements.PROTOCOL.name(), cachingExec, "CACHING");
}
}
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java Mon May 1 11:11:09 2017
@@ -31,9 +31,10 @@ import java.util.Map;
import org.apache.hc.client5.http.cache.HeaderConstants;
import org.apache.hc.client5.http.cache.HttpCacheEntry;
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
+import org.apache.hc.client5.http.impl.ExecSupport;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HeaderElement;
import org.apache.hc.core5.http.ProtocolException;
@@ -56,9 +57,9 @@ class ConditionalRequestBuilder {
* @return the wrapped request
* @throws ProtocolException when I am unable to build a new origin request.
*/
- public RoutedHttpRequest buildConditionalRequest(final RoutedHttpRequest request, final HttpCacheEntry cacheEntry)
+ public ClassicHttpRequest buildConditionalRequest(final ClassicHttpRequest request, final HttpCacheEntry cacheEntry)
throws ProtocolException {
- final RoutedHttpRequest newRequest = RoutedHttpRequest.adapt(request.getOriginal(), request.getRoute());
+ final ClassicHttpRequest newRequest = ExecSupport.copy(request);
newRequest.setHeaders(request.getAllHeaders());
final Header eTag = cacheEntry.getFirstHeader(HeaderConstants.ETAG);
if (eTag != null) {
@@ -96,9 +97,9 @@ class ConditionalRequestBuilder {
* @param variants
* @return the wrapped request
*/
- public RoutedHttpRequest buildConditionalRequestFromVariants(final RoutedHttpRequest request,
- final Map<String, Variant> variants) {
- final RoutedHttpRequest newRequest = RoutedHttpRequest.adapt(request.getOriginal(), request.getRoute());
+ public ClassicHttpRequest buildConditionalRequestFromVariants(final ClassicHttpRequest request,
+ final Map<String, Variant> variants) {
+ final ClassicHttpRequest newRequest = ExecSupport.copy(request);
newRequest.setHeaders(request.getAllHeaders());
// we do not support partial content so all etags are used
@@ -126,9 +127,8 @@ class ConditionalRequestBuilder {
* @param request client request we are trying to satisfy
* @return an unconditional validation request
*/
- public RoutedHttpRequest buildUnconditionalRequest(final RoutedHttpRequest request) {
- final RoutedHttpRequest newRequest = RoutedHttpRequest.adapt(request.getOriginal(), request.getRoute());
- newRequest.setHeaders(request.getAllHeaders());
+ public ClassicHttpRequest buildUnconditionalRequest(final ClassicHttpRequest request) {
+ final ClassicHttpRequest newRequest = ExecSupport.copy(request);
newRequest.addHeader(HeaderConstants.CACHE_CONTROL,HeaderConstants.CACHE_CONTROL_NO_CACHE);
newRequest.addHeader(HeaderConstants.PRAGMA,HeaderConstants.CACHE_CONTROL_NO_CACHE);
newRequest.removeHeaders(HeaderConstants.IF_RANGE);
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/RequestProtocolCompliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/RequestProtocolCompliance.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/RequestProtocolCompliance.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/RequestProtocolCompliance.java Mon May 1 11:11:09 2017
@@ -32,10 +32,10 @@ import java.util.Iterator;
import java.util.List;
import org.apache.hc.client5.http.cache.HeaderConstants;
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
import org.apache.hc.client5.http.protocol.ClientProtocolException;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.Header;
@@ -109,7 +109,7 @@ class RequestProtocolCompliance {
* @param request the request to check for compliance
* @throws ClientProtocolException when we have trouble making the request compliant
*/
- public void makeRequestCompliant(final RoutedHttpRequest request)
+ public void makeRequestCompliant(final ClassicHttpRequest request)
throws ClientProtocolException {
if (requestMustNotHaveEntity(request)) {
@@ -180,7 +180,7 @@ class RequestProtocolCompliance {
request.setHeader(HeaderConstants.MAX_FORWARDS, Integer.toString(currentMaxForwards - 1));
}
- private void verifyOPTIONSRequestWithBodyHasContentType(final RoutedHttpRequest request) {
+ private void verifyOPTIONSRequestWithBodyHasContentType(final ClassicHttpRequest request) {
if (!HeaderConstants.OPTIONS_METHOD.equals(request.getMethod())) {
return;
}
@@ -188,7 +188,7 @@ class RequestProtocolCompliance {
addContentTypeHeaderIfMissing(request);
}
- private void addContentTypeHeaderIfMissing(final RoutedHttpRequest request) {
+ private void addContentTypeHeaderIfMissing(final ClassicHttpRequest request) {
final HttpEntity entity = request.getEntity();
if (entity != null && entity.getContentType() == null) {
final HttpEntityWrapper entityWrapper = new HttpEntityWrapper(entity) {
@@ -203,7 +203,7 @@ class RequestProtocolCompliance {
}
}
- private void verifyRequestWithExpectContinueFlagHas100continueHeader(final RoutedHttpRequest request) {
+ private void verifyRequestWithExpectContinueFlagHas100continueHeader(final ClassicHttpRequest request) {
if (request.containsHeader(HttpHeaders.EXPECT) && request.getEntity() != null) {
add100ContinueHeaderIfMissing(request);
} else {
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseProtocolCompliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseProtocolCompliance.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseProtocolCompliance.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseProtocolCompliance.java Mon May 1 11:11:09 2017
@@ -33,10 +33,10 @@ import java.util.List;
import org.apache.hc.client5.http.cache.HeaderConstants;
import org.apache.hc.client5.http.protocol.ClientProtocolException;
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
import org.apache.hc.client5.http.utils.DateUtils;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HeaderElement;
@@ -66,20 +66,23 @@ class ResponseProtocolCompliance {
* we attempt to see if it is HTTP 1.1 Compliant and if not, attempt to
* make it so.
*
+ * @param originalRequest The original {@link HttpRequest}
* @param request The {@link HttpRequest} that generated an origin hit and response
* @param response The {@link HttpResponse} from the origin server
* @throws IOException Bad things happened
*/
- public void ensureProtocolCompliance(final RoutedHttpRequest request, final ClassicHttpResponse response)
- throws IOException {
+ public void ensureProtocolCompliance(
+ final ClassicHttpRequest originalRequest,
+ final ClassicHttpRequest request,
+ final ClassicHttpResponse response) throws IOException {
if (backendResponseMustNotHaveBody(request, response)) {
consumeBody(response);
response.setEntity(null);
}
- requestDidNotExpect100ContinueButResponseIsOne(request, response);
+ requestDidNotExpect100ContinueButResponseIsOne(originalRequest, response);
- transferEncodingIsNotReturnedTo1_0Client(request, response);
+ transferEncodingIsNotReturnedTo1_0Client(originalRequest, response);
ensurePartialContentIsNotSentToAClientThatDidNotRequestIt(request, response);
@@ -221,13 +224,12 @@ class ResponseProtocolCompliance {
|| backendResponse.getCode() == HttpStatus.SC_NOT_MODIFIED;
}
- private void requestDidNotExpect100ContinueButResponseIsOne(final RoutedHttpRequest request,
- final ClassicHttpResponse response) throws IOException {
+ private void requestDidNotExpect100ContinueButResponseIsOne(
+ final ClassicHttpRequest originalRequest, final ClassicHttpResponse response) throws IOException {
if (response.getCode() != HttpStatus.SC_CONTINUE) {
return;
}
- final HttpRequest originalRequest = request.getOriginal();
final Header header = originalRequest.getFirstHeader(HttpHeaders.EXPECT);
if (header != null && header.getValue().equalsIgnoreCase(HeaderElements.CONTINUE)) {
return;
@@ -236,9 +238,8 @@ class ResponseProtocolCompliance {
throw new ClientProtocolException(UNEXPECTED_100_CONTINUE);
}
- private void transferEncodingIsNotReturnedTo1_0Client(final RoutedHttpRequest request,
- final HttpResponse response) {
- final HttpRequest originalRequest = request.getOriginal();
+ private void transferEncodingIsNotReturnedTo1_0Client(
+ final ClassicHttpRequest originalRequest, final HttpResponse response) {
final ProtocolVersion version = originalRequest.getVersion() != null ? originalRequest.getVersion() : HttpVersion.DEFAULT;
if (version.compareToVersion(HttpVersion.HTTP_1_1) >= 0) {
return;
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java Mon May 1 11:11:09 2017
@@ -26,16 +26,19 @@
*/
package org.apache.hc.client5.http.impl.cache;
+import java.io.IOException;
import java.util.HashMap;
import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.client5.http.cache.HttpCacheContext;
-import org.apache.hc.client5.http.impl.sync.ClientExecChain;
+import org.apache.hc.client5.http.impl.ExecSupport;
+import org.apache.hc.client5.http.sync.ExecRuntime;
import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.sync.methods.HttpExecutionAware;
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
+import org.apache.hc.client5.http.sync.ExecChain;
+import org.apache.hc.client5.http.sync.ExecChainHandler;
+import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
@@ -52,16 +55,17 @@ public abstract class AbstractProtocolTe
protected HttpHost host;
protected HttpRoute route;
protected HttpEntity body;
- protected ClientExecChain mockBackend;
+ protected HttpClientContext context;
+ protected ExecChain mockExecChain;
+ protected ExecRuntime mockEndpoint;
protected HttpCache mockCache;
- protected RoutedHttpRequest request;
- protected HttpCacheContext context;
+ protected ClassicHttpRequest request;
protected ClassicHttpResponse originResponse;
protected CacheConfig config;
- protected ClientExecChain impl;
+ protected ExecChainHandler impl;
protected HttpCache cache;
- public static RoutedHttpRequest eqRequest(final RoutedHttpRequest in) {
+ public static ClassicHttpRequest eqRequest(final ClassicHttpRequest in) {
EasyMock.reportMatcher(new RequestEquivalent(in));
return null;
}
@@ -84,9 +88,9 @@ public abstract class AbstractProtocolTe
body = HttpTestUtils.makeBody(entityLength);
- request = RoutedHttpRequest.adapt(new BasicClassicHttpRequest("GET", "/foo"), route);
+ request = new BasicClassicHttpRequest("GET", "/foo");
- context = HttpCacheContext.create();
+ context = HttpClientContext.create();
originResponse = HttpTestUtils.make200Response();
@@ -96,52 +100,54 @@ public abstract class AbstractProtocolTe
.build();
cache = new BasicHttpCache(config);
- mockBackend = EasyMock.createNiceMock(ClientExecChain.class);
+ mockExecChain = EasyMock.createNiceMock(ExecChain.class);
+ mockEndpoint = EasyMock.createNiceMock(ExecRuntime.class);
mockCache = EasyMock.createNiceMock(HttpCache.class);
- impl = createCachingExecChain(mockBackend, cache, config);
+ impl = createCachingExecChain(cache, config);
}
- protected ClientExecChain createCachingExecChain(final ClientExecChain backend,
- final HttpCache cache, final CacheConfig config) {
- return new CachingExec(backend, cache, config);
+ public ClassicHttpResponse execute(final ClassicHttpRequest request) throws IOException, HttpException {
+ return impl.execute(ExecSupport.copy(request), new ExecChain.Scope(route, request, mockEndpoint, context), mockExecChain);
}
- protected boolean supportsRangeAndContentRangeHeaders(final ClientExecChain impl) {
+ protected ExecChainHandler createCachingExecChain(final HttpCache cache, final CacheConfig config) {
+ return new CachingExec(cache, config);
+ }
+
+ protected boolean supportsRangeAndContentRangeHeaders(final ExecChainHandler impl) {
return impl instanceof CachingExec && ((CachingExec) impl).supportsRangeAndContentRangeHeaders();
}
protected void replayMocks() {
- EasyMock.replay(mockBackend);
+ EasyMock.replay(mockExecChain);
EasyMock.replay(mockCache);
}
protected void verifyMocks() {
- EasyMock.verify(mockBackend);
+ EasyMock.verify(mockExecChain);
EasyMock.verify(mockCache);
}
protected IExpectationSetters<ClassicHttpResponse> backendExpectsAnyRequest() throws Exception {
- final ClassicHttpResponse resp = mockBackend.execute(
- EasyMock.isA(RoutedHttpRequest.class),
- EasyMock.isA(HttpClientContext.class),
- EasyMock.<HttpExecutionAware>isNull());
+ final ClassicHttpResponse resp = mockExecChain.proceed(
+ EasyMock.isA(ClassicHttpRequest.class),
+ EasyMock.isA(ExecChain.Scope.class));
return EasyMock.expect(resp);
}
protected IExpectationSetters<ClassicHttpResponse> backendExpectsAnyRequestAndReturn(
final ClassicHttpResponse response) throws Exception {
- final ClassicHttpResponse resp = mockBackend.execute(
- EasyMock.isA(RoutedHttpRequest.class),
- EasyMock.isA(HttpClientContext.class),
- EasyMock.<HttpExecutionAware>isNull());
+ final ClassicHttpResponse resp = mockExecChain.proceed(
+ EasyMock.isA(ClassicHttpRequest.class),
+ EasyMock.isA(ExecChain.Scope.class));
return EasyMock.expect(resp).andReturn(response);
}
protected void emptyMockCacheExpectsNoPuts() throws Exception {
- mockBackend = EasyMock.createNiceMock(ClientExecChain.class);
+ mockExecChain = EasyMock.createNiceMock(ExecChain.class);
mockCache = EasyMock.createNiceMock(HttpCache.class);
- impl = new CachingExec(mockBackend, mockCache, config);
+ impl = new CachingExec(mockCache, config);
EasyMock.expect(mockCache.getCacheEntry(EasyMock.isA(HttpHost.class), EasyMock.isA(HttpRequest.class)))
.andReturn(null).anyTimes();
@@ -167,7 +173,7 @@ public abstract class AbstractProtocolTe
.setMaxObjectSize(MAX_BYTES)
.setSharedCache(false)
.build();
- impl = new CachingExec(mockBackend, cache, config);
+ impl = new CachingExec(cache, config);
}
public AbstractProtocolTest() {
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/DummyBackend.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/DummyBackend.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/DummyBackend.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/DummyBackend.java Mon May 1 11:11:09 2017
@@ -28,10 +28,7 @@ package org.apache.hc.client5.http.impl.
import java.io.IOException;
-import org.apache.hc.client5.http.impl.sync.ClientExecChain;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.sync.methods.HttpExecutionAware;
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
+import org.apache.hc.client5.http.sync.ExecChain;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpException;
@@ -39,7 +36,7 @@ import org.apache.hc.core5.http.HttpRequ
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
-public class DummyBackend implements ClientExecChain {
+public class DummyBackend implements ExecChain {
private ClassicHttpRequest request;
private ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
@@ -54,10 +51,9 @@ public class DummyBackend implements Cli
}
@Override
- public ClassicHttpResponse execute(
- final RoutedHttpRequest request,
- final HttpClientContext clientContext,
- final HttpExecutionAware execAware) throws IOException, HttpException {
+ public ClassicHttpResponse proceed(
+ final ClassicHttpRequest request,
+ final Scope scope) throws IOException, HttpException {
this.request = request;
executions++;
return response;
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidationRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidationRequest.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidationRequest.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidationRequest.java Mon May 1 11:11:09 2017
@@ -35,10 +35,11 @@ import java.io.IOException;
import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.cache.HeaderConstants;
import org.apache.hc.client5.http.cache.HttpCacheEntry;
+import org.apache.hc.client5.http.sync.ExecRuntime;
import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.sync.methods.HttpExecutionAware;
+import org.apache.hc.client5.http.sync.ExecChain;
import org.apache.hc.client5.http.sync.methods.HttpGet;
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpHost;
@@ -54,9 +55,11 @@ public class TestAsynchronousValidationR
private CachingExec mockClient;
private HttpHost host;
private HttpRoute route;
- private RoutedHttpRequest request;
+ private ClassicHttpRequest request;
private HttpClientContext context;
- private HttpExecutionAware mockExecAware;
+ private ExecChain.Scope scope;
+ private ExecChain execChain;
+ private ExecRuntime mockEndpoint;
private HttpCacheEntry mockCacheEntry;
private ClassicHttpResponse mockResponse;
@@ -66,11 +69,13 @@ public class TestAsynchronousValidationR
mockClient = mock(CachingExec.class);
host = new HttpHost("foo.example.com", 80);
route = new HttpRoute(host);
- request = RoutedHttpRequest.adapt(new HttpGet("/"), route);
+ request = new HttpGet("/");
context = HttpClientContext.create();
- mockExecAware = mock(HttpExecutionAware.class);
+ mockEndpoint = mock(ExecRuntime.class);
+ execChain = mock(ExecChain.class);
mockCacheEntry = mock(HttpCacheEntry.class);
mockResponse = mock(ClassicHttpResponse.class);
+ scope = new ExecChain.Scope(route, request, mockEndpoint, context);
}
@Test
@@ -78,18 +83,15 @@ public class TestAsynchronousValidationR
final String identifier = "foo";
final AsynchronousValidationRequest impl = new AsynchronousValidationRequest(
- mockParent, mockClient, request, context, mockExecAware, mockCacheEntry,
+ mockParent, mockClient, host, request, scope, execChain, mockCacheEntry,
identifier, 0);
- when(
- mockClient.revalidateCacheEntry(
- request, context, mockExecAware, mockCacheEntry)).thenReturn(mockResponse);
+ when(mockClient.revalidateCacheEntry(host, request, scope, execChain, mockCacheEntry)).thenReturn(mockResponse);
when(mockResponse.getCode()).thenReturn(200);
impl.run();
- verify(mockClient).revalidateCacheEntry(
- request, context, mockExecAware, mockCacheEntry);
+ verify(mockClient).revalidateCacheEntry(host, request, scope, execChain, mockCacheEntry);
verify(mockParent).markComplete(identifier);
verify(mockParent).jobSuccessful(identifier);
}
@@ -99,18 +101,15 @@ public class TestAsynchronousValidationR
final String identifier = "foo";
final AsynchronousValidationRequest impl = new AsynchronousValidationRequest(
- mockParent, mockClient, request, context, mockExecAware, mockCacheEntry,
+ mockParent, mockClient, host, request, scope, execChain, mockCacheEntry,
identifier, 0);
- when(
- mockClient.revalidateCacheEntry(
- request, context, mockExecAware, mockCacheEntry)).thenReturn(mockResponse);
+ when(mockClient.revalidateCacheEntry(host, request, scope, execChain, mockCacheEntry)).thenReturn(mockResponse);
when(mockResponse.getCode()).thenReturn(200);
impl.run();
- verify(mockClient).revalidateCacheEntry(
- request, context, mockExecAware, mockCacheEntry);
+ verify(mockClient).revalidateCacheEntry(host, request, scope, execChain, mockCacheEntry);
verify(mockParent).markComplete(identifier);
verify(mockParent).jobSuccessful(identifier);
}
@@ -121,19 +120,17 @@ public class TestAsynchronousValidationR
final Header[] warning = new Header[] {new BasicHeader(HeaderConstants.WARNING, "110 localhost \"Response is stale\"")};
final AsynchronousValidationRequest impl = new AsynchronousValidationRequest(
- mockParent, mockClient, request, context, mockExecAware, mockCacheEntry,
+ mockParent, mockClient, host, request, scope, execChain, mockCacheEntry,
identifier, 0);
- when(
- mockClient.revalidateCacheEntry(
- request, context, mockExecAware, mockCacheEntry)).thenReturn(mockResponse);
+ when(mockClient.revalidateCacheEntry(host, request, scope, execChain, mockCacheEntry))
+ .thenReturn(mockResponse);
when(mockResponse.getCode()).thenReturn(200);
when(mockResponse.getHeaders(HeaderConstants.WARNING)).thenReturn(warning);
impl.run();
- verify(mockClient).revalidateCacheEntry(
- request, context, mockExecAware, mockCacheEntry);
+ verify(mockClient).revalidateCacheEntry(host, request, scope, execChain, mockCacheEntry);
verify(mockResponse).getHeaders(HeaderConstants.WARNING);
verify(mockParent).markComplete(identifier);
verify(mockParent).jobFailed(identifier);
@@ -144,18 +141,15 @@ public class TestAsynchronousValidationR
final String identifier = "foo";
final AsynchronousValidationRequest impl = new AsynchronousValidationRequest(
- mockParent, mockClient, request, context, mockExecAware, mockCacheEntry,
+ mockParent, mockClient, host, request, scope, execChain, mockCacheEntry,
identifier, 0);
- when(
- mockClient.revalidateCacheEntry(
- request, context, mockExecAware, mockCacheEntry)).thenThrow(
- new ProtocolException());
+ when(mockClient.revalidateCacheEntry(host, request, scope, execChain, mockCacheEntry))
+ .thenThrow(new ProtocolException());
impl.run();
- verify(mockClient).revalidateCacheEntry(
- request, context, mockExecAware, mockCacheEntry);
+ verify(mockClient).revalidateCacheEntry(host, request, scope, execChain, mockCacheEntry);
verify(mockParent).markComplete(identifier);
verify(mockParent).jobFailed(identifier);
}
@@ -165,18 +159,15 @@ public class TestAsynchronousValidationR
final String identifier = "foo";
final AsynchronousValidationRequest impl = new AsynchronousValidationRequest(
- mockParent, mockClient, request, context, mockExecAware, mockCacheEntry,
+ mockParent, mockClient, host, request, scope, execChain, mockCacheEntry,
identifier, 0);
- when(
- mockClient.revalidateCacheEntry(
- request, context, mockExecAware, mockCacheEntry)).thenThrow(
- new IOException());
+ when(mockClient.revalidateCacheEntry(host, request, scope, execChain, mockCacheEntry))
+ .thenThrow(new IOException());
impl.run();
- verify(mockClient).revalidateCacheEntry(
- request, context, mockExecAware, mockCacheEntry);
+ verify(mockClient).revalidateCacheEntry(host, request, scope, execChain, mockCacheEntry);
verify(mockParent).markComplete(identifier);
verify(mockParent).jobFailed(identifier);
}
@@ -186,18 +177,16 @@ public class TestAsynchronousValidationR
final String identifier = "foo";
final AsynchronousValidationRequest impl = new AsynchronousValidationRequest(
- mockParent, mockClient, request, context, mockExecAware, mockCacheEntry,
+ mockParent, mockClient, host, request, scope, execChain, mockCacheEntry,
identifier, 0);
- when(
- mockClient.revalidateCacheEntry(
- request, context, mockExecAware, mockCacheEntry)).thenThrow(
- new RuntimeException());
+ when(mockClient.revalidateCacheEntry(host, request, scope, execChain, mockCacheEntry))
+ .thenThrow(new RuntimeException());
impl.run();
verify(mockClient).revalidateCacheEntry(
- request, context, mockExecAware, mockCacheEntry);
+ host, request, scope, execChain, mockCacheEntry);
verify(mockParent).markComplete(identifier);
verify(mockParent).jobFailed(identifier);
}
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidator.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidator.java Mon May 1 11:11:09 2017
@@ -40,10 +40,10 @@ import java.util.concurrent.TimeUnit;
import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.cache.HeaderConstants;
import org.apache.hc.client5.http.cache.HttpCacheEntry;
+import org.apache.hc.client5.http.sync.ExecRuntime;
import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.sync.methods.HttpExecutionAware;
+import org.apache.hc.client5.http.sync.ExecChain;
import org.apache.hc.client5.http.sync.methods.HttpGet;
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpHost;
@@ -62,9 +62,11 @@ public class TestAsynchronousValidator {
private CachingExec mockClient;
private HttpHost host;
private HttpRoute route;
- private RoutedHttpRequest request;
+ private ClassicHttpRequest request;
private HttpClientContext context;
- private HttpExecutionAware mockExecAware;
+ private ExecChain.Scope scope;
+ private ExecChain mockExecChain;
+ private ExecRuntime mockEndpoint;
private HttpCacheEntry mockCacheEntry;
private SchedulingStrategy mockSchedulingStrategy;
@@ -74,11 +76,13 @@ public class TestAsynchronousValidator {
mockClient = mock(CachingExec.class);
host = new HttpHost("foo.example.com", 80);
route = new HttpRoute(host);
- request = RoutedHttpRequest.adapt(new HttpGet("/"), route);
+ request = new HttpGet("/");
context = HttpClientContext.create();
- mockExecAware = mock(HttpExecutionAware.class);
+ mockExecChain = mock(ExecChain.class);
+ mockEndpoint = mock(ExecRuntime.class);
mockCacheEntry = mock(HttpCacheEntry.class);
mockSchedulingStrategy = mock(SchedulingStrategy.class);
+ scope = new ExecChain.Scope(route, request, mockEndpoint, context);
}
@Test
@@ -87,7 +91,7 @@ public class TestAsynchronousValidator {
when(mockCacheEntry.hasVariants()).thenReturn(false);
- impl.revalidateCacheEntry(mockClient, request, context, mockExecAware, mockCacheEntry);
+ impl.revalidateCacheEntry(mockClient, host, request, scope, mockExecChain, mockCacheEntry);
verify(mockCacheEntry).hasVariants();
verify(mockSchedulingStrategy).schedule(isA(AsynchronousValidationRequest.class));
@@ -101,7 +105,7 @@ public class TestAsynchronousValidator {
when(mockCacheEntry.hasVariants()).thenReturn(false);
- impl.revalidateCacheEntry(mockClient, request, context, mockExecAware, mockCacheEntry);
+ impl.revalidateCacheEntry(mockClient, host, request, scope, mockExecChain, mockCacheEntry);
final ArgumentCaptor<AsynchronousValidationRequest> cap = ArgumentCaptor.forClass(AsynchronousValidationRequest.class);
verify(mockCacheEntry).hasVariants();
@@ -121,7 +125,7 @@ public class TestAsynchronousValidator {
when(mockCacheEntry.hasVariants()).thenReturn(false);
doThrow(new RejectedExecutionException()).when(mockSchedulingStrategy).schedule(isA(AsynchronousValidationRequest.class));
- impl.revalidateCacheEntry(mockClient, request, context, mockExecAware, mockCacheEntry);
+ impl.revalidateCacheEntry(mockClient, host, request, scope, mockExecChain, mockCacheEntry);
verify(mockCacheEntry).hasVariants();
@@ -135,8 +139,8 @@ public class TestAsynchronousValidator {
when(mockCacheEntry.hasVariants()).thenReturn(false);
- impl.revalidateCacheEntry(mockClient, request, context, mockExecAware, mockCacheEntry);
- impl.revalidateCacheEntry(mockClient, request, context, mockExecAware, mockCacheEntry);
+ impl.revalidateCacheEntry(mockClient, host, request, scope, mockExecChain, mockCacheEntry);
+ impl.revalidateCacheEntry(mockClient, host, request, scope, mockExecChain, mockCacheEntry);
verify(mockCacheEntry, times(2)).hasVariants();
verify(mockSchedulingStrategy).schedule(isA(AsynchronousValidationRequest.class));
@@ -163,8 +167,10 @@ public class TestAsynchronousValidator {
new BasicHeaderIterator(variantHeaders, HeaderConstants.VARY));
mockSchedulingStrategy.schedule(isA(AsynchronousValidationRequest.class));
- impl.revalidateCacheEntry(mockClient, RoutedHttpRequest.adapt(req1, route), context, mockExecAware, mockCacheEntry);
- impl.revalidateCacheEntry(mockClient, RoutedHttpRequest.adapt(req2, route), context, mockExecAware, mockCacheEntry);
+ impl.revalidateCacheEntry(mockClient, host, req1, new ExecChain.Scope(route, req1, mockEndpoint, context),
+ mockExecChain, mockCacheEntry);
+ impl.revalidateCacheEntry(mockClient, host, req2, new ExecChain.Scope(route, req2, mockEndpoint, context),
+ mockExecChain, mockCacheEntry);
verify(mockCacheEntry, times(2)).hasVariants();
verify(mockCacheEntry, times(2)).headerIterator(HeaderConstants.VARY);
@@ -184,9 +190,9 @@ public class TestAsynchronousValidator {
when(mockCacheEntry.hasVariants()).thenReturn(false);
when(mockClient.revalidateCacheEntry(
- request, context, mockExecAware, mockCacheEntry)).thenReturn(null);
+ host, request, scope, mockExecChain, mockCacheEntry)).thenReturn(null);
- impl.revalidateCacheEntry(mockClient, request, context, mockExecAware, mockCacheEntry);
+ impl.revalidateCacheEntry(mockClient, host, request, scope, mockExecChain, mockCacheEntry);
try {
// shut down backend executor and make sure all finishes properly, 1 second should be sufficient
@@ -196,7 +202,7 @@ public class TestAsynchronousValidator {
} finally {
verify(mockCacheEntry).hasVariants();
- verify(mockClient).revalidateCacheEntry(request, context, mockExecAware, mockCacheEntry);
+ verify(mockClient).revalidateCacheEntry(host, request, scope, mockExecChain, mockCacheEntry);
Assert.assertEquals(0, impl.getScheduledIdentifiers().size());
}