Java Code Examples for io.vertx.ext.web.RoutingContext#currentRoute()

The following examples show how to use io.vertx.ext.web.RoutingContext#currentRoute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HonoBasicAuthHandler.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void parseCredentials(final RoutingContext context, final Handler<AsyncResult<JsonObject>> handler) {
    // In case of exception due to malformed authorisation header, Vertx BasicAuthHandlerImpl invokes
    // context.fail(e) thereby the DefaultFailureHandler is being invoked. This sends http status code 500
    // instead of 400. To resolve this, the RoutingContextDecorator is used. The overridden fail(Throwable) method
    // ensures that http status code 400 is returned.
    final RoutingContextDecorator routingContextDecorator = new RoutingContextDecorator(context.currentRoute(),
            context) {

        @Override
        public void fail(final Throwable throwable) {
            HttpUtils.badRequest(context, "Malformed authorization header");
        }
    };
    super.parseCredentials(routingContextDecorator, ar -> {
        if (ar.succeeded()) {
            final SpanContext spanContext = TracingHandler.serverSpanContext(context);
            if (spanContext != null && !(spanContext instanceof NoopSpanContext)) {
                TracingHelper.injectSpanContext(tracer, spanContext, ar.result());
            }
        }
        handler.handle(ar);
    });
}
 
Example 2
Source File: BlockingHandlerDecorator.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(RoutingContext context) {
  Route currentRoute = context.currentRoute();
  context.vertx().executeBlocking(fut -> {
    decoratedHandler.handle(new RoutingContextDecorator(currentRoute, context));
    fut.complete();
  }, ordered, res -> {
    if (res.failed()) {
      // This means an exception was thrown from the blocking handler
      context.fail(res.cause());
    }
  });
}
 
Example 3
Source File: SockJSPushHandler.java    From vertx-vaadin with MIT License 4 votes vote down vote up
SockJSRoutingContext(RoutingContext source, Handler<RoutingContext> action) {
    super(source.currentRoute(), source);
    this.action = action;
}
 
Example 4
Source File: SockJSPushHandler.java    From vertx-vaadin with MIT License 4 votes vote down vote up
SockJSRoutingContext(RoutingContext source, Handler<RoutingContext> action) {
    super(source.currentRoute(), source);
    this.action = action;
}