So I want to add a filter to all the endpoints of my application that capture a header and logs the value of this header. I've started with this filter
`
@Component
@Slf4j
public class RequestHeaderFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String requestHeaderValue = httpRequest.getHeader("RequestHeader");
log.info("The header value is" + requestHeaderValue);
chain.doFilter(request, response);
}
}`
I'm using Java 17 and Springboot 2.6.5, Spring v5.3.17
The first problem I encountered is that I should be importing from import javax.servlet.*; but apparently I need to add the dependency manually to my pom.xml like this
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.1</version> </dependency>
This seemed weird for me because all the examples of filters I've found on Google never mention to manually add the dependency like this, but after uptading the pom.xml it seems the interface "Filter" I'm implementing is working but now every time im calling and endpoint through Postman, adding this "RequestHeader" header, I believe the filter is not being created, since adding a breakpoint to this filter and trying to debug it is never stopping on this breakpoint.