Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-1081

getMetrics() does not work for HEAD or other early release methods

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 5.0, 5.4-alpha2
    • None
    • None

    Description

      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

      Attachments

        Activity

          People

            Unassigned Unassigned
            sebb Sebb
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: