类org.apache.http.nio.protocol.HttpAsyncResponseConsumer源码实例Demo

下面列出了怎么用org.apache.http.nio.protocol.HttpAsyncResponseConsumer的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: log4j2-elasticsearch   文件: HttpClientTest.java
@Test
public void executeAsyncDelegatesToConfiguredAsyncClient() {

    // given
    HttpClient client = Mockito.spy(createDefaultTestObject());
    CloseableHttpAsyncClient asyncClient = mockAsyncClient(client);

    BatchRequest request = createDefaultTestBatchRequest();

    // when
    client.executeAsync(request, createMockTestResultHandler());

    // then
    verify(client).getAsyncClient();
    verify(asyncClient).execute(
            any(HttpAsyncRequestProducer.class),
            any(HttpAsyncResponseConsumer.class),
            any(HttpContext.class),
            any(FutureCallback.class));

}
 
源代码2 项目: brave   文件: TracingHttpAsyncClientBuilder.java
@Override public <T> Future<T> execute(HttpAsyncRequestProducer requestProducer,
  HttpAsyncResponseConsumer<T> responseConsumer, HttpContext httpContext,
  FutureCallback<T> callback) {

  TraceContext invocationContext = currentTraceContext.get();
  if (invocationContext != null) {
    httpContext.setAttribute(TraceContext.class.getName(), invocationContext);
  }

  return delegate.execute(
    new TracingAsyncRequestProducer(requestProducer, httpContext),
    new TracingAsyncResponseConsumer<>(responseConsumer, httpContext),
    httpContext,
    callback != null && invocationContext != null
      ? new TraceContextFutureCallback<>(callback, currentTraceContext, invocationContext)
      : callback
  );
}
 
private StreamingReadAsyncClient(final URI uri, final KinesisVideoSigner signer, final String inputInJson, final Integer connectionTimeoutInMillis, final Integer readTimeoutInMillis, final HttpAsyncResponseConsumer<HttpResponse> httpAsyncResponseConsumer, final FutureCallback<HttpResponse> futureCallback) {
    this.uri = uri;
    this.signer = signer;
    this.inputInJson = inputInJson;
    this.connectionTimeoutInMillis = connectionTimeoutInMillis;
    this.readTimeoutInMillis = readTimeoutInMillis;
    this.httpAsyncResponseConsumer = httpAsyncResponseConsumer;
    this.futureCallback = futureCallback;
    this.asyncClient = getHttpClient();
}
 
源代码4 项目: uavstack   文件: ApacheAsyncHttpClientIT.java
@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;
}
 
@Test
public void producesPoolingAsyncResponseConsumer() {

    // given
    PoolingAsyncResponseConsumerFactory factory = createAsyncResponseConsumerFactory();

    // when
    HttpAsyncResponseConsumer result = factory.create();

    // then
    assertTrue(result instanceof PoolingAsyncResponseConsumer);
}
 
源代码6 项目: skywalking   文件: HttpAsyncClientInterceptor.java
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    HttpAsyncResponseConsumer consumer = (HttpAsyncResponseConsumer) allArguments[1];
    HttpContext context = (HttpContext) allArguments[2];
    FutureCallback callback = (FutureCallback) allArguments[3];
    allArguments[1] = new HttpAsyncResponseConsumerWrapper(consumer);
    allArguments[3] = new FutureCallbackWrapper(callback);
    CONTEXT_LOCAL.set(context);
}
 
public Builder withHttpAsyncResponseConsumer(final HttpAsyncResponseConsumer<HttpResponse> 
                  httpAsyncResponseConsumer) {
    mHttpAsyncResponseConsumer = httpAsyncResponseConsumer;
    return this;
}
 
@Override
public HttpAsyncResponseConsumer<HttpResponse> create() {
    return new PoolingAsyncResponseConsumer(pool);
}
 
public LogbookHttpAsyncResponseConsumer(final HttpAsyncResponseConsumer<T> consumer) {
    this.consumer = consumer;
}
 
源代码10 项目: logbook   文件: LogbookHttpAsyncResponseConsumer.java
@Override
protected HttpAsyncResponseConsumer<T> delegate() {
    return consumer;
}
 
@Override
protected HttpAsyncResponseConsumer delegate() {
    return delegate;
}
 
@Test
void shouldWrapIOException() throws IOException {
    final HttpAsyncResponseConsumer<HttpResponse> unit = new LogbookHttpAsyncResponseConsumer<>(createConsumer());

    final BasicHttpContext context = new BasicHttpContext();
    context.setAttribute(Attributes.STAGE, stage);

    final ResponseWritingStage last = mock(ResponseWritingStage.class);

    when(stage.process(any())).thenReturn(last);

    doThrow(new IOException()).when(last).write();

    assertThrows(UncheckedIOException.class, () ->
            unit.responseCompleted(context));
}
 
public HttpAsyncResponseConsumerWrapper(HttpAsyncResponseConsumer<T> consumer) {
    this.consumer = consumer;
}
 
private Thread baseTest() throws Throwable {
    Object[] allArguments = new Object[] {
        producer,
        consumer,
        httpContext,
        callback
    };
    Class[] types = new Class[] {
        HttpAsyncRequestProducer.class,
        HttpAsyncResponseConsumer.class,
        HttpContext.class,
        FutureCallback.class
    };
    httpAsyncClientInterceptor.beforeMethod(enhancedInstance, null, allArguments, types, null);
    Assert.assertEquals(CONTEXT_LOCAL.get(), httpContext);
    Assert.assertTrue(allArguments[1] instanceof HttpAsyncResponseConsumerWrapper);
    Assert.assertTrue(allArguments[3] instanceof FutureCallbackWrapper);

    sessionRequestConstructorInterceptor.onConstruct(enhancedInstance, null);

    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                //start local
                completeInterceptor.beforeMethod(enhancedInstance, null, null, null, null);
                //start request
                requestExecutorInterceptor.beforeMethod(enhancedInstance, null, null, null, null);

                HttpAsyncResponseConsumerWrapper consumerWrapper = new HttpAsyncResponseConsumerWrapper(consumer);

                consumerWrapper.responseReceived(response);

                new FutureCallbackWrapper(callback).completed(null);

            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
        }
    });
    thread.start();
    return thread;
}
 
源代码15 项目: brave   文件: TracingHttpAsyncClientBuilder.java
TracingAsyncResponseConsumer(HttpAsyncResponseConsumer<T> responseConsumer,
  HttpContext context) {
  this.responseConsumer = responseConsumer;
  this.context = context;
}
 
源代码16 项目: Tenable.io-SDK-for-Java   文件: AsyncHttpService.java
/**
 * Retries given HTTP request. Called internally only, from the HttpFuture
 *
 * @param httpUriRequest the HttpUriRequest to retry
 * @param responseConsumer the response consumer
 * @param numRetry The retry count
 * @return the resulting Future<HttpResponse> instance
 */
Future<HttpResponse> retryOperation( HttpUriRequest httpUriRequest, HttpAsyncResponseConsumer<HttpResponse> responseConsumer, int numRetry ) {
    httpUriRequest.setHeader( "X-Tio-Retry-Count", Integer.toString( numRetry ) );
    return responseConsumer == null ? asyncClient.execute( httpUriRequest, null ) : asyncClient.execute( HttpAsyncMethods.create( httpUriRequest ), responseConsumer, null, null );
}
 
源代码17 项目: Tenable.io-SDK-for-Java   文件: HttpFuture.java
/**
 * 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;
}
 
HttpAsyncResponseConsumer<HttpResponse> create(); 
protected abstract HttpAsyncResponseConsumer<T> delegate(); 
 类所在包
 类方法
 同包方法