I have a ServletInputStream
that I need to read more than once (the code that reads it the second time is in an API I don\'t control). When using IOUtils.
If you want to examine or consume part or all of the request body before handing off the request to this other API method, then you probably cannot do that at the level of a user of the Servlet API. Instead, you need to work a little lower, consuming the Servlet API on the one hand, but also serving it to the other API.
Specifically, you can preserve the data read from the request's input stream by whatever means you choose, and provide the same to the other API by wrapping the HttpServletRequest
in an implementation that mostly delegates to the wrapped request object, but whose getInputStream()
method provides a stream from which the whole request body can be read.