File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Questions re: response.getOutputStream() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Questions re: response.getOutputStream()" Watch "Questions re: response.getOutputStream()" New topic

Questions re: response.getOutputStream()

Richard Olson

Joined: Mar 15, 2004
Posts: 15


I'm a newbie try to complete the following goal. We need a utility for capturing or intercepting HTTP responses then writing the output to a file for troubleshooting purposes; something like a sniffer, but without packet info.

I've tried various methods, but so far no success. I�ve tried using ServerOutputStream sOutStr = response.getOutputStream(). How do I write the output to a file? No write methods exist for writing ServerOutputStream to a file. I looked at some of the other streams, but none seem to fit my purposes or I missed the boat.

Any ideas because I�m confused. Hopefully, my description makes sense.

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

The typical approach (which isn't real friendly to newbies) is to wrap the response in an instance of HttpServletResonseWrapper and override the methods needed to alter the response's behaviour.

I have a rough example of this on my site:

In it the response is captured in a filter and written to stdout.
I could be altered very easily to write the output to file.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Richard Olson

Joined: Mar 15, 2004
Posts: 15
Thanks, Ben, I'll take a look
I agree. Here's the link:
subject: Questions re: response.getOutputStream()
It's not a secret anymore!