本文整理汇总了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());
}
示例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());
}
示例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());
}
示例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());
}
}
示例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());
}
}
示例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());
}
示例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());
}