Last Updated: February 25, 2016
· zohebsait

@RequestParam not working with POST calls in Spring MVC

I was seeing an odd issue where using @RequestParam for a POST call with Spring MVC was not working, and the parameter was always null.

I took at look at the FormHTTPMessageConverter code and notice that the body was always coming as blank, although the incoming request had a body.

public MultiValueMap<String, String> read(Class<? extends MultiValueMap<String, ?>> clazz,
                        HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {

                    MediaType contentType = inputMessage.getHeaders().getContentType();
                    Charset charset = contentType.getCharSet() != null ? contentType.getCharSet() : this.charset;
                    String body = FileCopyUtils.copyToString(new InputStreamReader(inputMessage.getBody(), charset));

So someone was consuming the inputStream on the request message before it hit this converter, and after some digging I found that the culprit was RequestLoggingFilter that I had enabled in web.xml and I had set the payLoad logging option to true. Sure enough, it was logging the payload but consuming the inputstream making it available to anything down the line! I disabled the payLoad logging and everything worked fine again!

Say Thanks