title: Accessing InputStream of x-www-form-urlencoded ServletRequest
body: <p>When you try to access the raw <code>InputStream</code> of a <code>x-www-form-urlencoded</code> servlet request, the stream could have already been indirectly consumed by a prior access to the parameters (e.g., via <code>ServletRequest#getParameterMap()</code>) of the request. This feature (bug?) has already been documented in <a href="https://javaee.github.io/servlet-spec/downloads/servlet-3.1/Final/servlet-3_1-final.pdf" rel="nofollow noreferrer">the section SRV.3.1.1 of the Servlet spec</a> and there are <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=47410" rel="nofollow noreferrer">other people</a> who have been bitten by this as well.</p>
  
  <p>This indirect stream consumption makes it, to the best of my knowledge, impossible to mirror the <code>InputStream</code>, which is exactly what we are trying to achieve in <a href="https://github.com/vy/hrrs" rel="nofollow noreferrer">HRRS</a>. Hence, I try to <a href="https://github.com/vy/hrrs/blob/master/servlet-filter/src/main/java/com/vlkan/hrrs/servlet/HrrsUrlEncodedFormHelper.java" rel="nofollow noreferrer">re-construct the <code>InputStream</code> from request parameters</a>. This, as you can imagine, a really nasty hack which I am not fond of either. Further, to make the things worse, when servlet pushes the form parameters into request parameter map, it merges them with query parameters too. Now you need to manually parse both request and query parameters to figure out the initial form parameters. A total shipwreck.</p>
  
  <p>Any ideas on how to replace this hack with a proper solution?</p>
  
  <p><strong>Edit:</strong> <em>Dear SO Java-badge owners, this is not a duplicate question. Please see the Tomcat bug report before marking the post as duplicate.</em> 
  Even if HRRS is the first filter in the list, it is not consuming <code>InputStream</code>, it is just wrapping the <code>InputStream</code> and passing along the wrapped request along the chain. Problem is, <code>getParameter()</code> calls in Tomcat is using an internal reference to the <code>InputStream</code> (that is, <code>o.a.c.connector.Request#getStream()</code>) and not calling <code>javax.servlet.ServletRequest#getInputStream()</code>. Hence, <code>InputStream</code> gets indirectly consumed without the wrapped one getting used at all. (See <code>o.a.c.connector.Request#readPostBody()</code> source code for details.)</p>