@Override
    public void sendHttpRequest(final HttpRequest request) {

        checkClosed();

        if (trace) {
            logger.debug(sputs("HTTP CLIENT: sendHttpRequest:: \n{}\n", request, "\nparams\n", request.params()));
        }

        final String uri = getURICreateParamsIfNeeded(request);

        final HttpMethod httpMethod = HttpMethod.valueOf(request.getMethod());

        final HttpClientRequest httpClientRequest = httpClient.request(
                httpMethod, uri,
                httpClientResponse -> handleResponse(request, httpClientResponse));

        final MultiMap<String, String> headers = request.getHeaders();

        httpClientRequest.exceptionHandler(error -> {

            if (error instanceof ConnectException) {
                closed.set(true);
                try {
                    stop();
                } catch (Exception ex) {

                    errorHandler.accept(ex);
                    logger.warn("Unable to stop client " +
                            "after failed connection", ex);
                }
                request.getReceiver().errorWithCode("\"Client connection was closed\"", HttpStatus.SERVICE_UNAVAILABLE);
                logger.warn("Connection error", error);
            } else {
                logger.error("Unable to connect to " + host + " port " + port, error);
            }

            errorHandler.accept(error);
        });

        if (headers != null) {

            for (String key : headers.keySet()) {
                httpClientRequest.putHeader(key, headers.getAll(key));
            }
        }

        final byte[] body = request.getBody();

        if (keepAlive) {
            httpClientRequest.putHeader(HttpHeaders.CONNECTION, HttpHeaders.KEEP_ALIVE);
        }

        if (body != null && body.length > 0) {


            httpClientRequest.putHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(body.length));
            if (request.getContentType() != null) {


                httpClientRequest.putHeader("Content-Type", request.getContentType());
            }
            httpClientRequest.end(Buffer.buffer(request.getBody()));

        } else {
            httpClientRequest.end();
        }

        if (trace) logger.trace("HttpClientVertx::SENT \n{}", request);

    }
@Override
    public void sendHttpRequest(final HttpRequest request) {

        checkClosed();

        if (trace) {
            logger.debug(sputs("HTTP CLIENT: sendHttpRequest:: \n{}\n", request, "\nparams\n", request.params()));
        }

        final String uri = getURICreateParamsIfNeeded(request);

        final HttpMethod httpMethod = HttpMethod.valueOf(request.getMethod());

        final HttpClientRequest httpClientRequest = httpClient.request(
                httpMethod, uri,
                httpClientResponse -> handleResponse(request, httpClientResponse));

        final MultiMap<String, String> headers = request.getHeaders();

        httpClientRequest.exceptionHandler(error -> {

            if (error instanceof ConnectException) {
                closed.set(true);
                try {
                    stop();
                } catch (Exception ex) {

                    errorHandler.accept(ex);
                    logger.warn("Unable to stop client " +
                            "after failed connection", ex);
                }
                request.getReceiver().errorWithCode("\"Client connection was closed\"", HttpStatus.SERVICE_UNAVAILABLE);
                logger.warn("Connection error", error);
            } else {
                logger.error("Unable to connect to " + host + " port " + port, error);
            }

            errorHandler.accept(error);
        });

        if (headers != null) {

            for (String key : headers.keySet()) {
                httpClientRequest.putHeader(key, headers.getAll(key));
            }
        }

        final byte[] body = request.getBody();

        if (keepAlive) {
            httpClientRequest.putHeader(HttpHeaders.CONNECTION, HttpHeaders.KEEP_ALIVE);
        }

        if (body != null && body.length > 0) {


            httpClientRequest.putHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(body.length));
            if (request.getContentType() != null) {


                httpClientRequest.putHeader("Content-Type", request.getContentType());
            }
            httpClientRequest.end(Buffer.buffer(request.getBody()));

        } else {
            httpClientRequest.end();
        }

        if (trace) logger.trace("HttpClientVertx::SENT \n{}", request);

    }
@ Override public void sendHttpRequest ( final HttpRequest request ) { checkClosed ( ) ; if ( trace ) { logger . debug ( sputs ( "HTTP CLIENT: sendHttpRequest:: \n{}\n" , request , "\nparams\n" , request . params ( ) ) ) ; } final String uri = getURICreateParamsIfNeeded ( request ) ; final HttpMethod httpMethod = HttpMethod . valueOf ( request . getMethod ( ) ) ; final HttpClientRequest httpClientRequest = httpClient . request ( httpMethod , uri , httpClientResponse -> handleResponse ( request , httpClientResponse ) ) ; final MultiMap < String , String > headers = request . getHeaders ( ) ; httpClientRequest . exceptionHandler ( error -> { if ( error instanceof ConnectException ) { closed . set ( true ) ; try { stop ( ) ; } catch ( Exception ex ) { errorHandler . accept ( ex ) ; logger . warn ( "Unable to stop client " + "after failed connection" , ex ) ; } request . getReceiver ( ) . errorWithCode ( "\"Client connection was closed\"" , HttpStatus . SERVICE_UNAVAILABLE ) ; logger . warn ( "Connection error" , error ) ; } else { logger . error ( "Unable to connect to " + host + " port " + port , error ) ; } errorHandler . accept ( error ) ; } ) ; if ( headers != null ) { for ( String key : headers . keySet ( ) ) { httpClientRequest . putHeader ( key , headers . getAll ( key ) ) ; } } final byte [ ] body = request . getBody ( ) ; if ( keepAlive ) { httpClientRequest . putHeader ( HttpHeaders . CONNECTION , HttpHeaders . KEEP_ALIVE ) ; } if ( body != null && body . length > 0 ) { httpClientRequest . putHeader ( HttpHeaders . CONTENT_LENGTH , Integer . toString ( body . length ) ) ; if ( request . getContentType ( ) != null ) { httpClientRequest . putHeader ( "Content-Type" , request . getContentType ( ) ) ; } httpClientRequest . end ( Buffer . buffer ( request . getBody ( ) ) ) ; } else { httpClientRequest . end ( ) ; } if ( trace ) logger . trace ( "HttpClientVertx::SENT \n{}" , request ) ; }
}
}