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());
}
});
}
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);
}
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()));
}
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();
}
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;
}
Aggregations