How to get the size of the HTTPResponse

K

Kiran Bagga

Hi


Maybe I am over thinking this or doing something dumb, But I cant seem to extract the right size of the HttpResponse object on the server side. I need it to log the number of response bytes. Any suggestions??
 
M

markspace

Hi


Maybe I am over thinking this or doing something dumb, But I cant
seem to extract the right size of the HttpResponse object on the
server side. I need it to log the number of response bytes. Any
suggestions??


What have you tried? Did you account for filters that may be modifying
the stream after you count it?

Overall, I think I'd try my firewall first. It seems to me that's a
sure fire method of accounting for network traffic. Programming comes
second.

What's the need driving knowing what the byte output count?
 
A

Arne Vajhøj

Maybe I am over thinking this or doing something dumb, But I cant
seem to extract the right size of the HttpResponse object on the
server side. I need it to log the number of response bytes. Any
suggestions??

Servlet filter?

Arne
 
K

Kiran Bagga

I am using servlet filters. The output body is stored in the OutputStream. I cant seem to find a way to extract the body from it and calculate the size. Any suggestions?
 
R

Robert Klemme

I am using servlet filters. The output body is stored in the
OutputStream. I cant seem to find a way to extract the body from it
and calculate the size. Any suggestions?

You should be able to stack another OutputStream on the other one. The
stacked stream could then count bytes. Still the problem Mark mentioned
remains.

Cheers

robert
 
D

Daniele Futtorovic

You make it use an ByteArrayOutputStream.

Google finds:

http://angelborroy.wordpress.com/2009/03/04/dump-request-and-response-using-javaxservletfilter/


I can try and create a simpler example if I find time for it.

While it would work, counting how many bytes went through the wire does
not require dumping the response in a BAOS, and hence break the
streaming. A CountingOutputStream layer would be sufficient.

Note that if it's only the size of the body that is of interest (as
opposed to the size of the body plus the header), then there likely
already is a component that computes that, to set the Content-Length
response header.
 
R

Roedy Green

Maybe I am over thinking this or doing something dumb,
But I cant seem to extract the right size of the HttpResponse object
on the server side. I need it to log the number of response bytes. Any
suggestions??

it is an optional field. Sometimes the server does not even know it
to start. It just sends and sends until it runs out of bytes. You have
to keep could of how many you read.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top