HttpMessageNotReadableException: Required request body is missing (Occasional) - SpringMVC Default Controller Request Mapping HTTP Method?

纵饮孤独 提交于 2020-12-15 17:50:35

问题


I have the following code which represents an Ajax POST request:

@RequestMapping("/participant/insertEvent")
public boolean insertEvent(Principal principal, @RequestBody String json, HttpServletRequest request) throws Exception {
     //...
     //return true or false
}

JS:

$.ajax({
    type : "post",
    dataType : "json",
    url : '/app/participant/insertEvent',   
    data : JSON.stringify({'p1': p1, 'p2' : p2})        
});

The app is deployed in Production and everything has been working with many users the whole week.

This morning I got the following production issue at this method (insertEvent):

org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public boolean 
app.controller.participant.AjaxOperationsController.insertEvent(java.security.Principal,java.lang.String,javax.servlet.http.HttpServletRequest) throws java.lang.Exception 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:130) at           org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124) at 

    org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) at ...

I'm wondering, is it because I didn't explicitly specify this is a method={RequestMethod.POST} ?

But if I don't specify an HTTP method, what is the default?

However, if this is the issue, then why does the app work 99% of the time, and not for that one user?


回答1:


FYI, the error was caused by including in the JSON an un-encoded % (percent) special char coming from a TextArea value.



来源:https://stackoverflow.com/questions/58452223/httpmessagenotreadableexception-required-request-body-is-missing-occasional

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!