You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Aegir Sun <Ae...@Sun.COM> on 2005/08/02 17:35:27 UTC
HttpClient hang when call releaseConnection() method
Hi,
I am a beginner for httpclient. I just tried to write a simple application with Httpclient(3.0 rc2). My program is the following:
/-------------------------------------------------------------------------
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
public class Test {
public static void main(String[] args) {
HttpClient client = new HttpClient();
GetMethod method = new GetMethod("http://iso.sfbay.sun.com/iso//redhat/2.1/WS/RH21WS-1.iso");
System.out.println("cp 0");
try {
client.executeMethod(method);
System.out.println("cp 1");
System.out.println(method.getResponseContentLength());
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
System.out.println("cp 2");
method.releaseConnection();
System.out.println("cp 3");
}
}
}
When I executed it, I see that it hangs between cp2 and cp3 (namely releaseConnection() method). And I also use a debuger to debug it. And I see that releaseConnetion may waiting something...
Can anyone tell me what happened? Or how to workaround it?
Thanks.
Aegir
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: HttpClient hang when call releaseConnection() method
Posted by Aegir Sun <Ae...@Sun.COM>.
Hi, Oleg:
Thanks for your quick response. It really helps me solve the problem.
Regards,
Aegir
Oleg Kalnichevski wrote:
>Aegir,
>
>Here's my take. Execute an HTTP HEAD first and see if produces the
>desired effect. If it does not, execute an HTTP GET followed by
>HttpMethod#abort(). Make sure you always release the connection, even
>if you have aborted method's execution
>
>Hope this helps
>
>Oleg
>
>
>On Wed, Aug 03, 2005 at 05:01:33PM +0800, Aegir Sun wrote:
>
>
>>Hi, Oleg:
>>
>>Thanks for your answer. But how can I get the iso file's content-length?
>>Since I just want to know the length of the target file(the content of
>>the file is meaningless to me), how can I implement this logic with
>>httpclient? I think "HEAD" method is not suitable here, because some
>>webserver only support get and post.
>>
>>Best Regards,
>>Aegir
>>
>>Oleg Kalnichevski wrote:
>>
>>
>>
>>>Aegir,
>>>
>>>It is not hanging. It is busy retrieving the entire ISO image (which is
>>>likely to be rather bulky) to order to be able to keep the connection
>>>alive. Consider hitting a different URL for your experiments with
>>>HttpClient
>>>
>>>Oleg
>>>
>>>
>>>On Tue, Aug 02, 2005 at 11:35:27PM +0800, Aegir Sun wrote:
>>>
>>>
>>>
>>>
>>>>Hi,
>>>>
>>>>I am a beginner for httpclient. I just tried to write a simple
>>>>application with Httpclient(3.0 rc2). My program is the following:
>>>>
>>>>/-------------------------------------------------------------------------
>>>>import java.io.IOException;
>>>>
>>>>import org.apache.commons.httpclient.HttpClient;
>>>>import org.apache.commons.httpclient.HttpException;
>>>>import org.apache.commons.httpclient.methods.GetMethod;
>>>>
>>>>public class Test {
>>>> public static void main(String[] args) {
>>>> HttpClient client = new HttpClient();
>>>> GetMethod method = new
>>>> GetMethod("http://iso.sfbay.sun.com/iso//redhat/2.1/WS/RH21WS-1.iso");
>>>> System.out.println("cp 0");
>>>>
>>>> try {
>>>> client.executeMethod(method);
>>>> System.out.println("cp 1");
>>>> System.out.println(method.getResponseContentLength());
>>>> } catch (HttpException e) {
>>>> e.printStackTrace();
>>>> } catch (IOException e) {
>>>> e.printStackTrace();
>>>> } finally {
>>>> System.out.println("cp 2");
>>>> method.releaseConnection();
>>>> System.out.println("cp 3");
>>>> }
>>>> }
>>>>}
>>>>
>>>>
>>>>When I executed it, I see that it hangs between cp2 and cp3 (namely
>>>>releaseConnection() method). And I also use a debuger to debug it. And I
>>>>see that releaseConnetion may waiting something...
>>>>
>>>>Can anyone tell me what happened? Or how to workaround it?
>>>>
>>>>Thanks.
>>>>Aegir
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
>>>>For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>>>
>>>
>>>
>>>
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>>
>>
>>
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: HttpClient hang when call releaseConnection() method
Posted by Oleg Kalnichevski <ol...@apache.org>.
Aegir,
Here's my take. Execute an HTTP HEAD first and see if produces the
desired effect. If it does not, execute an HTTP GET followed by
HttpMethod#abort(). Make sure you always release the connection, even
if you have aborted method's execution
Hope this helps
Oleg
On Wed, Aug 03, 2005 at 05:01:33PM +0800, Aegir Sun wrote:
> Hi, Oleg:
>
> Thanks for your answer. But how can I get the iso file's content-length?
> Since I just want to know the length of the target file(the content of
> the file is meaningless to me), how can I implement this logic with
> httpclient? I think "HEAD" method is not suitable here, because some
> webserver only support get and post.
>
> Best Regards,
> Aegir
>
> Oleg Kalnichevski wrote:
>
> >Aegir,
> >
> >It is not hanging. It is busy retrieving the entire ISO image (which is
> >likely to be rather bulky) to order to be able to keep the connection
> >alive. Consider hitting a different URL for your experiments with
> >HttpClient
> >
> >Oleg
> >
> >
> >On Tue, Aug 02, 2005 at 11:35:27PM +0800, Aegir Sun wrote:
> >
> >
> >>Hi,
> >>
> >>I am a beginner for httpclient. I just tried to write a simple
> >>application with Httpclient(3.0 rc2). My program is the following:
> >>
> >>/-------------------------------------------------------------------------
> >>import java.io.IOException;
> >>
> >>import org.apache.commons.httpclient.HttpClient;
> >>import org.apache.commons.httpclient.HttpException;
> >>import org.apache.commons.httpclient.methods.GetMethod;
> >>
> >>public class Test {
> >> public static void main(String[] args) {
> >> HttpClient client = new HttpClient();
> >> GetMethod method = new
> >> GetMethod("http://iso.sfbay.sun.com/iso//redhat/2.1/WS/RH21WS-1.iso");
> >> System.out.println("cp 0");
> >>
> >> try {
> >> client.executeMethod(method);
> >> System.out.println("cp 1");
> >> System.out.println(method.getResponseContentLength());
> >> } catch (HttpException e) {
> >> e.printStackTrace();
> >> } catch (IOException e) {
> >> e.printStackTrace();
> >> } finally {
> >> System.out.println("cp 2");
> >> method.releaseConnection();
> >> System.out.println("cp 3");
> >> }
> >> }
> >>}
> >>
> >>
> >>When I executed it, I see that it hangs between cp2 and cp3 (namely
> >>releaseConnection() method). And I also use a debuger to debug it. And I
> >>see that releaseConnetion may waiting something...
> >>
> >>Can anyone tell me what happened? Or how to workaround it?
> >>
> >>Thanks.
> >>Aegir
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> >>
> >>
> >>
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: HttpClient hang when call releaseConnection() method
Posted by Aegir Sun <Ae...@Sun.COM>.
Hi, Oleg:
Thanks for your answer. But how can I get the iso file's content-length?
Since I just want to know the length of the target file(the content of
the file is meaningless to me), how can I implement this logic with
httpclient? I think "HEAD" method is not suitable here, because some
webserver only support get and post.
Best Regards,
Aegir
Oleg Kalnichevski wrote:
>Aegir,
>
>It is not hanging. It is busy retrieving the entire ISO image (which is
>likely to be rather bulky) to order to be able to keep the connection
>alive. Consider hitting a different URL for your experiments with
>HttpClient
>
>Oleg
>
>
>On Tue, Aug 02, 2005 at 11:35:27PM +0800, Aegir Sun wrote:
>
>
>>Hi,
>>
>>I am a beginner for httpclient. I just tried to write a simple application
>>with Httpclient(3.0 rc2). My program is the following:
>>
>>/-------------------------------------------------------------------------
>>import java.io.IOException;
>>
>>import org.apache.commons.httpclient.HttpClient;
>>import org.apache.commons.httpclient.HttpException;
>>import org.apache.commons.httpclient.methods.GetMethod;
>>
>>public class Test {
>> public static void main(String[] args) {
>> HttpClient client = new HttpClient();
>> GetMethod method = new
>> GetMethod("http://iso.sfbay.sun.com/iso//redhat/2.1/WS/RH21WS-1.iso");
>> System.out.println("cp 0");
>>
>> try {
>> client.executeMethod(method);
>> System.out.println("cp 1");
>> System.out.println(method.getResponseContentLength());
>> } catch (HttpException e) {
>> e.printStackTrace();
>> } catch (IOException e) {
>> e.printStackTrace();
>> } finally {
>> System.out.println("cp 2");
>> method.releaseConnection();
>> System.out.println("cp 3");
>> }
>> }
>>}
>>
>>
>>When I executed it, I see that it hangs between cp2 and cp3 (namely
>>releaseConnection() method). And I also use a debuger to debug it. And I
>>see that releaseConnetion may waiting something...
>>
>>Can anyone tell me what happened? Or how to workaround it?
>>
>>Thanks.
>>Aegir
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>>
>>
>>
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: HttpClient hang when call releaseConnection() method
Posted by Oleg Kalnichevski <ol...@apache.org>.
Aegir,
It is not hanging. It is busy retrieving the entire ISO image (which is
likely to be rather bulky) to order to be able to keep the connection
alive. Consider hitting a different URL for your experiments with
HttpClient
Oleg
On Tue, Aug 02, 2005 at 11:35:27PM +0800, Aegir Sun wrote:
> Hi,
>
> I am a beginner for httpclient. I just tried to write a simple application
> with Httpclient(3.0 rc2). My program is the following:
>
> /-------------------------------------------------------------------------
> import java.io.IOException;
>
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.HttpException;
> import org.apache.commons.httpclient.methods.GetMethod;
>
> public class Test {
> public static void main(String[] args) {
> HttpClient client = new HttpClient();
> GetMethod method = new
> GetMethod("http://iso.sfbay.sun.com/iso//redhat/2.1/WS/RH21WS-1.iso");
> System.out.println("cp 0");
>
> try {
> client.executeMethod(method);
> System.out.println("cp 1");
> System.out.println(method.getResponseContentLength());
> } catch (HttpException e) {
> e.printStackTrace();
> } catch (IOException e) {
> e.printStackTrace();
> } finally {
> System.out.println("cp 2");
> method.releaseConnection();
> System.out.println("cp 3");
> }
> }
> }
>
>
> When I executed it, I see that it hangs between cp2 and cp3 (namely
> releaseConnection() method). And I also use a debuger to debug it. And I
> see that releaseConnetion may waiting something...
>
> Can anyone tell me what happened? Or how to workaround it?
>
> Thanks.
> Aegir
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org