On Thu, 28 Feb 2002, Mark Shaw wrote:
> Date: Thu, 28 Feb 2002 13:45:53 -0800
> From: Mark Shaw <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
> Subject: RequestDumperValve help
>
> I have a question (potential bug?) w/ RequestDumperValve. I have set up a
> simple SOAP like web-service (actually it's Caucho's Hessian protocol) and
> when I attempt to use this when also using the RequestDumperValve, my call,
> which uses POST, always fails on the server due to the servlet input stream
> being close. The Dumper logs all the correct values from the client
> request, but my servlet is passed (from invokeNext()?) a closed input stream
> so it can't read the SOAP request. I poked around in the code and
> discovered that this is related to HttpServletRequest.getParameterNames(),
> and digging deeper still, found that code in
> HttpRequestBase.parseParamaters() actually closes the input stream when
> reading the params from a POST:
>
> if ("POST".equals(getMethod()) && (getContentLength() > 0)
> && (this.stream == null)
> && "application/x-www-form-urlencoded".equals(contentType)) {
> try {
> int max = getContentLength();
> int len = 0;
> byte buf[] = new byte[getContentLength()];
> ServletInputStream is = getInputStream();
> while (len < max) {
> int next = is.read(buf, len, max - len);
> len += next;
> }
> is.close();
> RequestUtil.parseParameters(results, buf, encoding);
> } catch (Throwable t) {
> ;
> }
> }
>
> Is there any reason is.close() is called? Am I doing something wrong?
>
The input stream is closed because it has been completely read. Even
without the close() there, though, you'd still have a problem because the
stream will have been read already, and there's no way to rewind it.
That wouldn't be a problem if the servlet only used getParameter() type
calls itself. But if the servlet expects to read the input stream, and a
filter has already read it, you're violating the requirements of the
servlet and you'll need to do something different in your filter:
* Modify RequestDumperFilter to not dump the parameters
* Create a wrapper around the request before passing it on,
and have the wrapper provide a suitable input stream
even though the filter already read the "real" input stream.
> Thanks for any help on this,
> -Mark Shaw
Craig
--
To unsubscribe: <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>