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 Adrian Blakey <ad...@gmail.com> on 2008/11/18 01:39:01 UTC
Telling the server to close its connection?
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)
{ <<<<=======
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
Re: Telling the server to close its connection?
Posted by Oleg Kalnichevski <ol...@apache.org>.
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