Java Code Examples for io.undertow.server.HttpServerExchange#isComplete()

The following examples show how to use io.undertow.server.HttpServerExchange#isComplete() . 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: ServletAuthenticationCallHandler.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
/**
 * Only allow the request through if successfully authenticated or if authentication is not required.
 *
 * @see io.undertow.server.HttpHandler#handleRequest(io.undertow.server.HttpServerExchange)
 */
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    if(exchange.isInIoThread()) {
        exchange.dispatch(this);
        return;
    }
    SecurityContext context = exchange.getSecurityContext();
    if (context.authenticate()) {
        if(!exchange.isComplete()) {
           next.handleRequest(exchange);
        }
    } else {
        if(exchange.getStatusCode() >= StatusCodes.BAD_REQUEST && !exchange.isComplete()) {
            ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
            src.getOriginalResponse().sendError(exchange.getStatusCode());
        } else {
            exchange.endExchange();
        }
    }
}
 
Example 2
Source File: AuthenticationCallHandler.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
/**
 * Only allow the request through if successfully authenticated or if authentication is not required.
 *
 * @see io.undertow.server.HttpHandler#handleRequest(io.undertow.server.HttpServerExchange)
 */
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    if(exchange.isInIoThread()) {
        exchange.dispatch(this);
        return;
    }
    SecurityContext context = exchange.getSecurityContext();
    if (context.authenticate()) {
        if(!exchange.isComplete()) {
           next.handleRequest(exchange);
        }
    } else {
        exchange.endExchange();
    }
}
 
Example 3
Source File: TracingHttpHandlerConfiguration.java    From pivotal-bank-demo with Apache License 2.0 6 votes vote down vote up
@Override public void handleRequest(HttpServerExchange exchange) throws Exception {
  if (!exchange.isComplete()) {
    Span span = serverHandler.handleReceive(extractor, exchange.getRequestHeaders(), exchange);
    exchange.addExchangeCompleteListener((exch, nextListener) -> {
      try {
        nextListener.proceed();
      } finally {
        serverHandler.handleSend(exch, exch.getAttachment(ExceptionHandler.THROWABLE), span);
      }
    });
    try (Scope scope = currentTraceContext.newScope(span.context())) {
      next.handleRequest(exchange);
    } catch (Exception | Error e) { // move the error to where the complete listener can see it
      exchange.putAttachment(ExceptionHandler.THROWABLE, e);
      throw e;
    }
  } else {
    next.handleRequest(exchange);
  }
}
 
Example 4
Source File: AuthenticationCallHandler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Only allow the request through if successfully authenticated or if authentication is not required.
 *
 * @see io.undertow.server.HttpHandler#handleRequest(io.undertow.server.HttpServerExchange)
 */
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    if(exchange.isInIoThread()) {
        exchange.dispatch(this);
        return;
    }
    SecurityContext context = exchange.getSecurityContext();
    if (context.authenticate()) {
        if(!exchange.isComplete()) {
           next.handleRequest(exchange);
        }
    } else {
        exchange.endExchange();
    }
}
 
Example 5
Source File: ServletAuthenticationCallHandler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Only allow the request through if successfully authenticated or if authentication is not required.
 *
 * @see io.undertow.server.HttpHandler#handleRequest(io.undertow.server.HttpServerExchange)
 */
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    if(exchange.isInIoThread()) {
        exchange.dispatch(this);
        return;
    }
    SecurityContext context = exchange.getSecurityContext();
    if (context.authenticate()) {
        if(!exchange.isComplete()) {
           next.handleRequest(exchange);
        }
    } else {
        if(exchange.getStatusCode() >= StatusCodes.BAD_REQUEST && !exchange.isComplete()) {
            ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
            src.getOriginalResponse().sendError(exchange.getStatusCode());
        } else {
            exchange.endExchange();
        }
    }
}
 
Example 6
Source File: ManagementHttpRequestHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    final boolean proceed = service.beginRequest();
    try {
        if (proceed) {
            next.handleRequest(exchange);
        } else {
            exchange.setStatusCode(503);
            exchange.endExchange();
        }
    } finally {
        if (proceed && (exchange.isComplete() || !exchange.isDispatched())) {
            service.endRequest();
        } else if (proceed) {
            exchange.addExchangeCompleteListener(listener);
        }
    }
}
 
Example 7
Source File: MetricsHandler.java    From mangooio with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    if (!exchange.isComplete()) {
        exchange.addExchangeCompleteListener(new MetricsListener(System.currentTimeMillis()));
    }
    this.nextHandler.handleRequest(exchange);
}