org.apache.hc.core5.http.impl.io

## Class HttpRequestExecutor

- java.lang.Object
- - org.apache.hc.core5.http.impl.io.HttpRequestExecutor

-     @Contract(threading=IMMUTABLE)
      public class HttpRequestExecutor
      extends Object

  `HttpRequestExecutor` is a client side HTTP protocol handler based on the blocking (classic) I/O model.

  `HttpRequestExecutor` relies on `HttpProcessor` to generate mandatory protocol headers for all outgoing messages and apply common, cross-cutting message transformations to all incoming and outgoing messages. Application specific processing can be implemented outside `HttpRequestExecutor` once the request has been executed and a response has been received.

  Since:
    4.0

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `HttpRequestExecutor.Builder` Builder for `HttpRequestExecutor`.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static Timeout` | `DEFAULT_WAIT_FOR_CONTINUE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpRequestExecutor()`
    `HttpRequestExecutor(ConnectionReuseStrategy connReuseStrategy)`
    `HttpRequestExecutor(Http1Config http1Config, ConnectionReuseStrategy connReuseStrategy, Http1StreamListener streamListener)` Creates new instance of HttpRequestExecutor.
    `HttpRequestExecutor(Timeout waitForContinue, ConnectionReuseStrategy connReuseStrategy, Http1StreamListener streamListener)` Deprecated. Use `HttpRequestExecutor(Http1Config, ConnectionReuseStrategy, Http1StreamListener)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static HttpRequestExecutor.Builder` | `builder()` Create a new `HttpRequestExecutor.Builder`.
    `ClassicHttpResponse` | `execute(ClassicHttpRequest request, HttpClientConnection conn, HttpContext context)` Sends the request and obtain a response.
    `ClassicHttpResponse` | `execute(ClassicHttpRequest request, HttpClientConnection conn, HttpResponseInformationCallback informationCallback, HttpContext localContext)` Sends the request and obtain a response.
    `boolean` | `keepAlive(ClassicHttpRequest request, ClassicHttpResponse response, HttpClientConnection connection, HttpContext context)` Determines whether the connection can be kept alive and is safe to be re-used for subsequent message exchanges.
    `void` | `postProcess(ClassicHttpResponse response, HttpProcessor processor, HttpContext localContext)` Post-processes the given response using the given protocol processor and completes the process of request execution.
    `void` | `preProcess(ClassicHttpRequest request, HttpProcessor processor, HttpContext localContext)` Pre-process the given request using the given protocol processor and initiates the process of request execution.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_WAIT_FOR_CONTINUE

          public static final Timeout DEFAULT_WAIT_FOR_CONTINUE

  - ### Constructor Detail

    - #### HttpRequestExecutor

          public HttpRequestExecutor(Http1Config http1Config,
                                     ConnectionReuseStrategy connReuseStrategy,
                                     Http1StreamListener streamListener)

      Creates new instance of HttpRequestExecutor.
      Since:
        5.3

    - #### HttpRequestExecutor

          @Deprecated
          public HttpRequestExecutor(Timeout waitForContinue,
                                                 ConnectionReuseStrategy connReuseStrategy,
                                                 Http1StreamListener streamListener)

      Deprecated. Use `HttpRequestExecutor(Http1Config, ConnectionReuseStrategy, Http1StreamListener)`

    - #### HttpRequestExecutor

          public HttpRequestExecutor(ConnectionReuseStrategy connReuseStrategy)

    - #### HttpRequestExecutor

          public HttpRequestExecutor()

  - ### Method Detail

    - #### execute

          public ClassicHttpResponse execute(ClassicHttpRequest request,
                                             HttpClientConnection conn,
                                             HttpResponseInformationCallback informationCallback,
                                             HttpContext localContext)
                                      throws IOException,
                                             HttpException

      Sends the request and obtain a response.
      Parameters:
        `request` - the request to execute.
        `conn` - the connection over which to execute the request.
        `informationCallback` - callback to execute upon receipt of information status (1xx). May be null.
        `localContext` - the context
      Returns:
        the response to the request.
      Throws:
        `IOException` - in case of an I/O error.
        `HttpException` - in case of HTTP protocol violation or a processing problem.

    - #### execute

          public ClassicHttpResponse execute(ClassicHttpRequest request,
                                             HttpClientConnection conn,
                                             HttpContext context)
                                      throws IOException,
                                             HttpException

      Sends the request and obtain a response.
      Parameters:
        `request` - the request to execute.
        `conn` - the connection over which to execute the request.
        `context` - the context
      Returns:
        the response to the request.
      Throws:
        `IOException` - in case of an I/O error.
        `HttpException` - in case of HTTP protocol violation or a processing problem.

    - #### preProcess

          public void preProcess(ClassicHttpRequest request,
                                 HttpProcessor processor,
                                 HttpContext localContext)
                          throws HttpException,
                                 IOException

      Pre-process the given request using the given protocol processor and initiates the process of request execution.
      Parameters:
        `request` - the request to prepare
        `processor` - the processor to use
        `localContext` - the context for sending the request
      Throws:
        `IOException` - in case of an I/O error.
        `HttpException` - in case of HTTP protocol violation or a processing problem.

    - #### postProcess

          public void postProcess(ClassicHttpResponse response,
                                  HttpProcessor processor,
                                  HttpContext localContext)
                           throws HttpException,
                                  IOException

      Post-processes the given response using the given protocol processor and completes the process of request execution.

      This method does not read the response entity, if any. The connection over which content of the response entity is being streamed from cannot be reused until the response entity has been fully consumed.

      Parameters:
        `response` - the response object to post-process
        `processor` - the processor to use
        `localContext` - the context for post-processing the response
      Throws:
        `IOException` - in case of an I/O error.
        `HttpException` - in case of HTTP protocol violation or a processing problem.

    - #### keepAlive

          public boolean keepAlive(ClassicHttpRequest request,
                                   ClassicHttpResponse response,
                                   HttpClientConnection connection,
                                   HttpContext context)
                            throws IOException

      Determines whether the connection can be kept alive and is safe to be re-used for subsequent message exchanges.
      Parameters:
        `request` - current request object.
        `response` - current response object.
        `connection` - actual connection.
        `context` - current context.
      Returns:
        `true` is the connection can be kept-alive and re-used.
      Throws:
        `IOException` - in case of an I/O error.

    - #### builder

          public static HttpRequestExecutor.Builder builder()

      Create a new `HttpRequestExecutor.Builder`.
      Since:
        5.2

Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.