[ https://issues.apache.org/jira/browse/HTTPCLIENT-1081?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17806449#comment-17806449 ]
Oleg Kalnichevski commented on HTTPCLIENT-1081: ----------------------------------------------- [~sebb] The issue has been resolved in 5.0 but I only now got around to verifying that. {code:java} // Create local HTTP context final HttpClientContext localContext = new HttpClientContext(); final HttpGet httpget = new HttpGet("http://httpbin.org/get"); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); // Pass local context as a parameter httpclient.execute(httpget, localContext, response -> { System.out.println("----------------------------------------"); System.out.println(httpget + "->" + new StatusLine(response)); EntityUtils.consume(response.getEntity()); final EndpointDetails endpointDetails = localContext.getEndpointDetails(); System.out.println("Remote address: " + endpointDetails.getRemoteAddress()); System.out.println("Request counts: " + endpointDetails.getRequestCount()); System.out.println("Response counts: " + endpointDetails.getResponseCount()); System.out.println("Bytes sent: " + endpointDetails.getSentBytesCount()); System.out.println("Bytes received: " + endpointDetails.getReceivedBytesCount()); return null; }); // EndpointDetails is present in the context even if the underlying connection // gets immediately released back to the connection pool final HttpHead httphead = new HttpHead("http://httpbin.org/get"); System.out.println("Executing request " + httphead.getMethod() + " " + httphead.getUri()); // Pass local context as a parameter httpclient.execute(httphead, localContext, response -> { System.out.println("----------------------------------------"); System.out.println(httphead + "->" + new StatusLine(response)); EntityUtils.consume(response.getEntity()); final EndpointDetails endpointDetails = localContext.getEndpointDetails(); System.out.println("Remote address: " + endpointDetails.getRemoteAddress()); System.out.println("Request counts: " + endpointDetails.getRequestCount()); System.out.println("Response counts: " + endpointDetails.getResponseCount()); System.out.println("Bytes sent: " + endpointDetails.getSentBytesCount()); System.out.println("Bytes received: " + endpointDetails.getReceivedBytesCount()); return null; }); {code} Oleg > getMetrics() does not work for HEAD or other early release methods > ------------------------------------------------------------------ > > Key: HTTPCLIENT-1081 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1081 > Project: HttpComponents HttpClient > Issue Type: Bug > Reporter: Sebb > Priority: Major > Fix For: 5.4-alpha2 > > > 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) > This is because the getMetrics() method calls assertValid() which checks that > the connection has not been released, and the HEAD request is released as > soon as it completes, before returning to the caller. > Possible solutions: > - don't call assertValid() in getMetrics() > - store a pointer to the metrics in the local context -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For additional commands, e-mail: dev-h...@hc.apache.org