org.apache.http.nio.protocol

## Interface HttpAsyncClientExchangeHandler

- All Superinterfaces:
    AutoCloseable, Cancellable, Closeable
  All Known Implementing Classes:
    BasicAsyncClientExchangeHandler

      public interface HttpAsyncClientExchangeHandler
      extends Closeable, Cancellable

  `HttpAsyncClientExchangeHandler` represents a callback interface whose methods get invoked when executing one or multiple HTTP message exchanges on the client side.

  Individual `HttpAsyncClientExchangeHandler` are expected to make use of a `HttpProcessor` to generate mandatory protocol headers for all outgoing messages and apply common, cross-cutting message transformations to all incoming and outgoing messages. `HttpAsyncClientExchangeHandler`s can delegate implementation of application specific content generation and processing to a `HttpAsyncRequestProducer` and a `HttpAsyncResponseConsumer`.
  Since:
    4.3

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `consumeContent(ContentDecoder decoder, IOControl ioctrl)` Invoked to process a chunk of content from the `ContentDecoder`.
    `void` | `failed(Exception ex)` Invoked to signal that the response processing terminated abnormally.
    `HttpRequest` | `generateRequest()` Invoked to generate a HTTP request message head.
    `void` | `inputTerminated()` Invoked to signal that the connection has been terminated prematurely by the opposite end.
    `boolean` | `isDone()` Determines whether or not the response processing completed.
    `void` | `produceContent(ContentEncoder encoder, IOControl ioctrl)` Invoked to write out a chunk of content to the `ContentEncoder`.
    `void` | `requestCompleted()` Invoked to signal that the request has been fully written out.
    `void` | `responseCompleted()` Invoked to signal that the response has been fully processed.
    `void` | `responseReceived(HttpResponse response)` Invoked when a HTTP response message is received.

    - ### Methods inherited from interface java.io.Closeable

      `close`

    - ### Methods inherited from interface org.apache.http.concurrent.Cancellable

      `cancel`

- - ### Method Detail

    - #### generateRequest

          HttpRequest generateRequest()
                                      throws IOException,
                                             HttpException

      Invoked to generate a HTTP request message head. The message is expected to implement the `HttpEntityEnclosingRequest` interface if it is to enclose a content entity. The `produceContent(ContentEncoder, IOControl)` method will not be invoked if `HttpEntityEnclosingRequest.getEntity()` returns `null`.
      Returns:
        HTTP request message.
      Throws:
        `HttpException` - in case of HTTP protocol violation
        `IOException` - in case of an I/O error

    - #### produceContent

          void produceContent(ContentEncoder encoder,
                            IOControl ioctrl)
                              throws IOException

      Invoked to write out a chunk of content to the `ContentEncoder`. The `IOControl` interface can be used to suspend output event notifications if the producer is temporarily unable to produce more content.

      When all content is finished, the producer MUST call `ContentEncoder.complete()`. Failure to do so may cause the entity to be incorrectly delimited.

      Please note that the `ContentEncoder` object is not thread-safe and should only be used within the context of this method call. The `IOControl` object can be shared and used on other thread to resume output event notifications when more content is made available.
      Parameters:
        `encoder` - content encoder.
        `ioctrl` - I/O control of the underlying connection.
      Throws:
        `IOException` - in case of an I/O error

    - #### requestCompleted

          void requestCompleted()

      Invoked to signal that the request has been fully written out.

    - #### responseReceived

          void responseReceived(HttpResponse response)
                                throws IOException,
                                       HttpException

      Invoked when a HTTP response message is received. Please note that the `consumeContent(ContentDecoder, IOControl)` method will be invoked only if the response messages has a content entity enclosed.
      Parameters:
        `response` - HTTP response message.
      Throws:
        `HttpException` - in case of HTTP protocol violation
        `IOException` - in case of an I/O error

    - #### consumeContent

          void consumeContent(ContentDecoder decoder,
                            IOControl ioctrl)
                              throws IOException

      Invoked to process a chunk of content from the `ContentDecoder`. The `IOControl` interface can be used to suspend input event notifications if the consumer is temporarily unable to process content.

      The consumer can use the `ContentDecoder.isCompleted()` method to find out whether or not the message content has been fully consumed.

      Please note that the `ContentDecoder` object is not thread-safe and should only be used within the context of this method call. The `IOControl` object can be shared and used on other thread to resume input event notifications when the consumer is capable of processing more content.
      Parameters:
        `decoder` - content decoder.
        `ioctrl` - I/O control of the underlying connection.
      Throws:
        `IOException` - in case of an I/O error

    - #### responseCompleted

          void responseCompleted()
                                 throws IOException,
                                        HttpException

      Invoked to signal that the response has been fully processed.
      Throws:
        `IOException`
        `HttpException`

    - #### inputTerminated

          void inputTerminated()

      Invoked to signal that the connection has been terminated prematurely by the opposite end.

    - #### failed

          void failed(Exception ex)

      Invoked to signal that the response processing terminated abnormally.
      Parameters:
        `ex` - exception

    - #### isDone

          boolean isDone()

      Determines whether or not the response processing completed.

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