io.undertow.server.handlers.ExceptionHandler Java Examples
The following examples show how to use
io.undertow.server.handlers.ExceptionHandler.
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: TracingHttpHandlerConfiguration.java From pivotal-bank-demo with Apache License 2.0 | 6 votes |
@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 #2
Source File: CustomHandlers.java From StubbornJava with MIT License | 5 votes |
public static ExceptionHandler exception(HttpHandler handler) { return Handlers.exceptionHandler((HttpServerExchange exchange) -> { try { handler.handleRequest(exchange); } catch (Throwable th) { log.error("exception thrown at " + exchange.getRequestURI(), th); throw th; } }); }
Example #3
Source File: CustomHandlers.java From StubbornJava with MIT License | 5 votes |
public static ExceptionHandler exception(HttpHandler handler) { return Handlers.exceptionHandler((HttpServerExchange exchange) -> { try { handler.handleRequest(exchange); } catch (Throwable th) { log.error("exception thrown at " + exchange.getRequestURI(), th); throw th; } }); }
Example #4
Source File: ExceptionHandlers.java From StubbornJava with MIT License | 4 votes |
public static void handleWebException(HttpServerExchange exchange) { WebException ex = (WebException) exchange.getAttachment(ExceptionHandler.THROWABLE); exchange.setStatusCode(ex.getStatusCode()); Exchange.body().sendHtml(exchange, "<h1>" + ex.getMessage() + "</h1>"); }
Example #5
Source File: ExceptionHandlers.java From StubbornJava with MIT License | 4 votes |
public static void handleApiException(HttpServerExchange exchange) { ApiException ex = (ApiException) exchange.getAttachment(ExceptionHandler.THROWABLE); exchange.setStatusCode(ex.getStatusCode()); Exchange.body().sendJson(exchange, "{\"message\": \"" + ex.getMessage() + "\"}"); }
Example #6
Source File: ApiHandlers.java From StubbornJava with MIT License | 4 votes |
public static void handleApiException(HttpServerExchange exchange) { ApiException ex = (ApiException) exchange.getAttachment(ExceptionHandler.THROWABLE); exchange.setStatusCode(ex.getStatusCode()); Exchange.body().sendJson(exchange, new ApiError(ex.getStatusCode(), ex.getMessage())); }
Example #7
Source File: ExceptionHandlers.java From StubbornJava with MIT License | 4 votes |
public static void handleWebException(HttpServerExchange exchange) { WebException ex = (WebException) exchange.getAttachment(ExceptionHandler.THROWABLE); exchange.setStatusCode(ex.getStatusCode()); Exchange.body().sendHtml(exchange, "<h1>" + ex.getMessage() + "</h1>"); }
Example #8
Source File: ExceptionHandlers.java From StubbornJava with MIT License | 4 votes |
public static void handleApiException(HttpServerExchange exchange) { ApiException ex = (ApiException) exchange.getAttachment(ExceptionHandler.THROWABLE); exchange.setStatusCode(ex.getStatusCode()); Exchange.body().sendJson(exchange, "{\"message\": \"" + ex.getMessage() + "\"}"); }
Example #9
Source File: ApiHandlers.java From StubbornJava with MIT License | 4 votes |
public static void handleApiException(HttpServerExchange exchange) { ApiException ex = (ApiException) exchange.getAttachment(ExceptionHandler.THROWABLE); exchange.setStatusCode(ex.getStatusCode()); Exchange.body().sendJson(exchange, new ApiError(ex.getStatusCode(), ex.getMessage())); }
Example #10
Source File: ServerDefaultHttpHandler.java From proteus with Apache License 2.0 | 3 votes |
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if (this.defaultResponseListener != null) { exchange.addDefaultResponseListener(defaultResponseListener); } long fiGlobal = this.headers.fastIterateNonEmpty(); while (fiGlobal != -1) { final HeaderValues headerValues = headers.fiCurrent(fiGlobal); exchange.getResponseHeaders().addAll(headerValues.getHeaderName(), headerValues); fiGlobal = headers.fiNextNonEmpty(fiGlobal); } try { next.handleRequest(exchange); } catch (Exception e) { exchange.putAttachment(ExceptionHandler.THROWABLE,e); defaultResponseListener.handleDefaultResponse(exchange); } }
Example #11
Source File: Handlers.java From quarkus-http with Apache License 2.0 | 2 votes |
/** * Returns a handler that maps exceptions to additional handlers * * @param next The next handler * @return The exception handler */ public static ExceptionHandler exceptionHandler(final HttpHandler next) { return new ExceptionHandler(next); }
Example #12
Source File: Handlers.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Returns a handler that maps exceptions to additional handlers * @param next The next handler * @return The exception handler */ public static ExceptionHandler exceptionHandler(final HttpHandler next) { return new ExceptionHandler(next); }