You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2017/11/14 17:43:00 UTC

[jira] [Commented] (HTTPCLIENT-1081) getMetrics() does not work for HEAD or other early release methods

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1081?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16251810#comment-16251810 ] 

ASF GitHub Bot commented on HTTPCLIENT-1081:
--------------------------------------------

Github user ham1 commented on a diff in the pull request:

    https://github.com/apache/jmeter/pull/320#discussion_r150905177
  
    --- Diff: src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java ---
    @@ -215,22 +269,128 @@ public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
             
         };
     
    -    /**
    -     * Special interceptor made to keep metrics when connection is released for some method like HEAD
    -     * Otherwise calling directly ((HttpConnection) localContext.getAttribute(HttpCoreContext.HTTP_CONNECTION)).getMetrics();
    -     * would throw org.apache.http.impl.conn.ConnectionShutdownException
    -     * See <a href="https://bz.apache.org/jira/browse/HTTPCLIENT-1081">HTTPCLIENT-1081</a>
    -     */
    -    private static final HttpResponseInterceptor METRICS_SAVER = (HttpResponse response, HttpContext context) -> {
    -        HttpConnectionMetrics metrics = ((HttpConnection) context.getAttribute(HttpCoreContext.HTTP_CONNECTION)).getMetrics();
    -        context.setAttribute(CONTEXT_METRICS, metrics);
    -    };
    -    private static final HttpRequestInterceptor METRICS_RESETTER = (HttpRequest request, HttpContext context) -> {
    -        HttpConnectionMetrics metrics = ((HttpConnection) context.getAttribute(HttpCoreContext.HTTP_CONNECTION)).getMetrics();
    -        metrics.reset();
    +    private static final String DIGEST_PARAMETERS = DigestParameters.VARIABLE_NAME;
    +
    +    
    +    private static final HttpRequestInterceptor PREEMPTIVE_AUTH_INTERCEPTOR = new HttpRequestInterceptor() {
    --- End diff --
    
    This is almost 100 lines and with lots of nesting becomes very hard to read and review, could it be split into smaller methods?


> 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
>             Fix For: 5.0
>
>
> 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
(v6.4.14#64029)

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