Code example for FormHttpMessageConverter

0
@Component 
public class FormEncodedContentTypeFilter extends OncePerRequestFilter { 
  private final FormHttpMessageConverter messageConverter; 
 
  public FormEncodedContentTypeFilter() { 
    this.messageConverter = new FormHttpMessageConverter(); 
  } 
 
  @Override 
  protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) 
                           throws ServletException, IOException { 
    if (isPost(request) && isContentTypeNotSet(request)) { 
      request = new FormEncodedHttpServletRequestWrapper(request, messageConverter); 
    } 
    chain.doFilter(request, response); 
  } 
 
  private boolean isContentTypeNotSet(HttpServletRequest request) { 
    return isBlank(request.getHeader("Content-Type")); 
  }