You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2009/02/20 17:25:59 UTC

Capturing a complete request (free filter code!)

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

All,

After becoming intrigued over Youssef's recent post (see the "Record and
simulate a web app" thread from the 18th), I wrote come code.

Unfortunately, I wasn't able to get a complete response captured because
of the timing of various events during the request (in summary: the
HttpProcessor does some stuff at the last minute that we can't capture
using application code). So, I've given up on writing the
response-capture part of the code, at least for now.

Since I wrote it, I figured I'd publish it, and here is as good a place
as any (attached, hopefully). I'm sure there are some folks on the list
who would like to see how request wrappers should be written and you can
even see a few other neat things like:

- - how to wrap a servlet input stream and reader
- - how to make a copy of streaming data
- - how to figure out which request parameters are GET versus POST

I'd love comments if anyone has them.

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

iEYEARECAAYFAkme2ZcACgkQ9CaO5/Lv0PB8QQCgwGJhkc5IPr9sccpeLJZbQ7mL
hyUAnikwihV2dZsG4B1LpRA6Iz4ZV7yW
=Kug3
-----END PGP SIGNATURE-----

Re: Capturing a complete request (free filter code!)

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

All,

On 2/20/2009 12:49 PM, Christopher Schultz wrote:
> So, I'm resuming my efforts to complete the response side of the
> equation. I'll post more code when it's available.

Okay, I've got my filter written. A reminder of the requirements:

- - Capture request as seen by the application
- - Capture response emitted by the /application/

Note that the last requirement does not include standard headers such as
"Date" and the default status code. Only messages actually generated by
the application are captured.

For those interested in seeing some techniques, these items are covered
by the code:

- - how to wrap a servlet input stream and reader
- - how to make a copy of streaming data
- - how to figure out which request parameters are GET versus POST
- - how to wrap a servlet output stream and writer

Again, comments and questions are welcome.

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

iEYEARECAAYFAkmsYg4ACgkQ9CaO5/Lv0PBtCwCgj9apHnSGHkQ5Dm0ZLkBQdISs
jm0AnR1CDifx2SKdKcMrtBQr7vsYOnbz
=gHd2
-----END PGP SIGNATURE-----

Re: Capturing a complete request (free filter code!)

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

All,

On 2/20/2009 11:25 AM, Christopher Schultz wrote:
> Unfortunately, I wasn't able to get a complete response captured because
> of the timing of various events during the request (in summary: the
> HttpProcessor does some stuff at the last minute that we can't capture
> using application code).

A shower and shave have given me some time to reflect on this.

The original requirements were to record request/response data in order
to /simulate the application/, not to create a complete log of
everything that happens.

In my efforts to record everything, I forgot that the goal wasn't to
record a complete HTTP conversation (as the name of my filter's class
would indicate). I came to the realization that the response will be
replayed /inside the server/ that I've been having difficulty in
instrumenting. That means that the inability to (gracefully) intercept
server-originating headers, etc. is not a problem: I'm only simulating
the application's response to a particular request, not the server's
response.

So, I'm resuming my efforts to complete the response side of the
equation. I'll post more code when it's available.

- -chris

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

iEYEARECAAYFAkme7S0ACgkQ9CaO5/Lv0PDQTQCeMfKYz+pP3UXhA+Acx1YOUk/s
7GgAnj+KeVvGW2MZ+q0gFBFnXwVjNCy4
=Qror
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org