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

The following examples show how to use io.vertx.ext.web.RoutingContext#addBodyEndHandler() . 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: LoggerHandlerImpl.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(RoutingContext context) {
  // common logging data
  long timestamp = System.currentTimeMillis();
  String remoteClient = getClientAddress(context.request().remoteAddress());
  HttpMethod method = context.request().method();
  String uri = context.request().uri();
  HttpVersion version = context.request().version();

  if (immediate) {
    log(context, timestamp, remoteClient, version, method, uri);
  } else {
    context.addBodyEndHandler(v -> log(context, timestamp, remoteClient, version, method, uri));
  }

  context.next();

}
 
Example 2
Source File: QuarkusJaxRsMetricsFilter.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public void filter(final ContainerRequestContext requestContext) {
    Long start = System.nanoTime();
    final Class<?> resourceClass = resourceInfo.getResourceClass();
    final Method resourceMethod = resourceInfo.getResourceMethod();
    /*
     * The reason for using a Vert.x handler instead of ContainerResponseFilter is that
     * RESTEasy does not call the response filter for requests that ended up with an unmapped exception.
     * This way we can capture these responses as well and update the metrics accordingly.
     */
    RoutingContext routingContext = CDI.current().select(CurrentVertxRequest.class).get().getCurrent();
    routingContext.addBodyEndHandler(
            event -> finishRequest(start, resourceClass, resourceMethod));
}
 
Example 3
Source File: TracingHandler.java    From java-vertx-web with Apache License 2.0 5 votes vote down vote up
protected void handlerFailure(RoutingContext routingContext) {
    Object object = routingContext.get(CURRENT_SPAN);
    if (object instanceof Span) {
        final Span span = (Span)object;
        routingContext.addBodyEndHandler(event -> decorators.forEach(spanDecorator ->
                spanDecorator.onFailure(routingContext.failure(), routingContext.response(), span)));
    }

    routingContext.next();
}
 
Example 4
Source File: SfsSingletonServer.java    From sfs with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(RoutingContext routingContext) {
    routingContext.addBodyEndHandler(event -> {
        HttpServerRequest request = routingContext.request();
        try {
            request.resume();
        } catch (Throwable e) {
            // do nothing
        }
    });
    SfsRequest sfsRequest = new SfsRequest(vertxContext, routingContext.request());
    delegate.handle(sfsRequest);
}
 
Example 5
Source File: TracingHandler.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Handles a failed HTTP request.
 *
 * @param routingContext The routing context for the request.
 */
protected void handlerFailure(final RoutingContext routingContext) {
    final Object object = routingContext.get(CURRENT_SPAN);
    if (object instanceof Span) {
        final Span span = (Span) object;
        routingContext.addBodyEndHandler(event -> decorators.forEach(spanDecorator ->
                spanDecorator.onFailure(routingContext.failure(), routingContext.response(), span)));
    }

    routingContext.next();
}
 
Example 6
Source File: AccessLogHandler.java    From mpns with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(RoutingContext context) {
    long startTime = System.currentTimeMillis();
    context.addBodyEndHandler(event -> log(context, startTime));
    context.next();
}
 
Example 7
Source File: TimeoutHandlerImpl.java    From vertx-web with Apache License 2.0 3 votes vote down vote up
@Override
public void handle(RoutingContext ctx) {

  // We send a error response after timeout
  long tid = ctx.vertx().setTimer(timeout, t -> ctx.fail(errorCode));

  ctx.addBodyEndHandler(v -> ctx.vertx().cancelTimer(tid));

  ctx.next();
}