Interface BaseExchange<A extends ExchangeContext,B,C>

Type Parameters:
A - The exchange context type
B - The request type
C - The response type
All Known Subinterfaces:
ErrorExchange<A>, ErrorWebExchange<A>, Exchange<A>, Exchange<A>, InterceptableExchange<A>, WebExchange<A>

public interface BaseExchange<A extends ExchangeContext,B,C>

Base HTTP exchange (request/response) for representing server or client exchanges.

An HTTP exchange basically comes down to a request and a response being exchanged between a client and a server. In a client exchange, the client sends the request to the server and receives the response from the server. In a server exchange, the server receives the request from the client and sends the response to the client.

A context is also attached to every exchange to provide contextual data and operation during during the processing of the exchange.

Since:
1.6
Author:
Jeremy Kuhn
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the context attached to the exchange.
    Returns the error that caused the cancellation of the exchange.
    Returns the protocol of the exchange (eg.
    Returns the request part of the exchange.
    default void
    Resets the exchange with a CANCEL(0x8) code.
    void
    reset(long code)
    Resets the exchange.
    Returns the response part of the exchange.
  • Method Details

    • getProtocol

      HttpVersion getProtocol()

      Returns the protocol of the exchange (eg. HTTP/1.1).

      Returns:
      the protocol
    • context

      A context()

      Returns the context attached to the exchange.

      Returns:
      the exchange context or null
    • request

      B request()

      Returns the request part of the exchange.

      Returns:
      the request part
    • response

      C response()

      Returns the response part of the exchange.

      Returns:
      the response part
    • reset

      default void reset()

      Resets the exchange with a CANCEL(0x8) code.

      See Also:
    • reset

      void reset(long code)

      Resets the exchange.

      This method is typically invoked to cancel the exchange (i.e. stop processing) by immediately cancelling active subscription to the response data publisher.

      Behaviour depends on the HTTP protocol version, an HTTP/1.x connection might be closed right away if is in an incomplete state when the request and/or the response were partially received and/or sent whereas with HTTP/2 connection this will just reset the stream bound to the exchange with the specified code as defined by RFC 7540 Section 7.

      Parameters:
      code - a code
    • getCancelCause

      Optional<Throwable> getCancelCause()

      Returns the error that caused the cancellation of the exchange.

      Exchange disposal resulting or not from an error is usually catched in the request data publisher which can be bound to the response data publisher in which case, errors can be catched by defining Flux.doOnError(java.util.function.Consumer) on the response data publisher. When the request data publisher is not consumed, terminated or not bound to the response data publisher, the response data publisher can be disposed without error, this method gives access to the error when intercepting the exchange disposal by defining Flux.doOnCancel(java.lang.Runnable) on the response data publisher.

      Returns:
      an optional returning the cancel error or an empty optional if the exchange hasn't been disposed or if it completed successfully (i.e. when both request and response data publishers completed successfully)