wood burning stoves*
The moose likes Servlets and the fly likes Size of the response sent by the server. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Size of the response sent by the server." Watch "Size of the response sent by the server." New topic
Author

Size of the response sent by the server.

Robin Sharma
Ranch Hand

Joined: Aug 24, 2005
Posts: 76
Hi!

How do i calculate the size of the response sent by the server for a request? I am using a servlet filter which just prints the size of the request/response. Now, I can get the size of the request using the request.getContentLength() method. But, how do i get the size of the response?

Thanks.


DW
There is always a bug :-)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60802
    
  65

Why do you feel you need it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
It's quite simple. You need to wrap a response object in your object which plays a role of proxy. You should care only about two methods: getOutputStream and getWriter. Return your own implementation wrapping objects returned by original response for these methods. Your implementation is also a proxy which counts a number of processed bytes. You can use Java proxy capabilities or HttpServletResponseWrapper to simplify your implementation.


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
If, on the other hand, he needs the size to set the response content-length header, this size is needed before anything is written to the response. In that case all output should be to a local buffer - see java.io CharArrayWriter or ByteArrayOutputStream - finish the output, use the size to set the header, write the whole buffer at one go.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Size of the response sent by the server.
 
Similar Threads
JAXB and TCP/IP
Help please.
request redirect
Can HttpUnit be used to mock an HTTP Server?
socket programin in java