You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by sebb <se...@gmail.com> on 2011/04/09 14:20:36 UTC

ConnectionShutdownException when trying to get metrics after HEAD request

The following code works fine for GET:

            HttpResponse httpResponse =
httpClient.execute(httpRequest, localContext);
            HttpConnection conn = (HttpConnection)
localContext.getAttribute(ExecutionContext.HTTP_CONNECTION);
            HttpConnectionMetrics metrics = conn.getMetrics();

but fails on the getMetrics() call when the request is HEAD:

        org.apache.http.impl.conn.ConnectionShutdownException
	at org.apache.http.impl.conn.AbstractClientConnAdapter.assertValid(AbstractClientConnAdapter.java:154)
	at org.apache.http.impl.conn.AbstractClientConnAdapter.getMetrics(AbstractClientConnAdapter.java:190)

Is that intentional? Surely the metrics should still be valid?

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


Re: ConnectionShutdownException when trying to get metrics after HEAD request

Posted by sebb <se...@gmail.com>.
On 11 April 2011 11:51, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Sat, 2011-04-09 at 13:20 +0100, sebb wrote:
>> The following code works fine for GET:
>>
>>             HttpResponse httpResponse =
>> httpClient.execute(httpRequest, localContext);
>>             HttpConnection conn = (HttpConnection)
>> localContext.getAttribute(ExecutionContext.HTTP_CONNECTION);
>>             HttpConnectionMetrics metrics = conn.getMetrics();
>>
>> but fails on the getMetrics() call when the request is HEAD:
>>
>>         org.apache.http.impl.conn.ConnectionShutdownException
>>       at org.apache.http.impl.conn.AbstractClientConnAdapter.assertValid(AbstractClientConnAdapter.java:154)
>>       at org.apache.http.impl.conn.AbstractClientConnAdapter.getMetrics(AbstractClientConnAdapter.java:190)
>>
>> Is that intentional? Surely the metrics should still be valid?
>>
>
> That's because responses to HEAD requests do not enclose any content
> body, so the HTTP connection is returned back to the pool immediately.

Yes, but why does the getMetrics method require the connection to be active?

> We could make the AbstractClientConnAdapter class keep a copy of
> connection metrics even after the underlying HTTP connection is released
> back to the pool.

Or save the metrics in the local context?

> Feel free to raise a JIRA for this issue.

I'll do that later.

> Oleg
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>

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


Re: ConnectionShutdownException when trying to get metrics after HEAD request

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Sat, 2011-04-09 at 13:20 +0100, sebb wrote:
> The following code works fine for GET:
> 
>             HttpResponse httpResponse =
> httpClient.execute(httpRequest, localContext);
>             HttpConnection conn = (HttpConnection)
> localContext.getAttribute(ExecutionContext.HTTP_CONNECTION);
>             HttpConnectionMetrics metrics = conn.getMetrics();
> 
> but fails on the getMetrics() call when the request is HEAD:
> 
>         org.apache.http.impl.conn.ConnectionShutdownException
> 	at org.apache.http.impl.conn.AbstractClientConnAdapter.assertValid(AbstractClientConnAdapter.java:154)
> 	at org.apache.http.impl.conn.AbstractClientConnAdapter.getMetrics(AbstractClientConnAdapter.java:190)
> 
> Is that intentional? Surely the metrics should still be valid?
> 

That's because responses to HEAD requests do not enclose any content
body, so the HTTP connection is returned back to the pool immediately.

We could make the AbstractClientConnAdapter class keep a copy of
connection metrics even after the underlying HTTP connection is released
back to the pool.

Feel free to raise a JIRA for this issue.

Oleg



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


Re: ConnectionShutdownException when trying to get metrics after HEAD request

Posted by sebb <se...@gmail.com>.
On 9 April 2011 13:20, sebb <se...@gmail.com> wrote:
> The following code works fine for GET:
>
>            HttpResponse httpResponse =
> httpClient.execute(httpRequest, localContext);
>            HttpConnection conn = (HttpConnection)
> localContext.getAttribute(ExecutionContext.HTTP_CONNECTION);
>            HttpConnectionMetrics metrics = conn.getMetrics();
>
> but fails on the getMetrics() call when the request is HEAD:
>
>        org.apache.http.impl.conn.ConnectionShutdownException
>        at org.apache.http.impl.conn.AbstractClientConnAdapter.assertValid(AbstractClientConnAdapter.java:154)
>        at org.apache.http.impl.conn.AbstractClientConnAdapter.getMetrics(AbstractClientConnAdapter.java:190)
>
> Is that intentional? Surely the metrics should still be valid?
>

As a work-round, I added an HttpResponseInterceptor that saves the
metrics object in the local context, and the metric now works with
HEAD and GET, which suggests it is still valid after connection
shutdown.

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