private < T > CompletionStage < T > executeRequest ( HttpAsyncClient httpClient , HttpUriRequest httpRequest , JsonParser < T > parser ) { CompletableFuture < T > future = new CompletableFuture <> ( ) ; httpClient . execute ( httpRequest , new FutureCallback < HttpResponse > ( ) { @ Override public void failed ( Exception e ) { future . completeExceptionally ( e ) ; } @ Override public void completed ( HttpResponse response ) { int statusCode = response . getStatusLine ( ) . getStatusCode ( ) ; if ( statusCode == HttpStatus . SC_OK || statusCode == HttpStatus . SC_ACCEPTED ) { // Parse result type from the returned JSON try { T result = parser . parse ( response . getEntity ( ) . getContent ( ) ) ; future . complete ( result ) ; } catch ( Exception e ) { future . completeExceptionally ( e ) ; } } else { future . completeExceptionally ( createSaltException ( statusCode ) ) ; } } @ Override public void cancelled ( ) { future . cancel ( false ) ; } } ) ; return future ; }
Executes a prepared HTTP request using the given client .