Java Code Examples for io.undertow.util.StatusCodes#BAD_REQUEST
The following examples show how to use
io.undertow.util.StatusCodes#BAD_REQUEST .
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 lams with GNU General Public License v2.0 | 6 votes |
/** * 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: SimpleErrorPageHandler.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public boolean handleDefaultResponse(final HttpServerExchange exchange) { if (!exchange.isResponseChannelAvailable()) { return false; } Set<Integer> codes = responseCodes; if (codes == null ? exchange.getStatusCode() >= StatusCodes.BAD_REQUEST : codes.contains(Integer.valueOf(exchange.getStatusCode()))) { final String errorPage = "<html><head><title>Error</title></head><body>" + exchange.getStatusCode() + " - " + StatusCodes.getReason(exchange.getStatusCode()) + "</body></html>"; exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, "" + errorPage.length()); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html"); Sender sender = exchange.getResponseSender(); sender.send(errorPage); return true; } return false; }
Example 3
Source File: HttpErrorLoggerExtension.java From hawkular-metrics with Apache License 2.0 | 6 votes |
@Override public void exchangeEvent(HttpServerExchange exchange, ExchangeCompletionListener.NextListener nextListener) { int httpStatusCode = exchange.getStatusCode(); if (httpStatusCode >= StatusCodes.BAD_REQUEST) { final String path; final String query = exchange.getQueryString(); if (!query.isEmpty()) { path = exchange.getRequestPath() + "?" + query; } else { path = exchange.getRequestPath(); } HttpString method = exchange.getRequestMethod(); log.warnf("Endpoint %s %s fails with HTTP code: %d", method, path, httpStatusCode); } nextListener.proceed(); }
Example 4
Source File: Response.java From mangooio with Apache License 2.0 | 2 votes |
/** * Creates a response object with HTTP status code 400 * * @return A response object {@link io.mangoo.routing.Response} */ public static Response withBadRequest() { return new Response(StatusCodes.BAD_REQUEST); }