Example usage for io.vertx.core.http HttpHeaders HOST

List of usage examples for io.vertx.core.http HttpHeaders HOST

Introduction

In this page you can find the example usage for io.vertx.core.http HttpHeaders HOST.

Prototype

CharSequence HOST

To view the source code for io.vertx.core.http HttpHeaders HOST.

Click Source Link

Document

Host header name

Usage

From source file:org.hawkular.metrics.clients.ptrans.backend.MetricsSender.java

License:Apache License

private void send(List<SingleMetric> metrics) {
    connectionsUsed++;/*  w ww  .  j  a v  a2 s . co m*/
    String json = Batcher.metricListToJson(metrics);
    Buffer data = Buffer.buffer(json);
    HttpClientRequest req = httpClient.post(postUri, response -> {
        connectionsUsed--;
        if (response.statusCode() != 200) {
            if (log.isTraceEnabled()) {
                response.bodyHandler(msg -> {
                    log.trace("Could not send metrics: " + response.statusCode() + " : " + msg.toString());
                });
            }
            buffer.reInsert(metrics);
            metricInserted();
        } else {
            scheduleFlush();
        }
    });
    req.putHeader(HttpHeaders.HOST, hostHeader);
    req.putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(data.length()));
    req.putHeader(HttpHeaders.CONTENT_TYPE, Constants.APPLICATION_JSON);
    req.putHeader(Constants.TENANT_HEADER_NAME, tenant);
    req.exceptionHandler(err -> {
        connectionsUsed--;
        log.trace("Could not send metrics", err);
        buffer.reInsert(metrics);
        metricInserted();
    });
    req.write(data);
    req.end();
}