Search in sources :

Example 1 with RouterBuilder

use of io.vertx.ext.web.openapi.RouterBuilder in project strimzi-kafka-bridge by strimzi.

the class HttpBridge method start.

@Override
public void start(Promise<Void> startPromise) {
    RouterBuilder.create(vertx, "openapi.json", ar -> {
        if (ar.succeeded()) {
            RouterBuilder routerBuilder = ar.result();
            routerBuilder.operation(this.SEND.getOperationId().toString()).handler(this.SEND);
            routerBuilder.operation(this.SEND_TO_PARTITION.getOperationId().toString()).handler(this.SEND_TO_PARTITION);
            routerBuilder.operation(this.CREATE_CONSUMER.getOperationId().toString()).handler(this.CREATE_CONSUMER);
            routerBuilder.operation(this.DELETE_CONSUMER.getOperationId().toString()).handler(this.DELETE_CONSUMER);
            routerBuilder.operation(this.SUBSCRIBE.getOperationId().toString()).handler(this.SUBSCRIBE);
            routerBuilder.operation(this.UNSUBSCRIBE.getOperationId().toString()).handler(this.UNSUBSCRIBE);
            routerBuilder.operation(this.LIST_SUBSCRIPTIONS.getOperationId().toString()).handler(this.LIST_SUBSCRIPTIONS);
            routerBuilder.operation(this.ASSIGN.getOperationId().toString()).handler(this.ASSIGN);
            routerBuilder.operation(this.POLL.getOperationId().toString()).handler(this.POLL);
            routerBuilder.operation(this.COMMIT.getOperationId().toString()).handler(this.COMMIT);
            routerBuilder.operation(this.SEEK.getOperationId().toString()).handler(this.SEEK);
            routerBuilder.operation(this.SEEK_TO_BEGINNING.getOperationId().toString()).handler(this.SEEK_TO_BEGINNING);
            routerBuilder.operation(this.SEEK_TO_END.getOperationId().toString()).handler(this.SEEK_TO_END);
            routerBuilder.operation(this.LIST_TOPICS.getOperationId().toString()).handler(this.LIST_TOPICS);
            routerBuilder.operation(this.GET_TOPIC.getOperationId().toString()).handler(this.GET_TOPIC);
            routerBuilder.operation(this.LIST_PARTITIONS.getOperationId().toString()).handler(this.LIST_PARTITIONS);
            routerBuilder.operation(this.GET_PARTITION.getOperationId().toString()).handler(this.GET_PARTITION);
            routerBuilder.operation(this.GET_OFFSETS.getOperationId().toString()).handler(this.GET_OFFSETS);
            routerBuilder.operation(this.HEALTHY.getOperationId().toString()).handler(this.HEALTHY);
            routerBuilder.operation(this.READY.getOperationId().toString()).handler(this.READY);
            routerBuilder.operation(this.OPENAPI.getOperationId().toString()).handler(this.OPENAPI);
            routerBuilder.operation(this.INFO.getOperationId().toString()).handler(this.INFO);
            if (this.bridgeConfig.getHttpConfig().isCorsEnabled()) {
                routerBuilder.rootHandler(getCorsHandler());
            }
            this.router = routerBuilder.createRouter();
            // handling validation errors and not existing endpoints
            this.router.errorHandler(HttpResponseStatus.BAD_REQUEST.code(), this::errorHandler);
            this.router.errorHandler(HttpResponseStatus.NOT_FOUND.code(), this::errorHandler);
            this.router.route("/metrics").handler(this::metricsHandler);
            log.info("Starting HTTP-Kafka bridge verticle...");
            this.httpBridgeContext = new HttpBridgeContext<>();
            AdminClientEndpoint adminClientEndpoint = new HttpAdminClientEndpoint(this.vertx, this.bridgeConfig, this.httpBridgeContext);
            this.httpBridgeContext.setAdminClientEndpoint(adminClientEndpoint);
            adminClientEndpoint.open();
            this.bindHttpServer(startPromise);
        } else {
            log.error("Failed to create OpenAPI router factory");
            startPromise.fail(ar.cause());
        }
    });
}
Also used : AdminClientEndpoint(io.strimzi.kafka.bridge.AdminClientEndpoint) RouterBuilder(io.vertx.ext.web.openapi.RouterBuilder)

Example 2 with RouterBuilder

use of io.vertx.ext.web.openapi.RouterBuilder in project DroneSecurity by mirko-felice.

the class CourierShippingService method start.

@Override
public void start(@NotNull final Promise<Void> startPromise) {
    final Router globalRouter = Router.router(this.getVertx());
    RouterBuilder.create(this.getVertx(), OPEN_API_URL).onSuccess(routerBuilder -> {
        this.setupOperations(routerBuilder);
        final JsonArray servers = routerBuilder.getOpenAPI().getOpenAPI().getJsonArray("servers");
        final int serversCount = servers.size();
        final List<Future<?>> futures = new ArrayList<>(serversCount);
        for (int i = 0; i < serversCount; i++) {
            final JsonObject server = servers.getJsonObject(i);
            final JsonObject variables = server.getJsonObject("variables");
            final String basePath = SEP + variables.getJsonObject("basePath").getString(DEFAULT_KEY);
            final int port = Integer.parseInt(variables.getJsonObject("port").getString(DEFAULT_KEY));
            final String host = variables.getJsonObject("host").getString(DEFAULT_KEY);
            globalRouter.route(basePath).subRouter(routerBuilder.createRouter());
            futures.add(this.getVertx().createHttpServer().requestHandler(globalRouter).listen(port, host));
        }
        CompositeFuture.all(Arrays.asList(futures.toArray(new Future[0]))).onSuccess(ignored -> startPromise.complete());
    }).onFailure(startPromise::fail);
}
Also used : Json(io.vertx.core.json.Json) Connection(it.unibo.dronesecurity.lib.Connection) Arrays(java.util.Arrays) RequestParameters(io.vertx.ext.web.validation.RequestParameters) Router(io.vertx.ext.web.Router) PlacedOrder(it.unibo.dronesecurity.userapplication.shipping.courier.entities.PlacedOrder) RoutingContext(io.vertx.ext.web.RoutingContext) OrderConstants(it.unibo.dronesecurity.userapplication.shipping.courier.utilities.OrderConstants) CastHelper(it.unibo.dronesecurity.userapplication.utilities.CastHelper) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) MqttTopicConstants(it.unibo.dronesecurity.lib.MqttTopicConstants) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonObject(io.vertx.core.json.JsonObject) MqttMessageParameterConstants(it.unibo.dronesecurity.lib.MqttMessageParameterConstants) RouterBuilder(io.vertx.ext.web.openapi.RouterBuilder) ValidationHandler(io.vertx.ext.web.validation.ValidationHandler) MqttMessageValueConstants(it.unibo.dronesecurity.lib.MqttMessageValueConstants) DeliveringOrder(it.unibo.dronesecurity.userapplication.shipping.courier.entities.DeliveringOrder) Promise(io.vertx.core.Promise) OrderRepository(it.unibo.dronesecurity.userapplication.shipping.courier.repo.OrderRepository) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Future(io.vertx.core.Future) StandardCharsets(java.nio.charset.StandardCharsets) JsonArray(io.vertx.core.json.JsonArray) MqttMessage(software.amazon.awssdk.crt.mqtt.MqttMessage) List(java.util.List) AbstractVerticle(io.vertx.core.AbstractVerticle) NotNull(org.jetbrains.annotations.NotNull) JsonArray(io.vertx.core.json.JsonArray) Router(io.vertx.ext.web.Router) JsonObject(io.vertx.core.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with RouterBuilder

use of io.vertx.ext.web.openapi.RouterBuilder in project neonbee by SAP.

the class AbstractOpenAPIEndpointTest method testCreateEndpointRouter.

@Test
@DisplayName("createEndpointRouter should succeed")
void testCreateEndpointRouter(Vertx vertx, VertxTestContext testContext) {
    Checkpoint methodsCheckpoint = testContext.checkpoint(2);
    Checkpoint succeedingCheckpoint = testContext.checkpoint();
    DummyOpenAPIEndpoint dummyEndpoint = new DummyOpenAPIEndpoint() {

        @Override
        protected Future<String> getOpenAPIContractURL(Vertx vertx, JsonObject config) {
            methodsCheckpoint.flag();
            return succeededFuture(CONTRACT_PATH.toString());
        }

        @Override
        protected Future<Router> createRouter(Vertx vertx, RouterBuilder routerBuilder) {
            methodsCheckpoint.flag();
            return super.createRouter(vertx, routerBuilder);
        }
    };
    dummyEndpoint.createEndpointRouter(vertx, null, null).onComplete(testContext.succeeding(router -> succeedingCheckpoint.flag()));
}
Also used : Future.succeededFuture(io.vertx.core.Future.succeededFuture) VertxTestContext(io.vertx.junit5.VertxTestContext) TEST_RESOURCES(io.neonbee.test.helper.ResourceHelper.TEST_RESOURCES) Vertx(io.vertx.core.Vertx) Router(io.vertx.ext.web.Router) Truth.assertThat(com.google.common.truth.Truth.assertThat) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) RouterBuilderException(io.vertx.ext.web.openapi.RouterBuilderException) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) EndpointConfig(io.neonbee.config.EndpointConfig) JsonObject(io.vertx.core.json.JsonObject) Checkpoint(io.vertx.junit5.Checkpoint) RouterBuilder(io.vertx.ext.web.openapi.RouterBuilder) Path(java.nio.file.Path) Checkpoint(io.vertx.junit5.Checkpoint) JsonObject(io.vertx.core.json.JsonObject) Router(io.vertx.ext.web.Router) Vertx(io.vertx.core.Vertx) RouterBuilder(io.vertx.ext.web.openapi.RouterBuilder) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with RouterBuilder

use of io.vertx.ext.web.openapi.RouterBuilder in project web3signer by ConsenSys.

the class Eth1Runner method populateRouter.

@Override
protected Router populateRouter(final Context context) {
    final RouterBuilder routerBuilder = context.getRouterBuilder();
    final LogErrorHandler errorHandler = context.getErrorHandler();
    final ArtifactSignerProvider signerProvider = context.getArtifactSignerProvider();
    addPublicKeysListHandler(routerBuilder, signerProvider, ETH1_LIST.name(), context.getErrorHandler());
    final SignerForIdentifier<SecpArtifactSignature> secpSigner = new SignerForIdentifier<>(signerProvider, this::formatSecpSignature, SECP256K1);
    routerBuilder.operation(ETH1_SIGN.name()).handler(new BlockingHandlerDecorator(new Eth1SignForIdentifierHandler(secpSigner, new HttpApiMetrics(context.getMetricsSystem(), SECP256K1)), false)).failureHandler(errorHandler);
    addReloadHandler(routerBuilder, signerProvider, RELOAD.name(), context.getErrorHandler());
    return context.getRouterBuilder().createRouter();
}
Also used : SignerForIdentifier(tech.pegasys.web3signer.core.service.http.handlers.signing.SignerForIdentifier) BlockingHandlerDecorator(io.vertx.ext.web.impl.BlockingHandlerDecorator) SecpArtifactSignature(tech.pegasys.web3signer.signing.SecpArtifactSignature) RouterBuilder(io.vertx.ext.web.openapi.RouterBuilder) ArtifactSignerProvider(tech.pegasys.web3signer.signing.ArtifactSignerProvider) DefaultArtifactSignerProvider(tech.pegasys.web3signer.signing.config.DefaultArtifactSignerProvider) Eth1SignForIdentifierHandler(tech.pegasys.web3signer.core.service.http.handlers.signing.Eth1SignForIdentifierHandler) HttpApiMetrics(tech.pegasys.web3signer.core.service.http.metrics.HttpApiMetrics) LogErrorHandler(tech.pegasys.web3signer.core.service.http.handlers.LogErrorHandler)

Example 5 with RouterBuilder

use of io.vertx.ext.web.openapi.RouterBuilder in project web3signer by ConsenSys.

the class Runner method getRouterBuilder.

public static RouterBuilder getRouterBuilder(final Vertx vertx, final String specUrl) throws InterruptedException, ExecutionException {
    final CompletableFuture<RouterBuilder> completableFuture = new CompletableFuture<>();
    RouterBuilder.create(vertx, specUrl, ar -> {
        if (ar.succeeded()) {
            completableFuture.complete(ar.result());
        } else {
            completableFuture.completeExceptionally(ar.cause());
        }
    });
    final RouterBuilder routerBuilder = completableFuture.get();
    // disable automatic response content handler as it doesn't handle some corner cases.
    // Our handlers must set content type header manually.
    routerBuilder.getOptions().setMountResponseContentTypeHandler(false);
    // vertx-json-schema fails to createRouter for unknown string type formats
    routerBuilder.getSchemaParser().withStringFormatValidator("uint64", Runner::validateUInt64);
    return routerBuilder;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RouterBuilder(io.vertx.ext.web.openapi.RouterBuilder)

Aggregations

RouterBuilder (io.vertx.ext.web.openapi.RouterBuilder)9 Router (io.vertx.ext.web.Router)6 JsonObject (io.vertx.core.json.JsonObject)5 HttpServer (io.vertx.core.http.HttpServer)4 RequestParameters (io.vertx.ext.web.validation.RequestParameters)4 AbstractVerticle (io.vertx.core.AbstractVerticle)3 Future (io.vertx.core.Future)3 Promise (io.vertx.core.Promise)3 Vertx (io.vertx.core.Vertx)3 HttpServerOptions (io.vertx.core.http.HttpServerOptions)3 JsonArray (io.vertx.core.json.JsonArray)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 List (java.util.List)3 HttpHeaders (io.vertx.core.http.HttpHeaders)2 SelfSignedCertificate (io.vertx.core.net.SelfSignedCertificate)2 ValidationHandler (io.vertx.ext.web.validation.ValidationHandler)2 Path (java.nio.file.Path)2 Optional (java.util.Optional)2 Logger (org.slf4j.Logger)2