- All Known Subinterfaces:
WebResponseBody
Represents the payload body of a server response in a server exchange.
The response body basically provides multiple ways to produce the response payload.
- Since:
- 1.0
- Author:
- Jeremy Kuhn
- See Also:
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
A resource payload producer.static interface
ResponseBody.Sse<A,
B extends ResponseBody.Sse.Event<A>, C extends ResponseBody.Sse.EventFactory<A, B>> A server-sent events payload producer as defined by Server-Sent Events. -
Method Summary
Modifier and TypeMethodDescriptionvoid
empty()
Produces an empty payload.raw()
Returns a raw payload producer.resource()
Returns a resource payload producer.ResponseBody.Sse
<ByteBuf, ResponseBody.Sse.Event<ByteBuf>, ResponseBody.Sse.EventFactory<ByteBuf, ResponseBody.Sse.Event<ByteBuf>>> sse()
Returns a server-sent events payload producer as defined by Server-Sent Events.<T extends CharSequence>
ResponseBody.Sse<T, ResponseBody.Sse.Event<T>, ResponseBody.Sse.EventFactory<T, ResponseBody.Sse.Event<T>>> Returns a server-sent events payload producer as defined by Server-Sent Events.<T extends CharSequence>
OutboundData<T> string()
Returns a string payload producer.Transforms the payload publisher.
-
Method Details
-
transform
ResponseBody transform(Function<Publisher<ByteBuf>, Publisher<ByteBuf>> transformer) throws IllegalArgumentExceptionTransforms the payload publisher.
This can be used in an exchange interceptor in order to decorate response data publisher.
- Parameters:
transformer
- a request payload publisher transformer- Returns:
- the request body
- Throws:
IllegalArgumentException
- if data were already sent to the client
-
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
ResponseBody.Resource 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
-
sse
ResponseBody.Sse<ByteBuf,ResponseBody.Sse.Event<ByteBuf>, sse()ResponseBody.Sse.EventFactory<ByteBuf, ResponseBody.Sse.Event<ByteBuf>>> Returns a server-sent events payload producer as defined by Server-Sent Events.
A typical usage is:
exchange.response().body().sse().from( (events, data) -> Flux.interval(Duration.ofSeconds(1)) .map(seq -> events.create(event -> event .id(Long.toString(seq)) .event("seq") .value(Unpooled.unreleasableBuffer(Unpooled.copiedBuffer("Event #" + seq, Charsets.DEFAULT))) ) ) );
- Returns:
- a server-sent events payload producer
-
sseString
<T extends CharSequence> ResponseBody.Sse<T,ResponseBody.Sse.Event<T>, sseString()ResponseBody.Sse.EventFactory<T, ResponseBody.Sse.Event<T>>> Returns a server-sent events payload producer as defined by Server-Sent Events.
A typical usage is:
exchange.response().body().sseString().from( (events, data) -> Flux.interval(Duration.ofSeconds(1)) .map(seq -> events.create(event -> event .id(Long.toString(seq)) .event("seq") .value("Event #" + seq, Charsets.DEFAULT)) ) ) );
- Type Parameters:
T
- The type of char sequence- Returns:
- a server-sent events payload producer
-