Previous Version: springCloudVersion = "Greenwich.RELEASE" springBootVersion = "2.1.13.RELEASE"

Upgraded Version: springCloudVersion = "Hoxton.SR3" springBootVersion = "2.3.11.RELEASE"

Spring Code:

  @RequestMapping(method = RequestMethod.POST, value = "valuemodified", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResponseEntity<OutputResource> processRequest(@RequestBody String jsonString) {

PostMan call: SpringBoot Getting HttpMessageNotReadableException after upgrading to 2.3.11.RELEASE

Error After Upgrade:


org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public TestController.processRequest(java.lang.String)
    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:161)
    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:131)
    at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)
    at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:167)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)

Not sure why it broke after upgrade. Things which I have tried after going through github issues and stackoverflow: 1. Tried using postmapping instead of request mapping. 2. Used different mediatypes But none worked.

Could you please suggest?

Comment From: bclozel

Does your sample request has a body? If it doesn't, maybe this is related to this note in the Spring Framework migration guide?

Could you provide a curl command for sending the request you're using? Or better, a sample application would definitely help. Thanks!

Comment From: ThirupathRao

@bclozel Yes and content-Type is application/x-www-form-urlencoded.

Comment From: ThirupathRao

CURL call: I just trimmed the curl call there are 30+ key values pairs in the body.

curl --location --request POST 'http://127.0.0.1:8083/v1/test' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'TEST[RISK][9][SCORE]=yellow' \
--data-urlencode 'TEST[RISK][7][SCORE]=red' \
--data-urlencode 'TEST[RISK][7][TSe]=Clarify TEssources' \
--data-urlencode 'TEST[RISK][10][RISK]=Low data level' \
--data-urlencode 'TSET[RISK][8][TSE]=Review relationship to the identified sites' \
--data-urlencode 'TSET[RISK][3][SCORE]=red' \
--data-urlencode 'TSET[ADDITIONAL]=' 
'

I tried Requestbody(required=false), it worked but I received null value instead of actual payload and I also tried few other mediatype instead of MediaType.APPLICATION_JSON_UTF8_VALUE.

Comment From: bclozel

Could you provide a sample application that we can clone and run? I've tried to reproduce the problem locally and couldn't.

I've created a project on start.spring.io (using this URL) and added the following controller:

@RestController
public class TestController {

    @PostMapping("/test")
    public String test(@RequestBody String body) {
        return body;
    }
}

I'm getting the expected encoded request body as a result, and no exception:

curl --location --request POST 'http://127.0.0.1:8080/test' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'TEST[RISK][9][SCORE]=yellow' \
--data-urlencode 'TEST[RISK][7][SCORE]=red' \
--data-urlencode 'TEST[RISK][7][TSe]=Clarify TEssources' \
--data-urlencode 'TEST[RISK][10][RISK]=Low data level' \
--data-urlencode 'TSET[RISK][8][TSE]=Review relationship to the identified sites' \
--data-urlencode 'TSET[RISK][3][SCORE]=red' \
--data-urlencode 'TSET[ADDITIONAL]='

TEST%5BRISK%5D%5B9%5D%5BSCORE%5D=yellow&TEST%5BRISK%5D%5B7%5D%5BSCORE%5D=red&TEST%5BRISK%5D%5B7%5D%5BTSe%5D=Clarify+TEssources&TEST%5BRISK%5D%5B10%5D%5BRISK%5D=Low+data+level&TSET%5BRISK%5D%5B8%5D%5BTSE%5D=Review+relationship+to+the+identified+sites&TSET%5BRISK%5D%5B3%5D%5BSCORE%5D=red&TSET%5BADDITIONAL%5D=%

Comment From: ThirupathRao

@bclozel Thanks for you reply. I wish I could give you the sample application or the code which I am working on but is proprietary.

I have tried this but did not work.

 @PostMapping(value = "test")
  public ResponseEntity<OutputResource> processRequest(@RequestBody String jsonString) {
org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public org.springframework.http.ResponseEntity 

Comment From: bclozel

I'm not asking for your complete application, but a sample application that reproduces the issue using the instructions I've provided.

Comment From: ThirupathRao

I will try to get a sample application is sometime. The one which you pointed out uses 2.3.12 v but I have upgraded to 2.3.11. will there be any difference in my scenario ?

Comment From: bclozel

You can change the version to 2.3.11 in the generated application to strictly replicate the same conditions. Thanks!

Comment From: ThirupathRao

@bclozel I tried with sample project, it is working fine. But not sure where is the issue. I see a stackoverflow question with the similar problem. https://stackoverflow.com/questions/60041700/requestparam-with-content-type-application-x-www-form-urlencoded-not-working-in

Comment From: bclozel

The StackOverflow question you're pointing at seems to show that people had issues with custom filters/request wrappers in their application. Maybe this is also the case in your application? More likely, the samples we've built are too simple and are missing a key part of the problem.

Are there servlet filters configures on your application (custom ones or provided by Spring)?

You can try and add more dependencies and configuration properties (that enable features) in your sample until you can see the problem.

Comment From: ThirupathRao

Issue is resolved. We have a wrapper around request.

I still don't know what change happened between the two mentioned spring boot versions but reading servletRequest. parameterMap in CachingRequestWrapper solved the issue.

Something which I found here: https://stackoverflow.com/questions/60041700/requestparam-with-content-type-application-x-www-form-urlencoded-not-working-in

Comment From: bclozel

Thanks for letting us know, I'm glad you've solved this problem!