當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpClientContext.setTargetHost方法代碼示例

本文整理匯總了Java中org.apache.http.client.protocol.HttpClientContext.setTargetHost方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientContext.setTargetHost方法的具體用法?Java HttpClientContext.setTargetHost怎麽用?Java HttpClientContext.setTargetHost使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.client.protocol.HttpClientContext的用法示例。


在下文中一共展示了HttpClientContext.setTargetHost方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testDoesNotSetConnectionInContextOnCacheHit

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
@Test
public void testDoesNotSetConnectionInContextOnCacheHit() throws Exception {
    final DummyBackend backend = new DummyBackend();
    final HttpResponse response = HttpTestUtils.make200Response();
    response.setHeader("Cache-Control", "max-age=3600");
    backend.setResponse(response);
    impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
    final HttpClientContext ctx = HttpClientContext.create();
    ctx.setTargetHost(host);
    impl.execute(route, request, context, null);
    impl.execute(route, request, ctx, null);
    assertNull(ctx.getConnection());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:14,代碼來源:TestCachingExecChain.java

示例2: testSetsTargetHostInContextOnCacheHit

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
@Test
public void testSetsTargetHostInContextOnCacheHit() throws Exception {
    final DummyBackend backend = new DummyBackend();
    final HttpResponse response = HttpTestUtils.make200Response();
    response.setHeader("Cache-Control", "max-age=3600");
    backend.setResponse(response);
    impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
    final HttpClientContext ctx = HttpClientContext.create();
    ctx.setTargetHost(host);
    impl.execute(route, request, context, null);
    impl.execute(route, request, ctx, null);
    assertSame(host, ctx.getTargetHost());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:14,代碼來源:TestCachingExecChain.java

示例3: testSetsRouteInContextOnCacheHit

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
@Test
public void testSetsRouteInContextOnCacheHit() throws Exception {
    final DummyBackend backend = new DummyBackend();
    final HttpResponse response = HttpTestUtils.make200Response();
    response.setHeader("Cache-Control", "max-age=3600");
    backend.setResponse(response);
    impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
    final HttpClientContext ctx = HttpClientContext.create();
    ctx.setTargetHost(host);
    impl.execute(route, request, context, null);
    impl.execute(route, request, ctx, null);
    assertEquals(route, ctx.getHttpRoute());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:14,代碼來源:TestCachingExecChain.java

示例4: testSetsRequestInContextOnCacheHit

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
@Test
public void testSetsRequestInContextOnCacheHit() throws Exception {
    final DummyBackend backend = new DummyBackend();
    final HttpResponse response = HttpTestUtils.make200Response();
    response.setHeader("Cache-Control", "max-age=3600");
    backend.setResponse(response);
    impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
    final HttpClientContext ctx = HttpClientContext.create();
    ctx.setTargetHost(host);
    impl.execute(route, request, context, null);
    impl.execute(route, request, ctx, null);
    if (!HttpTestUtils.equivalent(request, ctx.getRequest())) {
        assertSame(request, ctx.getRequest());
    }
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:16,代碼來源:TestCachingExecChain.java

示例5: testSetsResponseInContextOnCacheHit

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
@Test
public void testSetsResponseInContextOnCacheHit() throws Exception {
    final DummyBackend backend = new DummyBackend();
    final HttpResponse response = HttpTestUtils.make200Response();
    response.setHeader("Cache-Control", "max-age=3600");
    backend.setResponse(response);
    impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
    final HttpClientContext ctx = HttpClientContext.create();
    ctx.setTargetHost(host);
    impl.execute(route, request, context, null);
    final HttpResponse result = impl.execute(route, request, ctx, null);
    if (!HttpTestUtils.equivalent(result, ctx.getResponse())) {
        assertSame(result, ctx.getResponse());
    }
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:16,代碼來源:TestCachingExecChain.java

示例6: testSetsRequestSentInContextOnCacheHit

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
@Test
public void testSetsRequestSentInContextOnCacheHit() throws Exception {
    final DummyBackend backend = new DummyBackend();
    final HttpResponse response = HttpTestUtils.make200Response();
    response.setHeader("Cache-Control", "max-age=3600");
    backend.setResponse(response);
    impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
    final HttpClientContext ctx = HttpClientContext.create();
    ctx.setTargetHost(host);
    impl.execute(route, request, context, null);
    impl.execute(route, request, ctx, null);
    assertTrue(ctx.isRequestSent());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:14,代碼來源:TestCachingExecChain.java

示例7: testIssue1147

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
@Test
public void testIssue1147() throws Exception {
    final CacheConfig cacheConfig = CacheConfig.custom()
        .setSharedCache(true)
        .setMaxObjectSize(262144) //256kb
        .build();

    final ResourceFactory resourceFactory = new FileResourceFactory(cacheDir);
    final HttpCacheStorage httpCacheStorage = new ManagedHttpCacheStorage(cacheConfig);

    final ClientExecChain backend = mock(ClientExecChain.class);
    final HttpRequestWrapper get = HttpRequestWrapper.wrap(new HttpGet("http://somehost/"));
    final HttpClientContext context = HttpClientContext.create();
    final HttpHost target = new HttpHost("somehost", 80);
    final HttpRoute route = new HttpRoute(target);

    context.setTargetHost(target);

    final Date now = new Date();
    final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);

    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
    response.setEntity(HttpTestUtils.makeBody(128));
    response.setHeader("Content-Length", "128");
    response.setHeader("ETag", "\"etag\"");
    response.setHeader("Cache-Control", "public, max-age=3600");
    response.setHeader("Last-Modified", DateUtils.formatDate(tenSecondsAgo));

    when(backend.execute(
            eq(route),
            isA(HttpRequestWrapper.class),
            isA(HttpClientContext.class),
            (HttpExecutionAware) Matchers.isNull())).thenReturn(Proxies.enhanceResponse(response));

    final BasicHttpCache cache = new BasicHttpCache(resourceFactory, httpCacheStorage, cacheConfig);
    final ClientExecChain t = createCachingExecChain(backend, cache, cacheConfig);

    final HttpResponse response1 = t.execute(route, get, context, null);
    Assert.assertEquals(200, response1.getStatusLine().getStatusCode());
    IOUtils.consume(response1.getEntity());

    verify(backend).execute(
            eq(route),
            isA(HttpRequestWrapper.class),
            isA(HttpClientContext.class),
            (HttpExecutionAware) Matchers.isNull());

    removeCache();

    reset(backend);
    when(backend.execute(
            eq(route),
            isA(HttpRequestWrapper.class),
            isA(HttpClientContext.class),
            (HttpExecutionAware) Matchers.isNull())).thenReturn(Proxies.enhanceResponse(response));

    final HttpResponse response2 = t.execute(route, get, context, null);
    Assert.assertEquals(200, response2.getStatusLine().getStatusCode());
    IOUtils.consume(response2.getEntity());

    verify(backend).execute(
            eq(route),
            isA(HttpRequestWrapper.class),
            isA(HttpClientContext.class),
            (HttpExecutionAware) Matchers.isNull());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:67,代碼來源:TestHttpCacheJiraNumber1147.java


注:本文中的org.apache.http.client.protocol.HttpClientContext.setTargetHost方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。