Search in sources :

Example 46 with HttpClientRequest

use of io.vertx.core.http.HttpClientRequest in project parser-excel-elasticsearch by codingchili.

the class ElasticWriter method post.

private HttpClientRequest post(String path) {
    HttpClientRequest client = vertx.createHttpClient().post(getOptions(path));
    addHeaders(client);
    return client;
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest)

Example 47 with HttpClientRequest

use of io.vertx.core.http.HttpClientRequest in project parser-excel-elasticsearch by codingchili.

the class ElasticWriter method delete.

private HttpClientRequest delete(String path) {
    HttpClientRequest request = vertx.createHttpClient().delete(getOptions(path));
    addHeaders(request);
    return request;
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest)

Example 48 with HttpClientRequest

use of io.vertx.core.http.HttpClientRequest in project vertx-micrometer-metrics by vert-x3.

the class PrometheusMetricsITest method shouldExposeEventBusMetrics.

@Test
public void shouldExposeEventBusMetrics(TestContext context) {
    vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true).setStartEmbeddedServer(true).setEmbeddedServerOptions(new HttpServerOptions().setPort(9090))).setEnabled(true)));
    // Send something on the eventbus and wait til it's received
    Async asyncEB = context.async();
    vertx.eventBus().consumer("test-eb", msg -> asyncEB.complete());
    vertx.eventBus().publish("test-eb", "test message");
    asyncEB.await(2000);
    // Read metrics on HTTP endpoint for eventbus metrics
    Async async = context.async();
    HttpClientRequest req = vertx.createHttpClient().get(9090, "localhost", "/metrics").handler(res -> {
        context.assertEquals(200, res.statusCode());
        res.bodyHandler(body -> {
            String str = body.toString();
            context.verify(v -> assertThat(str).contains("vertx_eventbus_published_total{address=\"test-eb\",side=\"local\",} 1.0", "vertx_eventbus_received_total{address=\"test-eb\",side=\"local\",} 1.0", "vertx_eventbus_handlers{address=\"test-eb\",} 1.0", "vertx_eventbus_delivered_total{address=\"test-eb\",side=\"local\",} 1.0", "vertx_eventbus_processingTime_seconds_count{address=\"test-eb\",} 1.0"));
            async.complete();
        });
    });
    req.end();
    async.awaitSuccess(10000);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) Async(io.vertx.ext.unit.Async) HttpServerOptions(io.vertx.core.http.HttpServerOptions) VertxOptions(io.vertx.core.VertxOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) Test(org.junit.Test)

Example 49 with HttpClientRequest

use of io.vertx.core.http.HttpClientRequest in project vertx-micrometer-metrics by vert-x3.

the class PrometheusMetricsITest method tryConnect.

private static void tryConnect(Vertx vertx, TestContext context, int port, String host, String requestURI, Consumer<String> bodyReader, int attempt) {
    HttpClientRequest req = vertx.createHttpClient().get(port, host, requestURI).handler(res -> {
        context.assertEquals(200, res.statusCode());
        res.bodyHandler(body -> bodyReader.accept(body.toString()));
    }).exceptionHandler(e -> {
        if (attempt < 10) {
            System.out.println(e);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
            System.out.println("retrying...");
            tryConnect(vertx, context, port, host, requestURI, bodyReader, attempt + 1);
        } else {
            System.out.println("aborting");
        }
    });
    req.end();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Vertx(io.vertx.core.Vertx) RunWith(org.junit.runner.RunWith) VertxOptions(io.vertx.core.VertxOptions) Router(io.vertx.ext.web.Router) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) MetricsDomain(io.vertx.micrometer.MetricsDomain) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) BackendRegistries(io.vertx.micrometer.backends.BackendRegistries) Consumer(java.util.function.Consumer) HttpClientRequest(io.vertx.core.http.HttpClientRequest) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) After(org.junit.After) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClientRequest(io.vertx.core.http.HttpClientRequest)

Example 50 with HttpClientRequest

use of io.vertx.core.http.HttpClientRequest in project okapi by folio-org.

the class ProxyService method proxyHeaders.

private void proxyHeaders(Iterator<ModuleInstance> it, ProxyContext pc, ReadStream<Buffer> stream, Buffer bcontent, ModuleInstance mi) {
    RoutingContext ctx = pc.getCtx();
    HttpClientRequest cReq = httpClient.requestAbs(ctx.request().method(), makeUrl(mi, ctx), res -> {
        if (res.statusCode() < 200 || res.statusCode() >= 300) {
            proxyResponseImmediate(pc, res, mi);
            if (bcontent == null) {
                stream.resume();
            }
        } else if (it.hasNext()) {
            relayToRequest(res, pc, mi);
            makeTraceHeader(mi, res.statusCode(), pc);
            res.endHandler(x -> proxyR(it, pc, stream, bcontent));
        } else {
            relayToResponse(ctx.response(), res);
            makeTraceHeader(mi, res.statusCode(), pc);
            if (bcontent == null) {
                stream.handler(data -> {
                    ctx.response().write(data);
                    pc.trace("ProxyHeaders request chunk '" + data.toString() + "'");
                });
                stream.endHandler(v -> {
                    ctx.response().end();
                    pc.trace("ProxyHeaders request end");
                });
                stream.exceptionHandler(e -> pc.warn("proxyHeaders: content exception ", e));
                stream.resume();
            } else {
                pc.trace("ProxyHeaders request buf '" + bcontent + "'");
                ctx.response().end(bcontent);
            }
        }
    });
    cReq.exceptionHandler(e -> {
        pc.warn("proxyHeaders failure: " + mi.getUrl() + ": ", e);
        pc.responseText(500, "proxyHeaders failure: " + mi.getModuleDescriptor().getId() + " " + mi.getUrl() + ": " + e + " " + e.getMessage());
    });
    cReq.headers().setAll(ctx.request().headers());
    cReq.headers().remove("Content-Length");
    cReq.end();
    log(pc, cReq);
}
Also used : HttpServerRequest(io.vertx.core.http.HttpServerRequest) Json(io.vertx.core.json.Json) Arrays(java.util.Arrays) ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) XOkapiHeaders(org.folio.okapi.common.XOkapiHeaders) NOT_FOUND(org.folio.okapi.common.ErrorType.NOT_FOUND) MultiMap(io.vertx.core.MultiMap) OkapiToken(org.folio.okapi.common.OkapiToken) HashMap(java.util.HashMap) Random(java.util.Random) RoutingContext(io.vertx.ext.web.RoutingContext) Tenant(org.folio.okapi.bean.Tenant) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OkapiClient(org.folio.okapi.common.OkapiClient) OkapiLogger(org.folio.okapi.common.OkapiLogger) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientResponse(io.vertx.core.http.HttpClientResponse) Matcher(java.util.regex.Matcher) DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor) ProxyType(org.folio.okapi.bean.RoutingEntry.ProxyType) Map(java.util.Map) RoutingEntry(org.folio.okapi.bean.RoutingEntry) ProxyContext(org.folio.okapi.util.ProxyContext) ReadStream(io.vertx.core.streams.ReadStream) DiscoveryManager(org.folio.okapi.discovery.DiscoveryManager) ExtendedAsyncResult(org.folio.okapi.common.ExtendedAsyncResult) JsonObject(io.vertx.core.json.JsonObject) Failure(org.folio.okapi.common.Failure) InternalModule(org.folio.okapi.web.InternalModule) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Logger(io.vertx.core.logging.Logger) USER(org.folio.okapi.common.ErrorType.USER) Iterator(java.util.Iterator) Vertx(io.vertx.core.Vertx) Set(java.util.Set) Success(org.folio.okapi.common.Success) ModuleInstance(org.folio.okapi.bean.ModuleInstance) List(java.util.List) INTERNAL(org.folio.okapi.common.ErrorType.INTERNAL) Buffer(io.vertx.core.buffer.Buffer) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerResponse(io.vertx.core.http.HttpServerResponse) DropwizardHelper(org.folio.okapi.util.DropwizardHelper) Pattern(java.util.regex.Pattern) Handler(io.vertx.core.Handler) Comparator(java.util.Comparator) HttpClient(io.vertx.core.http.HttpClient) RoutingContext(io.vertx.ext.web.RoutingContext) HttpClientRequest(io.vertx.core.http.HttpClientRequest)

Aggregations

HttpClientRequest (io.vertx.core.http.HttpClientRequest)159 Test (org.junit.Test)82 Buffer (io.vertx.core.buffer.Buffer)73 HttpClient (io.vertx.core.http.HttpClient)56 HttpMethod (io.vertx.core.http.HttpMethod)51 HttpClientOptions (io.vertx.core.http.HttpClientOptions)50 HttpClientResponse (io.vertx.core.http.HttpClientResponse)42 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)42 Handler (io.vertx.core.Handler)40 HttpServerResponse (io.vertx.core.http.HttpServerResponse)40 CompletableFuture (java.util.concurrent.CompletableFuture)38 CountDownLatch (java.util.concurrent.CountDownLatch)36 TimeUnit (java.util.concurrent.TimeUnit)36 Vertx (io.vertx.core.Vertx)35 HttpServerOptions (io.vertx.core.http.HttpServerOptions)35 ArrayList (java.util.ArrayList)35 List (java.util.List)35 AtomicReference (java.util.concurrent.atomic.AtomicReference)34 MultiMap (io.vertx.core.MultiMap)33 HttpVersion (io.vertx.core.http.HttpVersion)31