hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Telling the server to close its connection?
Date Tue, 18 Nov 2008 13:34:15 GMT
On Mon, 2008-11-17 at 16:39 -0800, Adrian Blakey wrote:
> My server does not seem to want to close the connection. When I run  
> this in NetBeans the read method blocks and I get a notification that  
> says - "Step is blocked by suspended thread "Reference Handler"
> 
> The content length header is not returned.
> 
> How do I tell it to close?
> 
> My client looks a bit like this:
> 
>          HttpGet get = new HttpGet(uri);
>          int status = 0;
>          HttpEntity entity = null;
>          try {
>              HttpResponse response = client.execute(get);
>              entity = response.getEntity();
>              long len = entity.getContentLength();
>              StatusLine statusLine = response.getStatusLine();
>              status = statusLine.getStatusCode();
>              BufferedReader reader = new BufferedReader(
>                      new InputStreamReader(entity.getContent()));
>              try {
>                  String thisLine = null;
>                  while ((thisLine = reader.readLine()) != null)  
> { <<<<=======

HttpUriRequest#abort() is your friend.

Oleg



>                      log.debug(thisLine);
>                  }
>              } catch (IOException ex) {
>                  log.error("unable to get list, status " + status + "  
> " + ex);
>              } catch (RuntimeException ex) {
>                  get.abort();
>                  throw ex;
>              } finally {
>                  reader.close();
>              }
>          } catch (IOException ioe) {
>              log.error("unable to get trace, status " + status + " " +  
> ioe);
>              throw new RuntimeException(ioe);
>          } finally {
>              if (entity != null) {
>                  try {
>                      entity.consumeContent();
>                  } catch (IOException ex) {
>                      // nop
>                  }
>              }
>          }
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message