Search in sources :

Example 1 with RESTService

use of in.erail.service.RESTService in project api-framework by vinscom.

the class OpenAPI3RouteBuilder method getRouter.

@Override
public Router getRouter(Router pRouter) {
    OpenAPI3RouterFactory apiFactory = OpenAPI3RouterFactory.rxCreateRouterFactoryFromFile(getVertx(), getOpenAPI3File().getAbsolutePath()).blockingGet();
    getServices().getServices().forEach((api) -> {
        RESTService service = (RESTService) api;
        apiFactory.addHandlerByOperationId(service.getOperationId(), (routingContext) -> {
            routingContext.put(FrameworkConstants.RoutingContext.Attribute.BODY_AS_JSON, service.isBodyAsJson());
            if (isSecurityEnable()) {
                if (routingContext.user() == null) {
                    routingContext.fail(401);
                    return;
                }
                routingContext.user().isAuthorized(AUTHORIZATION_PREFIX + ":" + service.getOperationId(), (event) -> {
                    boolean authSuccess = event.succeeded() ? event.result() : false;
                    if (authSuccess) {
                        process(routingContext, service.getServiceUniqueId());
                    } else {
                        routingContext.fail(401);
                    }
                });
            } else {
                getLog().warn("Security disabled for " + service.getServiceUniqueId());
                process(routingContext, service.getServiceUniqueId());
            }
        });
    });
    return apiFactory.getRouter();
}
Also used : RESTService(in.erail.service.RESTService) OpenAPI3RouterFactory(io.vertx.reactivex.ext.web.api.contract.openapi3.OpenAPI3RouterFactory)

Example 2 with RESTService

use of in.erail.service.RESTService in project api-framework by vinscom.

the class OpenAPI3RouteBuilder method start.

@StartService
public void start() {
    getServices().getServices().stream().forEach((api) -> {
        RESTService service = (RESTService) api;
        getMetricTimers().put(service.getServiceUniqueId(), getMetricRegistry().timer("api.framework.service." + service.getServiceUniqueId()));
    });
}
Also used : RESTService(in.erail.service.RESTService) StartService(in.erail.glue.annotation.StartService)

Aggregations

RESTService (in.erail.service.RESTService)2 StartService (in.erail.glue.annotation.StartService)1 OpenAPI3RouterFactory (io.vertx.reactivex.ext.web.api.contract.openapi3.OpenAPI3RouterFactory)1