I have a SpringBoot 2.6.14 WebApp and I’m using a Spring OncePerRequestFilter
to log some information about the HTTP request and response.
The code is similar to the follow one:
@Slf4j(topic = "logger")
public class LoggingFilter extends OncePerRequestFilter {
private final ObjectMapper mapper;
public LoggingFilter(ObjectMapper mapper) {
super();
this.mapper = mapper;
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request);
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
......
}
I manage to log the uri, the type of request (GET,POST ecc..) the host and some other usefull info but I can not manage to retrieve the Controller
signature, or simply the name. Googling around I read that I can achieve this with an HandlerInterceptor
but I must use a filter.
For example if I have a Controller
like the follow one:
@RestController
@RequestMapping("/api/v1")
public class SomeController {
@GetMapping("/all")
public ResponseEntity<List<Some>> findAll() {
List<Some> result = service.findAll();
return new ResponseEntity<>(result, HttpStatus.OK);
}
}
and I call it I can retrieve the path /api/v1/all
but I would like to obtain even the findAll()
method name.
Is it possible without the HandlerInterceptor
?