Why is HttpServletRequest inputstream empty?

后端 未结 7 1666
春和景丽
春和景丽 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:34

    It will be empty if it's already consumed beforehand. This will be implicitly done whenever you call getParameter(), getParameterValues(), getParameterMap(), getReader(), etc on the HttpServletRequest. Make sure that you don't call any of those kind of methods which by themselves need to gather information from the request body before calling getInputStream(). If your servlet isn't doing that, then start checking the servlet filters which are mapped on the same URL pattern.


    Update: this seems to be GAE 1.5 specific. See also

    • http://code.google.com/p/googleappengine/issues/detail?id=5161
    • http://code.google.com/p/googleappengine/issues/detail?id=5898

    I'm afraid that there's no solution/workaround until they get it fixed. You could try to check if it's available inside a Filter and if so, then copy and store it as request attribute. But this might affect further processing by some GAE servlet.

提交回复
热议问题