@Test void shouldApplyAllConsumersToCallBeingConstructed() { val httpClient = mock(AsyncHttpClient.class); val rewriteUrl = "http: val headerName = "X-Header"; val headerValue = UUID.randomUUID().toString(); val numCustomized = new AtomicInteger(); val numRequestStart = new AtomicInteger(); val numRequestSuccess = new AtomicInteger(); val numRequestFailure = new AtomicInteger(); Consumer<RequestBuilder> requestCustomizer = requestBuilder -> { requestBuilder.setUrl(rewriteUrl) .setHeader(headerName, headerValue); numCustomized.incrementAndGet(); }; Consumer<AsyncHttpClientCall.AsyncHttpClientCallBuilder> callCustomizer = callBuilder -> callBuilder .requestCustomizer(requestCustomizer) .requestCustomizer(rb -> log.warn("I'm customizing: {}", rb)) .onRequestSuccess(createConsumer(numRequestSuccess)) .onRequestFailure(createConsumer(numRequestFailure)) .onRequestStart(createConsumer(numRequestStart)); val factory = AsyncHttpClientCallFactory.builder() .callCustomizer(callCustomizer) .httpClient(httpClient) .build(); val call = (AsyncHttpClientCall) factory.newCall(REQUEST); val callRequest = call.createRequest(call.request()); assertTrue(numCustomized.get() == 1); assertTrue(numRequestStart.get() == 0); assertTrue(numRequestSuccess.get() == 0); assertTrue(numRequestFailure.get() == 0); assertEquals(callRequest.getUrl(), rewriteUrl); assertEquals(callRequest.getHeaders().get(headerName), headerValue); assertNotNull(call.getOnRequestStart()); assertTrue(call.getOnRequestStart().size() == 1); assertNotNull(call.getOnRequestSuccess()); assertTrue(call.getOnRequestSuccess().size() == 1); assertNotNull(call.getOnRequestFailure()); assertTrue(call.getOnRequestFailure().size() == 1); assertNotNull(call.getRequestCustomizers()); assertTrue(call.getRequestCustomizers().size() == 2); }
@Override public Call newCall(Request request) { val callBuilder = AsyncHttpClientCall.builder() .httpClientSupplier(httpClientSupplier) .request(request); runConsumers(this.callCustomizers, callBuilder); return callBuilder.build(); }
AsyncHttpClientCallFactory implements Call.Factory { @Override public Call newCall(Request request) { val callBuilder = AsyncHttpClientCall.builder() .httpClientSupplier(httpClientSupplier) .request(request); runConsumers(this.callCustomizers, callBuilder); return callBuilder.build(); } }
AsyncHttpClientCallFactory implements Call.Factory { @Override public Call newCall(Request request) { val callBuilder = AsyncHttpClientCall.builder() .httpClientSupplier(httpClientSupplier) .request(request); runConsumers(this.callCustomizers, callBuilder); return callBuilder.build(); }  }
AsyncHttpClientCallFactory implements Call.Factory { @Override public Call newCall(Request request) { val callBuilder = AsyncHttpClientCall.builder() .httpClientSupplier(httpClientSupplier) .request(request); runConsumers(this.callCustomizers, callBuilder); return callBuilder.build(); }  @Override Call newCall(Request request); }
AsyncHttpClientCallFactory implements Call.Factory { @Override public Call newCall(Request request) { val callBuilder = AsyncHttpClientCall.builder() .httpClientSupplier(httpClientSupplier) .request(request); runConsumers(this.callCustomizers, callBuilder); return callBuilder.build(); }  @Override Call newCall(Request request);  }