org.apache.http.nio.protocol.BasicAsyncResponseConsumer Java Examples
The following examples show how to use
org.apache.http.nio.protocol.BasicAsyncResponseConsumer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpClientFactoryTest.java From log4j2-elasticsearch with Apache License 2.0 | 6 votes |
@Test public void disablingPooledResponseBuffersInitializesClientWithBasicAsyncResponseConsumerFactory() { // given HttpClientFactory.Builder builder = new HttpClientFactory.Builder(); builder.withServerList(TEST_SERVER_LIST) .withMaxTotalConnections(TEST_MAX_TOTAL_CONNECTIONS) .withPooledResponseBuffers(false); HttpClientFactory factory = spy(builder.build()); // when factory.createInstance(); // then ArgumentCaptor<HttpAsyncResponseConsumerFactory> captor = ArgumentCaptor.forClass(HttpAsyncResponseConsumerFactory.class); verify(factory).createConfiguredClient(any(), any(), captor.capture()); assertEquals(BasicAsyncResponseConsumer.class, captor.getValue().create().getClass()); }
Example #2
Source File: HttpClientTest.java From log4j2-elasticsearch with Apache License 2.0 | 6 votes |
@Test public void executeAsyncResponseIsNotPooledIfPoolNotConfigured() { // given HCHttp.Builder testObjectFactoryBuilder = HCHttpTest.createDefaultHttpObjectFactoryBuilder(); testObjectFactoryBuilder.withPooledResponseBuffers(false); HttpClient client = spy(testObjectFactoryBuilder.build().createClient()); CloseableHttpAsyncClient asyncClient = mockAsyncClient(client); BatchRequest request = createDefaultTestBatchRequest(); // when client.executeAsync(request, createMockTestResultHandler()); // then verify(client).getAsyncClient(); verify(asyncClient).execute( any(HttpAsyncRequestProducer.class), asyncConsumerCaptor.capture(), any(HttpContext.class), any(FutureCallback.class)); assertEquals(BasicAsyncResponseConsumer.class, asyncConsumerCaptor.getValue().getClass()); }
Example #3
Source File: JsonRpcHttpAsyncClient.java From jsonrpc4j with MIT License | 5 votes |
/** * Invokes the given method with the given arguments and invokes the * {@code JsonRpcCallback} with the result cast to the given * {@code returnType}, or null if void. The {@code extraHeaders} are added * to the request. * * @param methodName the name of the method to invoke * @param argument the arguments to the method * @param extraHeaders extra headers to add to the request * @param returnType the return type * @param callback the {@code JsonRpcCallback} */ @SuppressWarnings("unchecked") private <T> Future<T> doInvoke(String methodName, Object argument, Class<T> returnType, Map<String, String> extraHeaders, JsonRpcCallback<T> callback) { String path = serviceUrl.getPath() + (serviceUrl.getQuery() != null ? "?" + serviceUrl.getQuery() : ""); int port = serviceUrl.getPort() != -1 ? serviceUrl.getPort() : serviceUrl.getDefaultPort(); HttpRequest request = new BasicHttpEntityEnclosingRequest("POST", path); addHeaders(request, headers); addHeaders(request, extraHeaders); try { writeRequest(methodName, argument, request); } catch (IOException e) { callback.onError(e); } HttpHost target = new HttpHost(serviceUrl.getHost(), port, serviceUrl.getProtocol()); BasicAsyncRequestProducer asyncRequestProducer = new BasicAsyncRequestProducer(target, request); BasicAsyncResponseConsumer asyncResponseConsumer = new BasicAsyncResponseConsumer(); RequestAsyncFuture<T> futureCallback = new RequestAsyncFuture<>(returnType, callback); BasicHttpContext httpContext = new BasicHttpContext(); requester.execute(asyncRequestProducer, asyncResponseConsumer, pool, httpContext, futureCallback); return (callback instanceof JsonRpcFuture ? (Future<T>) callback : null); }