Why is HttpServletRequest inputstream empty?

后端 未结 7 1656
春和景丽
春和景丽 2020-11-30 05:52

I have this code where I read the input from a request input stream and use a JacksonMapper to convert into a POJO. Its running in a jetty 7 container with guice support.

7条回答
  •  旧巷少年郎
    2020-11-30 06:24

    I ended up with the problem when enabling debug logging for org.springframework in a Spring Boot 2.2.1 project, and thus using spring-webmvc 5.2.1.

    This is caused by the request logging of the parameter-map, which reads the input stream if the Content-Type is application/x-www-form-urlencoded. I believe this spring issue is related to it.

    See the following code which causes the problem.

    private void logRequest(HttpServletRequest request) {
        LogFormatUtils.traceDebug(logger, traceOn -> {
            String params;
            if (isEnableLoggingRequestDetails()) {
                params = request.getParameterMap().entrySet().stream()
                        .map(entry -> entry.getKey() + ":" + Arrays.toString(entry.getValue()))
                        .collect(Collectors.joining(", "));
            }
            else {
                params = (request.getParameterMap().isEmpty() ? "" : "masked");
            }
    ...
    

    source

    I ended up reporting an issue and and changing the content-type in the request instead.

提交回复
热议问题