Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DispatcherServlet reads request body while log request information #22985

Closed
andreysubbotin opened this issue May 17, 2019 · 1 comment
Closed
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid

Comments

@andreysubbotin
Copy link

Affects 5.1


DispatcherServlet.logRequest method reads input stream with request body while executing request.getParameterMap(). As soon as the input stream is read for the first time, it’s marked as consumed and cannot be read again.
So any MVC controller will not be able to read request body after the logging. An exception appears in the log:

[org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public void com.haulmont.bpm.web.controller.ModelController.updateModel(java.lang.String,org.springframework.util.MultiValueMap<java.lang.String, java.lang.String>,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException]

Sample:
Spring application with Spring MVC.
Controller that handles request body:

@Controller("ModelController")
@RequestMapping("/modeler/model")
public class ModelController {
 @RequestMapping(value = "/{actModelId}", method = RequestMethod.PUT)
    public void updateModel(@PathVariable String actModelId,
                            @RequestBody MultiValueMap<String, String> values,
                            HttpServletRequest request,
                            HttpServletResponse response) throws IOException {}
}

This works fine on Spring 4.3.18.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 17, 2019
@rstoyanchev rstoyanchev added the in: web Issues in web modules (web, webmvc, webflux, websocket) label May 17, 2019
@rstoyanchev
Copy link
Contributor

I assume this is "application/x-www-form-urlencoded"? Servlet API, section 3.1.1 says request params are parsed from form data only on HTTP POST. What's populating request parameters is the question then? Do you have FormContentFilter (or its predecessor HttpPutFormContentFilter)? If not, please confirm if it is the Servlet container doing it, despite the Servlet spec, and if yes what server and version is it? Perhaps the server has some option to enable or disable this since it's not per spec.

Note that we do have something that allows reconstructing the request body from parameters but that's only applied for HTTP POST. We might enhance need to enhance it so it also does it for PUT but otherwise falls back on getInputStream() if it finds no parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants