Interface InterceptableResponseBody
An interceptable response body allows to provide a response payload in case the request sent is cancelled and/or transform the response payload received from the endpoint.
It is exposed in the InterceptableRequest
, once the request has been sent to the endpoint and an actual response received it is no longer possible to provide a response payload and
IllegalStateException
shall be raised.
- Since:
- 1.6
- Author:
- Jeremy Kuhn
- See Also:
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
A resource payload producer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
empty()
Produces an empty payload.raw()
Returns a raw payload producer.resource()
Returns a resource payload producer.<T extends CharSequence>
OutboundData<T> string()
Returns a string payload producer.Transforms the response payload publisher.
-
Method Details
-
transform
InterceptableResponseBody transform(Function<Publisher<ByteBuf>, Publisher<ByteBuf>> transformer) throws IllegalStateExceptionTransforms the response payload publisher.
This can be used in an exchange interceptor in order to decorate the response data publisher.
- Parameters:
transformer
- a payload publisher transformer- Returns:
- the response body
- Throws:
IllegalStateException
- if the response payload publisher has already been subscribed
-
empty
void empty()Produces an empty payload.
If a payload has already been provided this method does nothing.
A typical usage is:
exchange.response().body().empty();
-
raw
OutboundData<ByteBuf> raw()Returns a raw payload producer.
A typical usage is:
exchange.response().body().raw().stream( Flux.just( Unpooled.unreleasableBuffer(Unpooled.copiedBuffer("Hello ", Charsets.DEFAULT)), Unpooled.unreleasableBuffer(Unpooled.copiedBuffer("World!", Charsets.DEFAULT)) ) );
- Returns:
- a raw payload producer
-
string
Returns a string payload producer.
A typical usage is:
exchange.response().body().string().stream( Flux.just( Unpooled.unreleasableBuffer("Hello "), Unpooled.unreleasableBuffer("World!") ) );
- Type Parameters:
T
- the type of char sequence- Returns:
- a string payload producer
-
resource
InterceptableResponseBody.ResourceData resource()Returns a resource payload producer.
A typical usage is:
ResourceService resourceService = ... exchange.response().body().resource().value(resourceService.get("file:/path/to/resource");
- Returns:
- a resource payload producer
-