当前位置: 首页>>代码示例>>Java>>正文


Java HttpExecutionAware类代码示例

本文整理汇总了Java中org.apache.http.client.methods.HttpExecutionAware的典型用法代码示例。如果您正苦于以下问题:Java HttpExecutionAware类的具体用法?Java HttpExecutionAware怎么用?Java HttpExecutionAware使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

HttpExecutionAware类属于org.apache.http.client.methods包,在下文中一共展示了HttpExecutionAware类的40个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
    }
}
 
开发者ID:virjar,项目名称:vscrawler,代码行数:17,代码来源:ProxyFeedBackClientExecChain.java


示例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);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:18,代码来源:TestProtocolDeviations.java


示例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);
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:CachingExec.java


示例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);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:CachingExec.java


示例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);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:17,代码来源:TestProtocolDeviations.java


示例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);
        }
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:28,代码来源:AsynchronousValidator.java


示例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));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:18,代码来源:TestProtocolRecommendations.java


示例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;
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:TestProtocolExec.java


示例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;
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:24,代码来源:TestServiceUnavailableRetryExec.java


示例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);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:17,代码来源:TestProtocolDeviations.java


示例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);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestProtocolRequirements.java


示例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));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:TestProtocolRequirements.java


示例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));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestProtocolRequirements.java


示例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());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:24,代码来源:TestProtocolRequirements.java


示例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());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:19,代码来源:TestProtocolRequirements.java


示例16: testForwardsUnknownHeadersOnRequestsFromHigherProtocolVersions

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testForwardsUnknownHeadersOnRequestsFromHigherProtocolVersions() throws Exception {
    request = HttpRequestWrapper.wrap(
            new BasicHttpRequest("GET", "/foo", new ProtocolVersion("HTTP", 1, 2)));
    request.removeHeaders("Connection");
    request.addHeader("X-Unknown-Header", "some-value");

    final HttpRequestWrapper downgraded = HttpRequestWrapper.wrap(
            new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1));
    downgraded.removeHeaders("Connection");
    downgraded.addHeader("X-Unknown-Header", "some-value");

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.isA(HttpRoute.class),
                    eqRequest(downgraded),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
    replayMocks();

    impl.execute(route, request, context, null);

    verifyMocks();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:25,代码来源:TestProtocolRequirements.java


示例17: testTransferCodingsAreNotSentToAnHTTP_1_0Client

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testTransferCodingsAreNotSentToAnHTTP_1_0Client() throws Exception {

    originResponse.setHeader("Transfer-Encoding", "identity");

    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.assertNull(result.getFirstHeader("TE"));
    Assert.assertNull(result.getFirstHeader("Transfer-Encoding"));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:24,代码来源:TestProtocolRequirements.java


示例18: testOrderOfMultipleHeadersIsPreservedOnRequests

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
private void testOrderOfMultipleHeadersIsPreservedOnRequests(final String h, final HttpRequestWrapper request)
        throws Exception {
    final Capture<HttpRequestWrapper> reqCapture = new Capture<HttpRequestWrapper>();

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.isA(HttpRoute.class),
                    EasyMock.capture(reqCapture),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
    replayMocks();

    impl.execute(route, request, context, null);

    verifyMocks();

    final HttpRequest forwarded = reqCapture.getValue();
    Assert.assertNotNull(forwarded);
    final String expected = HttpTestUtils.getCanonicalHeaderValue(request, h);
    final String actual = HttpTestUtils.getCanonicalHeaderValue(forwarded, h);
    if (!actual.contains(expected)) {
        Assert.assertEquals(expected, actual);
    }

}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestProtocolRequirements.java


示例19: testOrderOfMultipleHeadersIsPreservedOnResponses

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
private void testOrderOfMultipleHeadersIsPreservedOnResponses(final String h) throws Exception {
    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.assertNotNull(result);
    Assert.assertEquals(HttpTestUtils.getCanonicalHeaderValue(originResponse, h), HttpTestUtils
            .getCanonicalHeaderValue(result, h));

}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:19,代码来源:TestProtocolRequirements.java


示例20: testUnknownResponseStatusCodeIsNotCached

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
private void testUnknownResponseStatusCodeIsNotCached(final int code) throws Exception {

        emptyMockCacheExpectsNoPuts();

        originResponse = Proxies.enhanceResponse(
                new BasicHttpResponse(HttpVersion.HTTP_1_1, code, "Moo"));
        originResponse.setHeader("Date", DateUtils.formatDate(new Date()));
        originResponse.setHeader("Server", "MockOrigin/1.0");
        originResponse.setHeader("Cache-Control", "max-age=3600");
        originResponse.setEntity(body);

        EasyMock.expect(
                mockBackend.execute(
                        EasyMock.isA(HttpRoute.class),
                        EasyMock.isA(HttpRequestWrapper.class),
                        EasyMock.isA(HttpClientContext.class),
                        EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

        replayMocks();

        impl.execute(route, request, context, null);

        // in particular, there were no storage calls on the cache
        verifyMocks();
    }
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestProtocolRequirements.java


示例21: testUnknownHeadersOnRequestsAreForwarded

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testUnknownHeadersOnRequestsAreForwarded() throws Exception {
    request.addHeader("X-Unknown-Header", "blahblah");
    final Capture<HttpRequestWrapper> reqCap = new Capture<HttpRequestWrapper>();
    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.isA(HttpRoute.class),
                    EasyMock.capture(reqCap),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();

    impl.execute(route, request, context, null);

    verifyMocks();
    final HttpRequest forwarded = reqCap.getValue();
    final Header[] hdrs = forwarded.getHeaders("X-Unknown-Header");
    Assert.assertEquals(1, hdrs.length);
    Assert.assertEquals("blahblah", hdrs[0].getValue());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestProtocolRequirements.java


示例22: test200ResponseToOPTIONSWithNoBodyShouldIncludeContentLengthZero

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void test200ResponseToOPTIONSWithNoBodyShouldIncludeContentLengthZero() throws Exception {

    request = HttpRequestWrapper.wrap(new BasicHttpRequest("OPTIONS", "/", HttpVersion.HTTP_1_1));
    originResponse.setEntity(null);
    originResponse.setHeader("Content-Length", "0");

    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, request, context, null);

    verifyMocks();
    final Header contentLength = result.getFirstHeader("Content-Length");
    Assert.assertNotNull(contentLength);
    Assert.assertEquals("0", contentLength.getValue());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:TestProtocolRequirements.java


示例23: testDecrementsMaxForwardsWhenForwardingOPTIONSRequest

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testDecrementsMaxForwardsWhenForwardingOPTIONSRequest() throws Exception {

    request = HttpRequestWrapper.wrap(new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1));
    request.setHeader("Max-Forwards", "7");

    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();

    final HttpRequest captured = cap.getValue();
    Assert.assertEquals("6", captured.getFirstHeader("Max-Forwards").getValue());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:TestProtocolRequirements.java


示例24: testFundamentals

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testFundamentals() 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);

    protocolExec.execute(route, request, context, execAware);

    Mockito.verify(httpProcessor).process(request, context);
    Mockito.verify(requestExecutor).execute(route, request, context, execAware);
    Mockito.verify(httpProcessor).process(response, context);

    Assert.assertEquals(new HttpHost("foo", 80), context.getTargetHost());
    Assert.assertEquals(target, context.getTargetHost());
    Assert.assertEquals(route, context.getHttpRoute());
    Assert.assertSame(request, context.getRequest());
    Assert.assertSame(response, context.getResponse());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:27,代码来源:TestProtocolExec.java


示例25: testResponseToAHEADRequestMustNotHaveABody

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testResponseToAHEADRequestMustNotHaveABody() throws Exception {
    request = HttpRequestWrapper.wrap(new BasicHttpRequest("HEAD", "/", HttpVersion.HTTP_1_1));
    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, request, context, null);

    verifyMocks();

    Assert.assertTrue(result.getEntity() == null || result.getEntity().getContentLength() == 0);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:19,代码来源:TestProtocolRequirements.java


示例26: testResponsesToPOSTWithoutCacheControlOrExpiresAreNotCached

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testResponsesToPOSTWithoutCacheControlOrExpiresAreNotCached() throws Exception {
    emptyMockCacheExpectsNoPuts();

    final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/",
            HttpVersion.HTTP_1_1);
    post.setHeader("Content-Length", "128");
    post.setEntity(HttpTestUtils.makeBody(128));

    originResponse.removeHeaders("Cache-Control");
    originResponse.removeHeaders("Expires");

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.isA(HttpRoute.class),
                    EasyMock.isA(HttpRequestWrapper.class),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();

    impl.execute(route, HttpRequestWrapper.wrap(post), context, null);

    verifyMocks();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestProtocolRequirements.java


示例27: testResponsesToPUTsAreNotCached

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testResponsesToPUTsAreNotCached() throws Exception {
    emptyMockCacheExpectsNoPuts();

    final BasicHttpEntityEnclosingRequest put = new BasicHttpEntityEnclosingRequest("PUT", "/",
            HttpVersion.HTTP_1_1);
    put.setEntity(HttpTestUtils.makeBody(128));
    put.addHeader("Content-Length", "128");

    originResponse.setHeader("Cache-Control", "max-age=3600");

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.isA(HttpRoute.class),
                    EasyMock.isA(HttpRequestWrapper.class),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();

    impl.execute(route, HttpRequestWrapper.wrap(put), context, null);

    verifyMocks();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:25,代码来源:TestProtocolRequirements.java


示例28: testResponsesToDELETEsAreNotCached

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testResponsesToDELETEsAreNotCached() throws Exception {
    emptyMockCacheExpectsNoPuts();

    request = HttpRequestWrapper.wrap(new BasicHttpRequest("DELETE", "/", HttpVersion.HTTP_1_1));
    originResponse.setHeader("Cache-Control", "max-age=3600");

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.isA(HttpRoute.class),
                    EasyMock.isA(HttpRequestWrapper.class),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();

    impl.execute(route, request, context, null);

    verifyMocks();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:21,代码来源:TestProtocolRequirements.java


示例29: testResponsesToTRACEsAreNotCached

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testResponsesToTRACEsAreNotCached() throws Exception {
    emptyMockCacheExpectsNoPuts();

    request = HttpRequestWrapper.wrap(new BasicHttpRequest("TRACE", "/", HttpVersion.HTTP_1_1));
    originResponse.setHeader("Cache-Control", "max-age=3600");

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.isA(HttpRoute.class),
                    EasyMock.isA(HttpRequestWrapper.class),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();

    impl.execute(route, request, context, null);

    verifyMocks();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:21,代码来源:TestProtocolRequirements.java


示例30: test204ResponsesDoNotContainMessageBodies

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void test204ResponsesDoNotContainMessageBodies() throws Exception {
    originResponse = Proxies.enhanceResponse(
            new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NO_CONTENT, "No Content"));
    originResponse.setEntity(HttpTestUtils.makeBody(entityLength));

    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.assertTrue(result.getEntity() == null || result.getEntity().getContentLength() == 0);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestProtocolRequirements.java


示例31: testPostProcessRuntimeException

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test(expected = RuntimeException.class)
public void testPostProcessRuntimeException() 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(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;
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestProtocolExec.java


示例32: test303ResponsesAreNotCached

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void test303ResponsesAreNotCached() throws Exception {
    emptyMockCacheExpectsNoPuts();

    request = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));

    originResponse = Proxies.enhanceResponse(
            new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_SEE_OTHER, "See Other"));
    originResponse.setHeader("Date", DateUtils.formatDate(new Date()));
    originResponse.setHeader("Server", "MockServer/1.0");
    originResponse.setHeader("Cache-Control", "max-age=3600");
    originResponse.setHeader("Content-Type", "application/x-cachingclient-test");
    originResponse.setHeader("Location", "http://foo.example.com/other");
    originResponse.setEntity(HttpTestUtils.makeBody(entityLength));

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.isA(HttpRoute.class),
                    EasyMock.isA(HttpRequestWrapper.class),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();
    impl.execute(route, request, context, null);
    verifyMocks();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:27,代码来源:TestProtocolRequirements.java


示例33: test304ResponseWithDateHeaderForwardedFromOriginIncludesDateHeader

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void test304ResponseWithDateHeaderForwardedFromOriginIncludesDateHeader()
        throws Exception {

    request.setHeader("If-None-Match", "\"etag\"");

    originResponse = Proxies.enhanceResponse(
            new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED,
                    "Not Modified"));
    originResponse.setHeader("Date", DateUtils.formatDate(new Date()));
    originResponse.setHeader("Server", "MockServer/1.0");
    originResponse.setHeader("ETag", "\"etag\"");

    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.assertNotNull(result.getFirstHeader("Date"));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:27,代码来源:TestProtocolRequirements.java


示例34: testMustIncludeWWWAuthenticateHeaderOnAnOrigin401Response

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testMustIncludeWWWAuthenticateHeaderOnAnOrigin401Response() throws Exception {
    originResponse = Proxies.enhanceResponse(
            new BasicHttpResponse(HttpVersion.HTTP_1_1, 401, "Unauthorized"));
    originResponse.setHeader("WWW-Authenticate", "x-scheme x-param");

    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);
    if (result.getStatusLine().getStatusCode() == 401) {
        Assert.assertNotNull(result.getFirstHeader("WWW-Authenticate"));
    }

    verifyMocks();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestProtocolRequirements.java


示例35: testMustIncludeProxyAuthenticateHeaderFromAnOrigin407Response

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testMustIncludeProxyAuthenticateHeaderFromAnOrigin407Response() throws Exception {
    originResponse = Proxies.enhanceResponse(
            new BasicHttpResponse(HttpVersion.HTTP_1_1, 407, "Proxy Authentication Required"));
    originResponse.setHeader("Proxy-Authenticate", "x-scheme x-param");

    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);
    if (result.getStatusLine().getStatusCode() == 407) {
        Assert.assertNotNull(result.getFirstHeader("Proxy-Authenticate"));
    }

    verifyMocks();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestProtocolRequirements.java


示例36: testRequestWithWeakETagValidatorIsNotAllowed

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
private HttpResponse testRequestWithWeakETagValidatorIsNotAllowed(final String header)
        throws Exception {
    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).times(0, 1);

    replayMocks();
    final HttpResponse response = impl.execute(route, request, context, null);
    verifyMocks();

    // it's probably ok to return a 400 (Bad Request) to this client
    if (cap.hasCaptured()) {
        final HttpRequest forwarded = cap.getValue();
        final Header h = forwarded.getFirstHeader(header);
        if (h != null) {
            Assert.assertFalse(h.getValue().startsWith("W/"));
        }
    }
    return response;

}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestProtocolRequirements.java


示例37: testDoesNotModifyHeaderOnRequest

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
private void testDoesNotModifyHeaderOnRequest(final String header, final String value) throws Exception {
    final BasicHttpEntityEnclosingRequest req =
        new BasicHttpEntityEnclosingRequest("POST","/",HttpVersion.HTTP_1_1);
    req.setEntity(HttpTestUtils.makeBody(128));
    req.setHeader("Content-Length","128");
    req.setHeader(header,value);

    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, HttpRequestWrapper.wrap(req), context, null);
    verifyMocks();

    final HttpRequest captured = cap.getValue();
    Assert.assertEquals(value, captured.getFirstHeader(header).getValue());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:24,代码来源:TestProtocolRequirements.java


示例38: testViaHeaderOnRequestProperlyRecordsClientProtocol

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testViaHeaderOnRequestProperlyRecordsClientProtocol()
throws Exception {
    request = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_0));
    request.removeHeaders("Via");
    final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.isA(HttpRoute.class),
                    EasyMock.capture(cap),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();
    impl.execute(route, request, context, null);
    verifyMocks();

    final HttpRequest captured = cap.getValue();
    final String via = captured.getFirstHeader("Via").getValue();
    final String protocol = via.split("\\s+")[0];
    final String[] protoParts = protocol.split("/");
    if (protoParts.length > 1) {
        Assert.assertTrue("http".equalsIgnoreCase(protoParts[0]));
    }
    Assert.assertEquals("1.0",protoParts[protoParts.length-1]);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:27,代码来源:TestProtocolRequirements.java


示例39: testProperlyFormattedViaHeaderIsAddedToRequests

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Test
public void testProperlyFormattedViaHeaderIsAddedToRequests() throws Exception {
    final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
    request.removeHeaders("Via");
    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.isA(HttpRoute.class),
                    EasyMock.capture(cap),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();
    impl.execute(route, request, context, null);
    verifyMocks();

    final HttpRequest captured = cap.getValue();
    final String via = captured.getFirstHeader("Via").getValue();
    assertValidViaHeader(via);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:20,代码来源:TestProtocolRequirements.java


示例40: execute

import org.apache.http.client.methods.HttpExecutionAware; //导入依赖的package包/类
@Override
public CloseableHttpResponse execute(
    HttpRoute route,
    HttpRequestWrapper request,
    HttpClientContext clientContext,
    HttpExecutionAware execAware) throws IOException, HttpException {

  ActiveSpan localSpan = clientContext.getAttribute(ACTIVE_SPAN, ActiveSpan.class);
  CloseableHttpResponse response = null;
  try {
    if (localSpan == null) {
      localSpan = handleLocalSpan(request, clientContext);
    }

    return (response = handleNetworkProcessing(localSpan, route, request, clientContext, execAware));
  } catch (Exception e) {
    localSpan.deactivate();
    throw e;
  } finally {
    if (response != null) {
      /**
       * This exec runs after {@link org.apache.http.impl.execchain.RedirectExec} which loops
       * until there is no redirect or reaches max redirect count.
       * {@link RedirectStrategy} is used to decide whether localSpan should be finished or not.
       * If there is a redirect localSpan is not finished and redirect is logged.
       */
      Integer redirectCount = clientContext.getAttribute(REDIRECT_COUNT, Integer.class);
      if (!redirectHandlingDisabled &&
          clientContext.getRequestConfig().isRedirectsEnabled() &&
          redirectStrategy.isRedirected(request, response, clientContext) &&
          ++redirectCount < clientContext.getRequestConfig().getMaxRedirects()) {

        clientContext.setAttribute(REDIRECT_COUNT, redirectCount);
      } else {
        localSpan.deactivate();
      }
    }
  }
}
 
开发者ID:opentracing-contrib,项目名称:java-apache-httpclient,代码行数:40,代码来源:TracingClientExec.java



注:本文中的org.apache.http.client.methods.HttpExecutionAware类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。