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

[5.0] Potential cleanup for CloseableHttpAsyncClient#execute(SimpleHttpRequest, HttpContext, FutureCallback)

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Trivial
    • Resolution: Fixed
    • 5.0
    • 5.0.1
    • HttpClient (async)
    • None

    Description

      The source code for CloseableHttpAsyncClient#execute(SimpleHttpRequest, HttpContext, FutureCallback) looks like this:

          public final Future<SimpleHttpResponse> execute(
                  final SimpleHttpRequest request,
                  final HttpContext context,
                  final FutureCallback<SimpleHttpResponse> callback) {
              Args.notNull(request, "Request");
              final BasicFuture<SimpleHttpResponse> future = new BasicFuture<>(callback);
              execute(SimpleRequestProducer.create(request), SimpleResponseConsumer.create(), context, new FutureCallback<SimpleHttpResponse>() {
                  @Override
                  public void completed(final SimpleHttpResponse response) {
                      future.completed(response);
                  }
                  @Override
                  public void failed(final Exception ex) {
                      future.failed(ex);
                  }
                  @Override
                  public void cancelled() {
                      future.cancel(true);
                  }
              });
              return future;
          }

      To me this looks more complicated than it needs to be. I think it can be replaced with just:

          public final Future<SimpleHttpResponse> execute(
                  final SimpleHttpRequest request,
                  final HttpContext context,
                  final FutureCallback<SimpleHttpResponse> callback) {
              Args.notNull(request, "Request");
              return execute(SimpleRequestProducer.create(request), SimpleResponseConsumer.create(), context, callback);
          }
      

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            slisaasquatch Siqi Li
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: