-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Markus,

Markus Reis wrote:
> I fear you are right :-)
> 
> Due to the fact that you cannot read twice from the same
> ServletInputStream (unfortunately you are again right here :-)) I did
> the following in the mean time:

Is this just a draft? Or do you have it running anywhere?

> The above code reads the ServletInputStream into a byte buffer and
> hands on a ByteArrayInputStream from this buffer to my application
> (which in turn reads from the ByteArrayInputStream and does not attempt
> to read the initial ServletInputStream twice/again).

This is the proper strategy, but in order to put it into your Valve (or,
hack the ExtendedAccessLogValve), you'll need to wrap the Request object
in your own, new object that returns this ByteArrayInputStream to the
caller when request.getInputStream is called. You also have to serve the
same underlying object when getReader is called. Maybe something like this:

public BufferedReader getReader()
  throws IOException
{
   String encoding = getCharacterEncoding();
   if(null == encoding)
     encoding = org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING;

   return new BufferedReader(new InputStreamReader(getInputStream(),
                                                   encoding));
}

You'll need to implement a subclass of
java/org/apache/catalina/connector/Request.java (or maybe the other
Request.java in the TC source... easy to figure this out) and wrap the
existing Request with your new request object before you hand-off
control to the valve chain.

Unfortunately, Tomcat doesn't provide ready-made Request objects for
wrapping (like HttpServletRequestRrapper), but I've created some and
attached them to a bugzilla report
(https://issues.apache.org/bugzilla/show_bug.cgi?id=45014). Feel free to
use them yourself.

Also note that your InputStream actually needs to be a
ServletInputStream, so you'll have to work around that some way ;)

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkka6WkACgkQ9CaO5/Lv0PChTgCeLFLZ59uzZ7m7bCMaKbFq1vw2
blwAn2O8whFxXUNPriA9MNsn681/4WPh
=33D4
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to