commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Trevor Miller" <ub3rg...@gmail.com>
Subject Re: [httpclient]
Date Wed, 09 Aug 2006 15:49:20 GMT
Hi Chris,

Trust me, this does not work. I have written a Servlet with the following code:

    protected void processRequest (HttpServletRequest request,
HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType ("text/xml;charset=UTF-8");
        PrintWriter out = response.getWriter ();
        out.println("<events>");
        for (int i = 0; i < 100; i++) {
            out.println ("<event title=\"Event 5\"
time=\"200609131430\" id=\"5\">new Event</event>");
            try {
                Thread.sleep (500);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
        out.println("</events>");
        out.close ();
    }

Which should take close on 50 seconds to execute.

According to ProgressMonitorInutStream javadocs:
If its taking a while, a progress dialog will be popped up to inform the user.

My client application runs and after 53 seconds it prints out:
Connected, reading response.

Which indicates to me that all the data is read before it gets the
input stream. I guess I'm going to have to go look at the code for
HTTPClient....

Regards,
Trevor

On 8/9/06, Christian Hufgard <christian.hufgard@gmx.de> wrote:
> Hi Trevor
>
> > Needless to say, this does not work since by the time
> > method.getResponseBodyAsStream () is called, the data has already been
> > transferred.
>
> I do not think so. This is the preferred way a response should be
> read, since it does _not_ buffer the whole response in memory.
>
> Are you shure that this code does not work? How do yo figure out the
> overall response size?
>
>
> Cheers,
>
>
> Chris
>
>
> Wednesday, August 9, 2006, 11:13:45 AM, you wrote:
>
> > Hi All,
>
> > I'm using HttpClient to download a simple XML document from a jsp
> > page, I want to be able to show a progress bar if it takes a long
> > time.
>
> > In order to test this, i write a simple JSP with some calls to
> > Thread.sleep to simulate network latency and used the following code:
>
> >         HttpClient client = new HttpClient();
> >         HttpMethod method = new
> > GetMethod("http://localhost:8084/TestHTTPWeb/index.jsp");
> >         try {
> >             client.executeMethod (method);
> >             System.out.println ("Connected, reading response.");
> >             InputStream in = new BufferedInputStream(
> >                           new ProgressMonitorInputStream(
> >                                   this,
> >                                   "Reading",
> >                                   method.getResponseBodyAsStream ()));
> >         } catch (IOException ex) {
> >             ex.printStackTrace();
> >         }
>
> > Needless to say, this does not work since by the time
> > method.getResponseBodyAsStream () is called, the data has already been
> > transferred.
>
> > Is there a way to do this?
>
> > Regards,
> > Trevor Miller
>
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > commons-user-help@jakarta.apache.org
>
>
>
> --
> Best regards,
>  Christian                            mailto:christian.hufgard@gmx.de
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>


-- 
Real programmers use Linux!

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message