• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java HttpAsyncResponseConsumer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



HttpAsyncResponseConsumer类属于org.apache.http.nio.protocol包,在下文中一共展示了HttpAsyncResponseConsumer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testTooLargeResponse

import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testTooLargeResponse() throws Exception {
    ContentTooLongException tooLong = new ContentTooLongException("too long!");
    CloseableHttpAsyncClient httpClient = mock(CloseableHttpAsyncClient.class);
    when(httpClient.<HttpResponse>execute(any(HttpAsyncRequestProducer.class), any(HttpAsyncResponseConsumer.class),
            any(HttpClientContext.class), any(FutureCallback.class))).then(new Answer<Future<HttpResponse>>() {
        @Override
        public Future<HttpResponse> answer(InvocationOnMock invocationOnMock) throws Throwable {
            HeapBufferedAsyncResponseConsumer consumer = (HeapBufferedAsyncResponseConsumer) invocationOnMock.getArguments()[1];
            FutureCallback callback = (FutureCallback) invocationOnMock.getArguments()[3];
            assertEquals(new ByteSizeValue(100, ByteSizeUnit.MB).bytesAsInt(), consumer.getBufferLimit());
            callback.failed(tooLong);
            return null;
        }
    });
    RemoteScrollableHitSource source = sourceWithMockedClient(true, httpClient);

    AtomicBoolean called = new AtomicBoolean();
    Consumer<Response> checkResponse = r -> called.set(true);
    Throwable e = expectThrows(RuntimeException.class,
            () -> source.doStartNextScroll(FAKE_SCROLL_ID, timeValueMillis(0), checkResponse));
    // Unwrap the some artifacts from the test
    while (e.getMessage().equals("failed")) {
        e = e.getCause();
    }
    // This next exception is what the user sees
    assertEquals("Remote responded with a chunk that was too large. Use a smaller batch size.", e.getMessage());
    // And that exception is reported as being caused by the underlying exception returned by the client
    assertSame(tooLong, e.getCause());
    assertFalse(called.get());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:RemoteScrollableHitSourceTests.java


示例2: testInternalHttpRequest

import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; //导入依赖的package包/类
/**
 * Verifies the content of the {@link HttpRequest} that's internally created and passed through to the http client
 */
@SuppressWarnings("unchecked")
public void testInternalHttpRequest() throws Exception {
    ArgumentCaptor<HttpAsyncRequestProducer> requestArgumentCaptor = ArgumentCaptor.forClass(HttpAsyncRequestProducer.class);
    int times = 0;
    for (String httpMethod : getHttpMethods()) {
        HttpUriRequest expectedRequest = performRandomRequest(httpMethod);
        verify(httpClient, times(++times)).<HttpResponse>execute(requestArgumentCaptor.capture(),
                any(HttpAsyncResponseConsumer.class), any(HttpClientContext.class), any(FutureCallback.class));
        HttpUriRequest actualRequest = (HttpUriRequest)requestArgumentCaptor.getValue().generateRequest();
        assertEquals(expectedRequest.getURI(), actualRequest.getURI());
        assertEquals(expectedRequest.getClass(), actualRequest.getClass());
        assertArrayEquals(expectedRequest.getAllHeaders(), actualRequest.getAllHeaders());
        if (expectedRequest instanceof HttpEntityEnclosingRequest) {
            HttpEntity expectedEntity = ((HttpEntityEnclosingRequest) expectedRequest).getEntity();
            if (expectedEntity != null) {
                HttpEntity actualEntity = ((HttpEntityEnclosingRequest) actualRequest).getEntity();
                assertEquals(EntityUtils.toString(expectedEntity), EntityUtils.toString(actualEntity));
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:RestClientSingleHostTests.java


示例3: createRestClient

import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; //导入依赖的package包/类
@Before
@SuppressWarnings("unchecked")
public void createRestClient() throws IOException {
    CloseableHttpAsyncClient httpClient = mock(CloseableHttpAsyncClient.class);
    when(httpClient.<HttpResponse>execute(any(HttpAsyncRequestProducer.class), any(HttpAsyncResponseConsumer.class),
           any(HttpClientContext.class), any(FutureCallback.class))).thenAnswer(new Answer<Future<HttpResponse>>() {
        @Override
        public Future<HttpResponse> answer(InvocationOnMock invocationOnMock) throws Throwable {
            HttpAsyncRequestProducer requestProducer = (HttpAsyncRequestProducer) invocationOnMock.getArguments()[0];
            HttpUriRequest request = (HttpUriRequest)requestProducer.generateRequest();
            HttpHost httpHost = requestProducer.getTarget();
            HttpClientContext context = (HttpClientContext) invocationOnMock.getArguments()[2];
            assertThat(context.getAuthCache().get(httpHost), instanceOf(BasicScheme.class));
            FutureCallback<HttpResponse> futureCallback = (FutureCallback<HttpResponse>) invocationOnMock.getArguments()[3];
            //return the desired status code or exception depending on the path
            if (request.getURI().getPath().equals("/soe")) {
                futureCallback.failed(new SocketTimeoutException(httpHost.toString()));
            } else if (request.getURI().getPath().equals("/coe")) {
                futureCallback.failed(new ConnectTimeoutException(httpHost.toString()));
            } else if (request.getURI().getPath().equals("/ioe")) {
                futureCallback.failed(new IOException(httpHost.toString()));
            } else {
                int statusCode = Integer.parseInt(request.getURI().getPath().substring(1));
                StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("http", 1, 1), statusCode, "");
                futureCallback.completed(new BasicHttpResponse(statusLine));
            }
            return null;
        }
    });
    int numHosts = RandomNumbers.randomIntBetween(getRandom(), 2, 5);
    httpHosts = new HttpHost[numHosts];
    for (int i = 0; i < numHosts; i++) {
        httpHosts[i] = new HttpHost("localhost", 9200 + i);
    }
    failureListener = new HostsTrackingFailureListener();
    restClient = new RestClient(httpClient, 10000, new Header[0], httpHosts, null, failureListener);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:RestClientMultipleHostsTests.java


示例4: makeConsumers

import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public List<HttpAsyncResponseConsumer> makeConsumers(List<HttpAsyncResponseConsumer> list) {

    List<HttpAsyncResponseConsumer> ls = new ArrayList<HttpAsyncResponseConsumer>();

    for (HttpAsyncResponseConsumer r : list) {
        ls.add(makeConsumer(r));
    }

    return ls;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:12,代码来源:ApacheAsyncHttpClientIT.java


示例5: executeRequest

import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; //导入依赖的package包/类
private Future<Response> executeRequest(Request request, HttpRequestBase method, HttpContext context, HTTPCallback<HttpResponse> callback) {
    if (request.isDownload()) {
        HttpAsyncRequestProducer producer = HttpAsyncMethods.create(method);
        HttpAsyncResponseConsumer<HttpResponse> consumer = new BasicAsyncResponseConsumer();
        return executeRequest(producer, consumer, context, callback);
    } else
        return executeRequest(method, context, callback);
}
 
开发者ID:mercadolibre,项目名称:java-restclient,代码行数:9,代码来源:HTTPCAsyncClient.java


示例6: executeAsync

import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; //导入依赖的package包/类
private <T> Future<T> executeAsync(HttpUriRequest request, HttpAsyncResponseConsumer<T> consumer) {
    if(this.auth != null) {
        this.auth.authenticateRequest(request);
    }
    request.addHeader("User-Agent", HttpClient.userAgent);
    HttpHost target = new HttpHost(request.getURI().getHost(), request.getURI().getPort());
    return client.execute(new BasicAsyncRequestProducer(target, request), consumer, null);
}
 
开发者ID:algorithmiaio,项目名称:algorithmia-java,代码行数:9,代码来源:HttpClient.java


示例7: createHttpAsyncResponseConsumer

import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; //导入依赖的package包/类
@Override
public HttpAsyncResponseConsumer<HttpResponse> createHttpAsyncResponseConsumer() {
    return new HeapBufferedAsyncResponseConsumer(bufferLimit);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:HttpAsyncResponseConsumerFactory.java


示例8: get

import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; //导入依赖的package包/类
public <T> Future<T> get(String path, HttpAsyncResponseConsumer<T> consumer) {
    final HttpGet request = new HttpGet(getUrl(path));
    return this.executeAsync(request, consumer);
}
 
开发者ID:algorithmiaio,项目名称:algorithmia-java,代码行数:5,代码来源:HttpClient.java


示例9: post

import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; //导入依赖的package包/类
public <T> Future<T> post(String path, HttpEntity data, HttpAsyncResponseConsumer<T> consumer) {
    return post(getUrl(path), data, consumer, null);
}
 
开发者ID:algorithmiaio,项目名称:algorithmia-java,代码行数:4,代码来源:HttpClient.java


示例10: put

import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; //导入依赖的package包/类
public <T> Future<T> put(String path, HttpEntity data, HttpAsyncResponseConsumer<T> consumer) {
    final HttpPut request = new HttpPut(getUrl(path));
    request.setEntity(data);
    return this.executeAsync(request, consumer);
}
 
开发者ID:algorithmiaio,项目名称:algorithmia-java,代码行数:6,代码来源:HttpClient.java


示例11: delete

import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; //导入依赖的package包/类
public <T> Future<T> delete(String path, HttpAsyncResponseConsumer<T> consumer) {
    final HttpDelete request = new HttpDelete(getUrl(path));
    return executeAsync(request, consumer);
}
 
开发者ID:algorithmiaio,项目名称:algorithmia-java,代码行数:5,代码来源:HttpClient.java


示例12: head

import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; //导入依赖的package包/类
public <T> Future<T> head(String path, HttpAsyncResponseConsumer<T> consumer) {
    final HttpHead request = new HttpHead(getUrl(path));
    return executeAsync(request, consumer);
}
 
开发者ID:algorithmiaio,项目名称:algorithmia-java,代码行数:5,代码来源:HttpClient.java


示例13: execute

import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; //导入依赖的package包/类
@Override
public Future<HttpResponse> execute(final HttpAsyncClient httpClient) throws FileNotFoundException {
    final HttpAsyncResponseConsumer<HttpResponse> consumer = new BasicAsyncResponseConsumer();
    final HttpAsyncRequestProducer producer = this.getProducer();
    return httpClient.execute(producer, consumer, null);
}
 
开发者ID:mwaylabs,项目名称:relution-jenkins-plugin,代码行数:7,代码来源:ZeroCopyFileRequest.java


示例14: retryOperation

import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; //导入依赖的package包/类
/**
 * Retries given HTTP request. Called internally only, from the HttpFuture
 *
 * @param httpUriRequest the HttpUriRequest to retry
 * @param responseConsumer the response consumer
 * @return the resulting Future<HttpResponse> instance
 */
Future<HttpResponse> retryOperation( HttpUriRequest httpUriRequest, HttpAsyncResponseConsumer<HttpResponse> responseConsumer ) {
    return responseConsumer == null ? asyncClient.execute( httpUriRequest, null ) : asyncClient.execute( HttpAsyncMethods.create( httpUriRequest ), responseConsumer, null, null );
}
 
开发者ID:tenable,项目名称:Tenable.io-SDK-for-Java,代码行数:11,代码来源:AsyncHttpService.java


示例15: HttpFuture

import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; //导入依赖的package包/类
/**
 * Instantiates a new Http future.
 *
 * @param asyncHttpService   async http service instance
 * @param httpUriRequest     the http uri request
 * @param responseConsumer   the response consumer
 * @param httpResponseFuture the http response future
 * @param body               the body
 */
public HttpFuture( AsyncHttpService asyncHttpService, HttpUriRequest httpUriRequest, HttpAsyncResponseConsumer<HttpResponse> responseConsumer, Future<HttpResponse> httpResponseFuture, String body ) {
    this( asyncHttpService, httpUriRequest, httpResponseFuture, body );
    this.responseConsumer = responseConsumer;
}
 
开发者ID:tenable,项目名称:Tenable.io-SDK-for-Java,代码行数:14,代码来源:HttpFuture.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CSSNode类代码示例发布时间:2022-05-22
下一篇:
Java Option类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap