From a20df3da57291f107122e0fbf57e0a44a8ee15a9 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Wed, 16 Sep 2020 20:11:53 +0200 Subject: [PATCH] Logging the name for create-requests for already existent users --- .../de/juplo/boot/data/jdbc/UserController.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/juplo/boot/data/jdbc/UserController.java b/src/main/java/de/juplo/boot/data/jdbc/UserController.java index 0aaefd5..0a4a62f 100644 --- a/src/main/java/de/juplo/boot/data/jdbc/UserController.java +++ b/src/main/java/de/juplo/boot/data/jdbc/UserController.java @@ -6,10 +6,14 @@ import org.springframework.context.ApplicationEventPublisher; import org.springframework.dao.IncorrectResultSizeDataAccessException; import org.springframework.http.ResponseEntity; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StreamUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; import org.springframework.web.util.UriComponents; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.nio.charset.Charset; import java.time.LocalDateTime; import static de.juplo.boot.data.jdbc.UserEvent.Type.CREATED; @@ -94,10 +98,19 @@ public class UserController { @ExceptionHandler public ResponseEntity incorrectResultSizeDataAccessException( + HttpServletRequest request, IncorrectResultSizeDataAccessException e ) { - LOG.info("User already exists!"); + String username; + try { + username = StreamUtils.copyToString(request.getInputStream(), Charset.defaultCharset()); + } + catch (IOException ioe) + { + username = e.getMessage() + " -> " + ioe.getMessage(); + } + LOG.info("User {} already exists!", username); return ResponseEntity.badRequest().build(); } } -- 2.20.1