Given the following, kind of basic, REST controller in Spring Boot:
@RestController
public class NotificationController {
@PostMapping(path = "/api/notification")
public void handleNotification(@RequestBody @Valid NotificationRequest request) {
System.out.println(request.getMessage());
}
}
One requirement is to log the incoming request body before deserializing it to a NotificationRequest
. We'd like to have a trace, e.g. if the request is not well-formed. My first idea was to use the HttpServletRequest
directly but then I would lose the validation and automatic deserialization.
public void handleNotification(HttpServletRequest httpRequest) {
// ...
}
Is there some mechanism to log the incoming "raw" request body for this particular endpoint?