public abstract class BodyInserters
extends java.lang.Object
BodyInserter
that write various bodies, such a reactive streams,
server-sent events, resources, etc.Constructor and Description |
---|
BodyInserters() |
Modifier and Type | Method and Description |
---|---|
static <T> BodyInserter<T,ReactiveHttpOutputMessage> |
empty()
Return an empty
BodyInserter that writes nothing. |
static <T extends org.reactivestreams.Publisher<DataBuffer>> |
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 BodyInserter<MultiValueMap<java.lang.String,?>,ClientHttpRequest> |
fromMultipartData(MultiValueMap<java.lang.String,?> multipartData)
Return a
BodyInserter that writes the given MultiValueMap as Multipart
data. |
static <T> BodyInserter<T,ReactiveHttpOutputMessage> |
fromObject(T body)
Return a
BodyInserter that writes the given single object. |
static <T,P extends org.reactivestreams.Publisher<T>> |
fromPublisher(P publisher,
java.lang.Class<T> elementClass)
Return a
BodyInserter that writes the given Publisher . |
static <T,P extends org.reactivestreams.Publisher<T>> |
fromPublisher(P publisher,
ParameterizedTypeReference<T> typeReference)
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 org.reactivestreams.Publisher<ServerSentEvent<T>>> |
fromServerSentEvents(S eventsPublisher)
Return a
BodyInserter that writes the given ServerSentEvent publisher. |
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 org.reactivestreams.Publisher<T>> 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 org.reactivestreams.Publisher<T>> BodyInserter<P,ReactiveHttpOutputMessage> fromPublisher(P publisher, ParameterizedTypeReference<T> typeReference)
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 bodytypeReference
- 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
public static <T,S extends org.reactivestreams.Publisher<ServerSentEvent<T>>> BodyInserter<S,ServerHttpResponse> fromServerSentEvents(S eventsPublisher)
BodyInserter
that writes the given ServerSentEvent
publisher.
Note that a SSE BodyInserter
can also be obtained by passing a stream of strings
or POJOs (to be encoded as JSON) to fromPublisher(Publisher, Class)
, and specifying a
text/event-stream
Content-Type.
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 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 BodyInserter<MultiValueMap<java.lang.String,?>,ClientHttpRequest> fromMultipartData(MultiValueMap<java.lang.String,?> multipartData)
BodyInserter
that writes the given MultiValueMap
as Multipart
data.multipartData
- the form data to write to the output messageBodyInserter
that writes form datapublic static <T extends org.reactivestreams.Publisher<DataBuffer>> 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)