Top Description Inners Fields Constructors Methods
org.springframework.web.reactive.function

public abstract Class BodyInserters

extends Object
Class Inheritance
Imports
java.io.OutputStream, java.util.List, java.util.concurrent.Executor, java.util.function.Consumer, org.reactivestreams.Publisher, reactor.core.publisher.Mono, org.springframework.core.ParameterizedTypeReference, .ReactiveAdapter, .ReactiveAdapterRegistry, .ResolvableType, org.springframework.core.io.Resource, org.springframework.core.io.buffer.DataBuffer, .DataBufferFactory, .DataBufferUtils, org.springframework.http.HttpEntity, .MediaType, .ReactiveHttpOutputMessage, org.springframework.http.client.MultipartBodyBuilder, org.springframework.http.client.reactive.ClientHttpRequest, org.springframework.http.codec.HttpMessageWriter, .ServerSentEvent, org.springframework.http.server.reactive.ServerHttpResponse, org.springframework.lang.Nullable, org.springframework.util.Assert, .LinkedMultiValueMap, .MultiValueMap

Static factory methods for BodyInserter implementations.
Authors
Arjen Poutsma, Rossen Stoyanchev, Sebastien Deleuze
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
public static interface
BodyInserters.FormInserter<
the value type
T
>

Extension of BodyInserter that allows for adding form data or multipart form data.

public static interface
BodyInserters.MultipartInserter

Extension of FormInserter that allows for adding asynchronous parts.

Field Summary

Modifier and TypeField and Description
private static final BodyInserter<Void, ReactiveHttpOutputMessage>
private static final ResolvableType
private static final ResolvableType
private static final ReactiveAdapterRegistry
private static final ResolvableType
private static final ResolvableType

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static <T> HttpMessageWriter<T>
cast(HttpMessageWriter<?> messageWriter)

public static <T> BodyInserter<T, ReactiveHttpOutputMessage>

Returns:

the inserter
empty
()

Inserter that does not write.

private static <T> HttpMessageWriter<T>
findWriter(BodyInserter.Context context, ResolvableType elementType, MediaType mediaType)

public static <
the type of the publisher
T extends Publisher<DataBuffer>
>
BodyInserter<T, ReactiveHttpOutputMessage>

Returns:

the inserter to write directly to the body
fromDataBuffers
(T
the data buffer publisher to write
publisher
)

Inserter to write the given Publisher<DataBuffer> to the body.

public static BodyInserters.FormInserter<String>

Returns:

the inserter that allows adding more form data
fromFormData
(MultiValueMap<String, String>
the form data to write to the output message
formData
)

Return a FormInserter to write the given MultiValueMap as URL-encoded form data.

public static BodyInserters.FormInserter<String>

Returns:

the inserter that allows adding more form data
fromFormData
(String
the key to add to the form
name
,
String
the value to add to the form
value
)

Return a FormInserter to write the given key-value pair as URL-encoded form data.

public static <T, P extends Publisher<T>> BodyInserters.MultipartInserter

Returns:

the inserter that allows adding more parts
fromMultipartAsyncData
(String
the part name
name
,
P
the publisher that forms the part value
publisher
,
Class<T>
the class contained in the publisher
elementClass
)

Return a MultipartInserter to write the given asynchronous parts, as multipart data.

public static <T, P extends Publisher<T>> BodyInserters.MultipartInserter

Returns:

the inserter that allows adding more parts
fromMultipartAsyncData
(String
the part name
name
,
P
the publisher that forms the part value
publisher
,
ParameterizedTypeReference<T>
the type contained in the publisher
typeReference
)

Variant of fromMultipartAsyncData(String, Publisher, Class) that accepts a ParameterizedTypeReference for the element type, which allows specifying generic type information.

public static BodyInserters.MultipartInserter

Returns:

the inserter that allows adding more parts
fromMultipartData
(MultiValueMap<String, ?>
the form data to write to the output message
multipartData
)

Return a MultipartInserter to write the given MultiValueMap as multipart data.

public static BodyInserters.MultipartInserter

Returns:

the inserter that allows adding more parts
fromMultipartData
(String
the part name
name
,
Object
the part value, an Object or HttpEntity
value
)

Return a MultipartInserter to write the given parts, as multipart data.

public static <
the type of the body
T
>
BodyInserter<T, ReactiveHttpOutputMessage>

Returns:

the inserter to write a single object
fromObject
(T
the body to write to the response
body
)
Deprecated As of Spring Framework 5.2, in favor of fromValue(Object)

Inserter to write the given object.

public static <T extends Publisher<DataBuffer>> BodyInserter<T, ReactiveHttpOutputMessage>

Returns:

an inserter that writes what is written to the output stream
fromOutputStream
(Consumer<OutputStream>
invoked with an OutputStream that writes to the output message
outputStreamConsumer
,
Executor
used to invoke the outputStreamHandler on a separate thread
executor
)

Inserter based on bytes written to a OutputStream.

public static <T extends Publisher<DataBuffer>> BodyInserter<T, ReactiveHttpOutputMessage>

Returns:

an inserter that writes what is written to the output stream
fromOutputStream
(Consumer<OutputStream>
invoked with an OutputStream that writes to the output message
outputStreamConsumer
,
Executor
used to invoke the outputStreamHandler on a separate thread
executor
,
int
minimum size of the buffer produced by the publisher
chunkSize
)

Inserter based on bytes written to a OutputStream.

public static <
the type of the body
T
>
BodyInserter<T, ReactiveHttpOutputMessage>

Returns:

the inserter to write a producer
fromProducer
(T
the source of body value(s).
producer
,
Class<?>
the class of values to be produced
elementClass
)

Inserter to write the given producer of value(s) which must be a Publisher or another producer adaptable to a Publisher via ReactiveAdapterRegistry.

public static <
the type of the body
T
>
BodyInserter<T, ReactiveHttpOutputMessage>

Returns:

the inserter to write a producer
fromProducer
(T
the source of body value(s).
producer
,
ParameterizedTypeReference<?>
the type of values to be produced
elementTypeRef
)

Inserter to write the given producer of value(s) which must be a Publisher or another producer adaptable to a Publisher via ReactiveAdapterRegistry.

public static <
the type of the elements contained in the publisher
T
,
the Publisher type
P extends Publisher<T>
>
BodyInserter<P, ReactiveHttpOutputMessage>

Returns:

the inserter to write a Publisher
fromPublisher
(P
the publisher to write with
publisher
,
Class<T>
the class of elements in the publisher
elementClass
)

Inserter to write the given Publisher.

public static <
the type of the elements contained in the publisher
T
,
the Publisher type
P extends Publisher<T>
>
BodyInserter<P, ReactiveHttpOutputMessage>

Returns:

the inserter to write a Publisher
fromPublisher
(P
the publisher to write with
publisher
,
ParameterizedTypeReference<T>
the type of elements contained in the publisher
elementTypeRef
)

Inserter to write the given Publisher.

public static <
the type of the Resource
T extends Resource
>
BodyInserter<T, ReactiveHttpOutputMessage>

Returns:

the inserter to write a Publisher
fromResource
(T
the resource to write to the output message
resource
)

Inserter to write the given Resource.

public static <
the type of the data elements in the ServerSentEvent
T
, S extends Publisher<ServerSentEvent<T>>>
BodyInserter<S, ServerHttpResponse>

Returns:

the inserter to write a ServerSentEvent publisher
fromServerSentEvents
(S
the ServerSentEvent publisher to write to the response body
eventsPublisher
)

Inserter to write the given ServerSentEvent publisher.

public static <
the type of the body
T
>
BodyInserter<T, ReactiveHttpOutputMessage>

Returns:

the inserter to write a single value
fromValue
(T
the value to write
body
)

Inserter to write the given value.

private static UnsupportedMediaTypeException
private static <T> Mono<Void>
write(Publisher<? extends T> input, ResolvableType type, MediaType mediaType, ReactiveHttpOutputMessage message, BodyInserter.Context context, HttpMessageWriter<T> writer)

private static <M extends ReactiveHttpOutputMessage> Mono<Void>
writeWithMessageWriters(M outputMessage, BodyInserter.Context context, Object body, ResolvableType bodyType, ReactiveAdapter adapter)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait