How to get the size of the HTTPResponse

Discussion in 'Java' started by Kiran Bagga, Oct 10, 2013.

  1. Kiran Bagga

    Kiran Bagga Guest

    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??
    Kiran Bagga, Oct 10, 2013
    #1
    1. Advertising

  2. Kiran Bagga

    markspace Guest

    On 10/9/2013 4:54 PM, Kiran Bagga wrote:
    > 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?
    markspace, Oct 10, 2013
    #2
    1. Advertising

  3. Kiran Bagga

    Arne Vajhøj Guest

    On 10/9/2013 7:54 PM, Kiran Bagga wrote:
    > 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
    Arne Vajhøj, Oct 10, 2013
    #3
  4. Kiran Bagga

    Kiran Bagga Guest

    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?

    On Wednesday, October 9, 2013 7:48:45 PM UTC-7, Arne Vajhøj wrote:
    > On 10/9/2013 7:54 PM, Kiran Bagga wrote:
    >
    > > 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
    Kiran Bagga, Oct 10, 2013
    #4
  5. On 10.10.2013 19:20, Kiran Bagga wrote:
    > 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


    --
    remember.guy do |as, often| as.you_can - without end
    http://blog.rubybestpractices.com/
    Robert Klemme, Oct 10, 2013
    #5
  6. Kiran Bagga

    Arne Vajhøj Guest

    On 10/10/2013 1:20 PM, Kiran Bagga wrote:
    > On Wednesday, October 9, 2013 7:48:45 PM UTC-7, Arne Vajhøj wrote:
    >> On 10/9/2013 7:54 PM, Kiran Bagga wrote:
    >>> 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?

    >
    > 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 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.

    Arne
    Arne Vajhøj, Oct 11, 2013
    #6
  7. On 2013-10-11 04:59, Arne Vajhøj allegedly wrote:
    > On 10/10/2013 1:20 PM, Kiran Bagga wrote:
    >> On Wednesday, October 9, 2013 7:48:45 PM UTC-7, Arne Vajhøj wrote:
    >>> On 10/9/2013 7:54 PM, Kiran Bagga wrote:
    >>>> 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?

    >>
    >> 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 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.

    --
    DF.
    Daniele Futtorovic, Oct 13, 2013
    #7
  8. Kiran Bagga

    Roedy Green Guest

    On Wed, 9 Oct 2013 16:54:08 -0700 (PDT), Kiran Bagga
    <> wrote, quoted or indirectly quoted someone who said
    :

    >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.
    --
    Roedy Green Canadian Mind Products http://mindprod.com
    Unlike many machines, computers require no water once they are
    manufactured.
    Roedy Green, Oct 17, 2013
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Hanson
    Replies:
    4
    Views:
    8,551
    Yan-Hong Huang[MSFT]
    Aug 1, 2003
  2. Matthew Trunnell

    HttpResponse.ValidateFileRange()

    Matthew Trunnell, Feb 6, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    433
    Matthew Trunnell
    Feb 6, 2004
  3. =?Utf-8?B?QWxleCBLbGltYW50b3Y=?=

    HttpResponse Headers

    =?Utf-8?B?QWxleCBLbGltYW50b3Y=?=, Apr 2, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    854
    =?Utf-8?B?QWxleCBLbGltYW50b3Y=?=
    Apr 2, 2004
  4. =?Utf-8?B?Sm9zZSBGbG9yZXM=?=

    RE: How to read content of httpResponse.OutputStream

    =?Utf-8?B?Sm9zZSBGbG9yZXM=?=, May 12, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    18,713
    =?Utf-8?B?Sm9zZSBGbG9yZXM=?=
    May 18, 2004
  5. =?Utf-8?B?QWw=?=

    how to mesure a size of the HttpResponse?

    =?Utf-8?B?QWw=?=, Sep 17, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    292
    =?Utf-8?B?QWw=?=
    Sep 17, 2004
Loading...

Share This Page