We need an HttpRequestWrapper that can buffer the body of the POST / PUT request so that we can, for example, print it in the log messages. The standard HttpServletRequest does not allow us to cache the body: if you read it once, it disappeared because it is a stream. We created a simple wrapper class that reads the body, saves it as a String, and overrides the getReader () / getInputStream () methods so that they read the body from this string. However, now we find that it does not work when you call the getParameter * () methods (they always return null / empty) - perhaps because these methods are delegated to a wrapped, original request that does not know about the buffered body, and it tries read the source stream that has already left.
So, we probably need to redefine all the methods associated with the parameters in POST requests (getParameter, getParameterMaps, etc.) - we may have to manually parse the body and get the parameters, which does not seem like an easy task. We have to use it in a production environment, so I would rather find some existing, bulletproof code, instead of inventing our own.
But it is strange that I could not find a library that would offer such a class. Can someone point me to such a library? Do you already use this code in a public work environment?
I also saw some Tomcat inner classes whose names sound promising, like "BufferedInputFilter" (http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/coyote/http11/filters/BufferedInputFilter.html) - but this filter does not implement the standard ServletFilter, so I can not use it and how.
source
share