Skip to content

Instantly share code, notes, and snippets.

@njofce
Created March 7, 2021 16:29
Show Gist options
  • Save njofce/0d33f52059c32b46979e7b04e315a821 to your computer and use it in GitHub Desktop.
Save njofce/0d33f52059c32b46979e7b04e315a821 to your computer and use it in GitHub Desktop.
@Component
public class LogRequestFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
if(Arrays.asList("POST", "PUT").contains(httpRequest.getMethod())) {
CustomHttpRequestWrapper requestWrapper = new CustomHttpRequestWrapper(httpRequest);
filterChain.doFilter(requestWrapper, servletResponse);
return;
}
filterChain.doFilter(servletRequest, servletResponse);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment