public abstract class BodyInserters
extends java.lang.Object
BodyInserter
that write various bodies, such a reactive streams,
server-sent events, resources, etc.Modifier and Type | Field and Description |
---|---|
private static BodyInserter<java.lang.Void,ReactiveHttpOutputMessage> |
EMPTY |
private static ResolvableType |
FORM_TYPE |
private static ResolvableType |
RESOURCE_TYPE |
private static ResolvableType |
SERVER_SIDE_EVENT_TYPE |
Constructor and Description |
---|
BodyInserters() |
Modifier and Type | Method and Description |
---|---|
private static <T,P extends <any>,M extends ReactiveHttpOutputMessage> |
bodyInserterFor(P body,
ResolvableType bodyType) |
private static <T> HttpMessageWriter<T> |
cast(HttpMessageWriter<?> messageWriter) |
static <T> BodyInserter<T,ReactiveHttpOutputMessage> |
empty()
Return an empty
BodyInserter that writes nothing. |
private static <T> HttpMessageWriter<T> |
findMessageWriter(BodyInserter.Context context,
ResolvableType type,
MediaType mediaType) |
static <T extends <any>> |
fromDataBuffers(T publisher)
Return a
BodyInserter that writes the given Publisher<DataBuffer> to the body. |
static BodyInserter<MultiValueMap<java.lang.String,java.lang.String>,ClientHttpRequest> |
fromFormData(MultiValueMap<java.lang.String,java.lang.String> formData)
Return a
BodyInserter that writes the given MultiValueMap as URL-encoded
form data. |
static <T> BodyInserter<T,ReactiveHttpOutputMessage> |
fromObject(T body)
Return a
BodyInserter that writes the given single object. |
static <T,P extends <any>> |
fromPublisher(P publisher,
java.lang.Class<T> elementClass)
Return a
BodyInserter that writes the given Publisher . |
static <T,P extends <any>> |
fromPublisher(P publisher,
ResolvableType elementType)
Return a
BodyInserter that writes the given Publisher . |
static <T extends Resource> |
fromResource(T resource)
Return a
BodyInserter that writes the given Resource . |
static <T,S extends <any>> |
fromServerSentEvents(S eventsPublisher)
Return a
BodyInserter that writes the given ServerSentEvent publisher. |
static <T,S extends <any>> |
fromServerSentEvents(S eventsPublisher,
java.lang.Class<T> eventClass)
Return a
BodyInserter that writes the given Publisher publisher as
Server-Sent Events. |
static <T,S extends <any>> |
fromServerSentEvents(S eventsPublisher,
ResolvableType eventType)
Return a
BodyInserter that writes the given Publisher publisher as
Server-Sent Events. |
private static HttpMessageWriter<Resource> |
resourceHttpMessageWriter(BodyInserter.Context context) |
private static final ResolvableType RESOURCE_TYPE
private static final ResolvableType SERVER_SIDE_EVENT_TYPE
private static final ResolvableType FORM_TYPE
private static final BodyInserter<java.lang.Void,ReactiveHttpOutputMessage> EMPTY
public static <T> BodyInserter<T,ReactiveHttpOutputMessage> empty()
BodyInserter
that writes nothing.BodyInserter
public static <T> BodyInserter<T,ReactiveHttpOutputMessage> fromObject(T body)
BodyInserter
that writes the given single object.body
- the body of the responseBodyInserter
that writes a single objectpublic static <T,P extends <any>> BodyInserter<P,ReactiveHttpOutputMessage> fromPublisher(P publisher, java.lang.Class<T> elementClass)
BodyInserter
that writes the given Publisher
.T
- the type of the elements contained in the publisherP
- the type of the Publisher
publisher
- the publisher to stream to the response bodyelementClass
- the class of elements contained in the publisherBodyInserter
that writes a Publisher
public static <T,P extends <any>> BodyInserter<P,ReactiveHttpOutputMessage> fromPublisher(P publisher, ResolvableType elementType)
BodyInserter
that writes the given Publisher
.T
- the type of the elements contained in the publisherP
- the type of the Publisher
publisher
- the publisher to stream to the response bodyelementType
- the type of elements contained in the publisherBodyInserter
that writes a Publisher
public static <T extends Resource> BodyInserter<T,ReactiveHttpOutputMessage> fromResource(T resource)
BodyInserter
that writes the given Resource
.
If the resource can be resolved to a file, it will be copied using zero-copy.
T
- the type of the Resource
resource
- the resource to write to the output messageBodyInserter
that writes a Publisher
private static HttpMessageWriter<Resource> resourceHttpMessageWriter(BodyInserter.Context context)
public static <T,S extends <any>> BodyInserter<S,ServerHttpResponse> fromServerSentEvents(S eventsPublisher)
BodyInserter
that writes the given ServerSentEvent
publisher.T
- the type of the elements contained in the ServerSentEvent
eventsPublisher
- the ServerSentEvent
publisher to write to the response bodyBodyInserter
that writes a ServerSentEvent
publisherpublic static <T,S extends <any>> BodyInserter<S,ServerHttpResponse> fromServerSentEvents(S eventsPublisher, java.lang.Class<T> eventClass)
BodyInserter
that writes the given Publisher
publisher as
Server-Sent Events.T
- the type of the elements contained in the publishereventsPublisher
- the publisher to write to the response body as Server-Sent EventseventClass
- the class of event contained in the publisherBodyInserter
that writes the given Publisher
publisher as
Server-Sent Eventspublic static <T,S extends <any>> BodyInserter<S,ServerHttpResponse> fromServerSentEvents(S eventsPublisher, ResolvableType eventType)
BodyInserter
that writes the given Publisher
publisher as
Server-Sent Events.T
- the type of the elements contained in the publishereventsPublisher
- the publisher to write to the response body as Server-Sent EventseventType
- the type of event contained in the publisherBodyInserter
that writes the given Publisher
publisher as
Server-Sent Eventspublic static BodyInserter<MultiValueMap<java.lang.String,java.lang.String>,ClientHttpRequest> fromFormData(MultiValueMap<java.lang.String,java.lang.String> formData)
BodyInserter
that writes the given MultiValueMap
as URL-encoded
form data.formData
- the form data to write to the output messageBodyInserter
that writes form datapublic static <T extends <any>> BodyInserter<T,ReactiveHttpOutputMessage> fromDataBuffers(T publisher)
BodyInserter
that writes the given Publisher<DataBuffer>
to the body.T
- the type of the publisherpublisher
- the data buffer publisher to writeBodyInserter
that writes directly to the bodyReactiveHttpOutputMessage#writeWith(Publisher)
private static <T,P extends <any>,M extends ReactiveHttpOutputMessage> BodyInserter<T,M> bodyInserterFor(P body, ResolvableType bodyType)
private static <T> HttpMessageWriter<T> findMessageWriter(BodyInserter.Context context, ResolvableType type, MediaType mediaType)
private static <T> HttpMessageWriter<T> cast(HttpMessageWriter<?> messageWriter)