commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Will HttpClient wait for response before continuing?
Date Mon, 07 Feb 2005 18:20:48 GMT
On Mon, Feb 07, 2005 at 11:54:59AM -0600, Stephen Charles Huey wrote:
> Ok, I was just hoping that executeMethod would automatically retrieve
> all of the response so that when getResponseBodyAsString is called, it
> is only retrieving it from storage, but I understand from you that only
> if a method like that is called does it bother to wait around for the
> rest of the bytes.  
> 
Stephen,

The thing is that in most cases this is really not desireable. Think
about situation where one gets several megabytes worth of response
content


> So, to consume it, is this sufficient?
> 
> int result = hc.executeMethod(getLogin);
> String text = hc.getResponseBodyAsString();
> getLogin.releaseConnection();
> 

Absolutely. But you'd better be sure that the response content is fairly
small. See HttpClient 3.0 optimization guide for details:

http://jakarta.apache.org/commons/httpclient/3.0/performance.html


> 
> Or do I need to do more with it, like this?
> 
> int result = hc.executeMethod(getLogin);
> String text = hc.getResponseBodyAsString();
> int count = text.length();
> getLogin.releaseConnection();

I am not sure I see a difference.

> 
> 
> I know this is probably pretty basic stuff, but I'm just trying to make
> sure that the compiler doesn't optimize this junk and in some weird
> annoying way let the getResponseBodyAsString method know that actually,
> it's not really needed, so we're not going to wait for even you to
> finish because we're not actually doing anything with the String text...
> 

I am not sure Java does this sort of optimization. Anyways, you are much
better off implemeting your own response consumer as described in the
optimization guide instead of trying to get is one big chunk

Oleg

> 
> Thanks,
> Stephen
> 
> 
> ----- Original message -----
> From: "Oleg Kalnichevski" <olegk@apache.org>
> To: "Commons Net User list" <commons-user@jakarta.apache.org>
> Date: Mon, 7 Feb 2005 18:16:59 +0100
> Subject: Re: Will HttpClient wait for response before continuing?
> 
> Stephen,
> 
> No it won't. The releaseConnection method among obvious things such as
> returning the connection back to the connection manager also makes sure
> that the connection is actually reusable if it is kept alive (open).
> That pretty much implies making sure that the response body is fully
> consumed. If your application does not consume the response body in its
> entirety, the releaseConnection method will do it for it.
> 
> Hope this answers your question.
> 
> Oleg
> 
> 
> On Mon, Feb 07, 2005 at 10:18:49AM -0600, Stephen Charles Huey wrote:
> > If you do a GET or POST and call getResponseBodyAsString, HttpClient
> > obviously has to wait for the response.  If you don't call that, will it
> > just continue on to the next request before finishing getting the
> > response from the first one?  I'm trying to debug some connection
> > pooling stuff on our web app.  Here's some sample code from my load
> > tester:
> > 
> > 
> > 
> > int result = hc.executeMethod(getLogin);
> > getLogin.releaseConnection();
> >                 
> > doNothing(2000);  // wait 2 seconds
> > 
> > hc.executeMethod(getCreate);
> > getCreate.releaseConnection();
> > 
> > doNothing(2000);  // wait 2 seconds
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 

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