Interface Exchange<A extends ExchangeContext>
- Type Parameters:
A
- the type of the exchange context
- All Superinterfaces:
BaseExchange<A,
Request, Mono<? extends Response>>
- All Known Subinterfaces:
UnboundExchange<A>
,WebExchange<A>
Represents an HTTP client exchange (request/response) between a client and a server.
An HTTP client exchange is obtained from an Endpoint
and allows to build and send an HTTP request or to open a WebSocket to an HTTP server represented by that endpoint.
The HTTP request is only sent when the exchange's response publisher is subscribed and if it hasn't been intercepted by an ExchangeInterceptor
which is then responsible for providing the
response.
endpoint.exchange(Method.POST, "/")
.flatMap(exchange -> {
exchange.request()
.headers(headers -> headers.contentType("text/plain"))
.body().get().string().value("This is a request body");
return exchange.response();
})
.subscribe(response -> {}); // send the request
As for an HTTP request, a WebSocket is only created when the WebSocket exchange publisher is subscribed.
endpoint.exchange("/")
.flatMap(Exchange::webSocket)
.subscribe(wsExchange -> {}); // create a WebSocket connection
- Since:
- 1.6
- Author:
- Jeremy Kuhn
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionresponse()
Returns the response part of the exchange.default Mono
<? extends WebSocketExchange<A>> Returns a WebSocket exchange publisher.Mono
<? extends WebSocketExchange<A>> Returns a WebSocket exchange publisher requesting the specified subprotocol.Methods inherited from interface io.inverno.mod.http.base.BaseExchange
context, getCancelCause, getProtocol, request, reset, reset
-
Method Details
-
response
Returns the response part of the exchange.
The connection is created and the request sent when the returned publisher is subscribed.
- Specified by:
response
in interfaceBaseExchange<A extends ExchangeContext,
Request, Mono<? extends Response>> - Returns:
- the response part
- Throws:
IllegalStateException
- if the exchange is not bound to an endpoint
-
webSocket
Returns a WebSocket exchange publisher.
The WebSocket connection and the corresponding
WebSocketExchange
are created when the returned publisher is subscribed.- Returns:
- a WebSocket exchange mono
- Throws:
IllegalStateException
- if the exchange is not bound to an endpoint
-
webSocket
Returns a WebSocket exchange publisher requesting the specified subprotocol.
The WebSocket connection and the corresponding
WebSocketExchange
are created when the returned publisher is subscribed.- Parameters:
subProtocol
- the subprotocol requested to the server by the client.- Returns:
- a WebSocket exchange mono
- Throws:
IllegalStateException
- if the exchange is not bound to an endpoint
-