From 64e6b703b7fa50a31dc0b73ec85230aa99c77bd5 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 22 Feb 2023 02:13:52 +0300 Subject: Switch to Tomcat and omit its exceptions from logs --- pom.xml | 16 ---------------- src/main/java/com/juick/www/api/Index.java | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index aa48b4db..16e4cc2b 100644 --- a/pom.xml +++ b/pom.xml @@ -35,12 +35,6 @@ org.springframework.boot spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-tomcat - - org.springframework.boot @@ -71,16 +65,6 @@ org.springframework.boot spring-boot-starter-json - - org.springframework.boot - spring-boot-starter-undertow - - - io.undertow - undertow-websockets-jsr - - - com.squareup.okhttp3 okhttp diff --git a/src/main/java/com/juick/www/api/Index.java b/src/main/java/com/juick/www/api/Index.java index 7430c22d..1c990c65 100644 --- a/src/main/java/com/juick/www/api/Index.java +++ b/src/main/java/com/juick/www/api/Index.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2021, Juick + * Copyright (C) 2008-2023, Juick * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -33,6 +33,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; +import java.io.IOException; import java.net.URI; /** @@ -61,4 +62,21 @@ public class Index { public ResponseEntity badRequest(final ConstraintViolationException exception) { return ResponseEntity.badRequest().body(exception.getMessage()); } + @ExceptionHandler(IOException.class) + public ResponseEntity handleAbortedConnection(final IOException ex) + { + // avoids compile/runtime dependency by using class name + if (ex.getClass().getName().equals("org.apache.catalina.connector.ClientAbortException")) + { + return null; + } + + // log and return error page for any other IOExceptions + if (logger.isWarnEnabled()) + { + logger.warn("IO Error", ex); + } + + return ResponseEntity.badRequest().body(ex.getMessage()); + } } -- cgit v1.2.3