本文整理汇总了Java中org.apache.http.client.methods.HttpExecutionAware类的典型用法代码示例。如果您正苦于以下问题:Java HttpExecutionAware类的具体用法?Java HttpExecutionAware怎么用?Java HttpExecutionAware使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpExecutionAware类属于org.apache.http.client.methods包,在下文中一共展示了HttpExecutionAware类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Override
public CloseableHttpResponse execute(HttpRoute route, HttpRequestWrapper request, HttpClientContext clientContext,
HttpExecutionAware execAware) throws IOException, HttpException {
Proxy proxy = (Proxy) clientContext.getAttribute(VSCrawlerConstant.VSCRAWLER_AVPROXY_KEY);
if (proxy != null) {
proxy.recordUsage();
}
try {
return delegate.execute(route, request, clientContext, execAware);
} catch (IOException ioe) {
if (proxy != null) {
proxy.recordFailed();
}
throw ioe;
}
}
示例2: testPassesOnOrigin401ResponseWithoutWWWAuthenticateHeader
import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testPassesOnOrigin401ResponseWithoutWWWAuthenticateHeader() throws Exception {
originResponse = Proxies.enhanceResponse(
new BasicHttpResponse(HTTP_1_1, 401, "Unauthorized"));
EasyMock.expect(
mockBackend.execute(
EasyMock.eq(route),
EasyMock.isA(HttpRequestWrapper.class),
EasyMock.isA(HttpClientContext.class),
EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
replayMocks();
final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request), context, null);
verifyMocks();
Assert.assertSame(originResponse, result);
}
示例3: revalidateCacheEntry
import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
private CloseableHttpResponse revalidateCacheEntry(
final HttpRoute route,
final HttpRequestWrapper request,
final HttpClientContext context,
final HttpExecutionAware execAware,
final HttpCacheEntry entry,
final Date now) throws HttpException {
try {
if (asynchRevalidator != null
&& !staleResponseNotAllowed(request, entry, now)
&& validityPolicy.mayReturnStaleWhileRevalidating(entry, now)) {
log.trace("Serving stale with asynchronous revalidation");
final CloseableHttpResponse resp = generateCachedResponse(request, context, entry, now);
asynchRevalidator.revalidateCacheEntry(this, route, request, context, execAware, entry);
return resp;
}
return revalidateCacheEntry(route, request, context, execAware, entry);
} catch (final IOException ioex) {
return handleRevalidationFailure(request, context, entry, now);
}
}
示例4: handleCacheMiss
import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
private CloseableHttpResponse handleCacheMiss(
final HttpRoute route,
final HttpRequestWrapper request,
final HttpClientContext context,
final HttpExecutionAware execAware) throws IOException, HttpException {
final HttpHost target = context.getTargetHost();
recordCacheMiss(target, request);
if (!mayCallBackend(request)) {
return Proxies.enhanceResponse(
new BasicHttpResponse(
HttpVersion.HTTP_1_1, HttpStatus.SC_GATEWAY_TIMEOUT, "Gateway Timeout"));
}
final Map<String, Variant> variants = getExistingCacheVariants(target, request);
if (variants != null && !variants.isEmpty()) {
return negotiateResponseFromVariants(route, request, context,
execAware, variants);
}
return callBackend(route, request, context, execAware);
}
示例5: testPassesOnOrigin407WithoutAProxyAuthenticateHeader
import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testPassesOnOrigin407WithoutAProxyAuthenticateHeader() throws Exception {
originResponse = Proxies.enhanceResponse(
new BasicHttpResponse(HTTP_1_1, 407, "Proxy Authentication Required"));
EasyMock.expect(
mockBackend.execute(
EasyMock.eq(route),
EasyMock.isA(HttpRequestWrapper.class),
EasyMock.isA(HttpClientContext.class),
EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
replayMocks();
final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request), context, null);
verifyMocks();
Assert.assertSame(originResponse, result);
}
示例6: revalidateCacheEntry
import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
/**
* Schedules an asynchronous revalidation
*/
public synchronized void revalidateCacheEntry(
final CachingExec cachingExec,
final HttpRoute route,
final HttpRequestWrapper request,
final HttpClientContext context,
final HttpExecutionAware execAware,
final HttpCacheEntry entry) {
// getVariantURI will fall back on getURI if no variants exist
final String uri = cacheKeyGenerator.getVariantURI(context.getTargetHost(), request, entry);
if (!queued.contains(uri)) {
final int consecutiveFailedAttempts = failureCache.getErrorCount(uri);
final AsynchronousValidationRequest revalidationRequest =
new AsynchronousValidationRequest(
this, cachingExec, route, request, context, execAware, entry, uri, consecutiveFailedAttempts);
try {
schedulingStrategy.schedule(revalidationRequest);
queued.add(uri);
} catch (final RejectedExecutionException ree) {
log.debug("Revalidation for [" + uri + "] not scheduled: " + ree);
}
}
}
示例7: testDoesNotModifyHeaderOnRequests
import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
private void testDoesNotModifyHeaderOnRequests(final String headerName)
throws Exception {
final String headerValue = HttpTestUtils.getCanonicalHeaderValue(request, headerName);
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
EasyMock.expect(
mockBackend.execute(
EasyMock.eq(route),
EasyMock.capture(cap),
EasyMock.isA(HttpClientContext.class),
EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
replayMocks();
impl.execute(route, request, context, null);
verifyMocks();
assertEquals(headerValue,
HttpTestUtils.getCanonicalHeaderValue(cap.getValue(),
headerName));
}
示例8: testPostProcessHttpException
import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test(expected = HttpException.class)
public void testPostProcessHttpException() throws Exception {
final HttpRoute route = new HttpRoute(target);
final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("/test"));
final HttpClientContext context = HttpClientContext.create();
final CloseableHttpResponse response = Mockito.mock(CloseableHttpResponse.class);
Mockito.when(requestExecutor.execute(
Mockito.eq(route),
Mockito.<HttpRequestWrapper>any(),
Mockito.<HttpClientContext>any(),
Mockito.<HttpExecutionAware>any())).thenReturn(response);
Mockito.doThrow(new HttpException("Ooopsie")).when(httpProcessor).process(
Mockito.same(response), Mockito.<HttpContext>any());
try {
protocolExec.execute(route, request, context, execAware);
} catch (final Exception ex) {
Mockito.verify(response).close();
throw ex;
}
}
示例9: testStrategyRuntimeException
import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test(expected = RuntimeException.class)
public void testStrategyRuntimeException() throws Exception {
final HttpRoute route = new HttpRoute(target);
final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("/test"));
final HttpClientContext context = HttpClientContext.create();
final CloseableHttpResponse response = Mockito.mock(CloseableHttpResponse.class);
Mockito.when(requestExecutor.execute(
Mockito.eq(route),
Mockito.<HttpRequestWrapper>any(),
Mockito.<HttpClientContext>any(),
Mockito.<HttpExecutionAware>any())).thenReturn(response);
Mockito.doThrow(new RuntimeException("Ooopsie")).when(retryStrategy).retryRequest(
Mockito.<HttpResponse>any(),
Mockito.anyInt(),
Mockito.<HttpContext>any());
try {
retryExec.execute(route, request, context, execAware);
} catch (final Exception ex) {
Mockito.verify(response).close();
throw ex;
}
}
示例10: testPassesOnOrigin405WithoutAllowHeader
import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testPassesOnOrigin405WithoutAllowHeader() throws Exception {
originResponse = Proxies.enhanceResponse(
new BasicHttpResponse(HTTP_1_1, 405, "Method Not Allowed"));
EasyMock.expect(
mockBackend.execute(
EasyMock.eq(route),
EasyMock.isA(HttpRequestWrapper.class),
EasyMock.isA(HttpClientContext.class),
EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
replayMocks();
final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request), context, null);
verifyMocks();
Assert.assertSame(originResponse, result);
}
示例11: testHigherMajorProtocolVersionsOnRequestSwitchToTunnelBehavior
import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testHigherMajorProtocolVersionsOnRequestSwitchToTunnelBehavior() throws Exception {
// tunnel behavior: I don't muck with request or response in
// any way
request = HttpRequestWrapper.wrap(
new BasicHttpRequest("GET", "/foo", new ProtocolVersion("HTTP", 2, 13)));
EasyMock.expect(
mockBackend.execute(
EasyMock.eq(route),
eqRequest(request),
EasyMock.isA(HttpClientContext.class),
EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
replayMocks();
final HttpResponse result = impl.execute(route, request, context, null);
verifyMocks();
Assert.assertSame(originResponse, result);
}
示例12: testHigher1_XProtocolVersionsDowngradeTo1_1
import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testHigher1_XProtocolVersionsDowngradeTo1_1() throws Exception {
request = HttpRequestWrapper.wrap(
new BasicHttpRequest("GET", "/foo", new ProtocolVersion("HTTP", 1, 2)));
final HttpRequestWrapper downgraded = HttpRequestWrapper.wrap(
new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1));
EasyMock.expect(
mockBackend.execute(
EasyMock.eq(route),
eqRequest(downgraded),
EasyMock.isA(HttpClientContext.class),
EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
replayMocks();
final HttpResponse result = impl.execute(route, request, context, null);
verifyMocks();
Assert.assertTrue(HttpTestUtils.semanticallyTransparent(originResponse, result));
}
示例13: testRequestsWithLowerProtocolVersionsGetUpgradedTo1_1
import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testRequestsWithLowerProtocolVersionsGetUpgradedTo1_1() throws Exception {
request = HttpRequestWrapper.wrap(
new BasicHttpRequest("GET", "/foo", new ProtocolVersion("HTTP", 1, 0)));
final HttpRequestWrapper upgraded = HttpRequestWrapper.wrap(
new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1));
EasyMock.expect(
mockBackend.execute(
EasyMock.eq(route),
eqRequest(upgraded),
EasyMock.isA(HttpClientContext.class),
EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
replayMocks();
final HttpResponse result = impl.execute(route, request, context, null);
verifyMocks();
Assert.assertTrue(HttpTestUtils.semanticallyTransparent(originResponse, result));
}
示例14: testLowerOriginResponsesUpgradedToOurVersion1_1
import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testLowerOriginResponsesUpgradedToOurVersion1_1() throws Exception {
originResponse = Proxies.enhanceResponse(
new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 2), HttpStatus.SC_OK, "OK"));
originResponse.setHeader("Date", DateUtils.formatDate(new Date()));
originResponse.setHeader("Server", "MockOrigin/1.0");
originResponse.setEntity(body);
// not testing this internal behavior in this test, just want
// to check the protocol version that comes out the other end
EasyMock.expect(
mockBackend.execute(
EasyMock.isA(HttpRoute.class),
EasyMock.isA(HttpRequestWrapper.class),
EasyMock.isA(HttpClientContext.class),
EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
replayMocks();
final HttpResponse result = impl.execute(route, request, context, null);
verifyMocks();
Assert.assertEquals(HttpVersion.HTTP_1_1, result.getProtocolVersion());
}
示例15: testResponseToA1_0RequestShouldUse1_1
import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testResponseToA1_0RequestShouldUse1_1() throws Exception {
request = HttpRequestWrapper.wrap(
new BasicHttpRequest("GET", "/foo", new ProtocolVersion("HTTP", 1, 0)));
EasyMock.expect(
mockBackend.execute(
EasyMock.isA(HttpRoute.class),
EasyMock.isA(HttpRequestWrapper.class),
EasyMock.isA(HttpClientContext.class),
EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
replayMocks();
final HttpResponse result = impl.execute(route, request, context, null);
verifyMocks();
Assert.assertEquals(HttpVersion.HTTP_1_1, result.getProtocolVersion());
}