类 BodyInserters

java.lang.Object
cn.taketoday.web.reactive.function.BodyInserters

public abstract class BodyInserters extends Object
Static factory methods for BodyInserter implementations.
从以下版本开始:
4.0
作者:
Arjen Poutsma, Rossen Stoyanchev, Sebastien Deleuze, Harry Yang
  • 字段详细资料

    • RESOURCE_TYPE

      private static final cn.taketoday.core.ResolvableType RESOURCE_TYPE
    • SSE_TYPE

      private static final cn.taketoday.core.ResolvableType SSE_TYPE
    • FORM_DATA_TYPE

      private static final cn.taketoday.core.ResolvableType FORM_DATA_TYPE
    • MULTIPART_DATA_TYPE

      private static final cn.taketoday.core.ResolvableType MULTIPART_DATA_TYPE
    • EMPTY_INSERTER

      private static final BodyInserter<Void,ReactiveHttpOutputMessage> EMPTY_INSERTER
    • registry

      private static final cn.taketoday.core.ReactiveAdapterRegistry registry
  • 构造器详细资料

    • BodyInserters

      public BodyInserters()
  • 方法详细资料

    • empty

      public static <T> BodyInserter<T,ReactiveHttpOutputMessage> empty()
      Inserter that does not write.
      返回:
      the inserter
    • fromValue

      public static <T> BodyInserter<T,ReactiveHttpOutputMessage> fromValue(T body)
      Inserter to write the given value.

      Alternatively, consider using the bodyValue(Object) shortcuts on WebClient and ServerResponse.

      类型参数:
      T - the type of the body
      参数:
      body - the value to write
      返回:
      the inserter to write a single value
      抛出:
      IllegalArgumentException - if body is a Publisher or an instance of a type supported by ReactiveAdapterRegistry.getSharedInstance(), for which fromPublisher(Publisher, Class) or fromProducer(Object, Class) should be used.
      另请参阅:
    • fromProducer

      public static <T> BodyInserter<T,ReactiveHttpOutputMessage> fromProducer(T producer, Class<?> elementClass)
      Inserter to write the given producer of value(s) which must be a Publisher or another producer adaptable to a Publisher via ReactiveAdapterRegistry.

      Alternatively, consider using the body shortcuts on WebClient and ServerResponse.

      类型参数:
      T - the type of the body
      参数:
      producer - the source of body value(s).
      elementClass - the class of values to be produced
      返回:
      the inserter to write a producer
    • fromProducer

      public static <T> BodyInserter<T,ReactiveHttpOutputMessage> fromProducer(T producer, cn.taketoday.core.ParameterizedTypeReference<?> elementTypeRef)
      Inserter to write the given producer of value(s) which must be a Publisher or another producer adaptable to a Publisher via ReactiveAdapterRegistry.

      Alternatively, consider using the body shortcuts on WebClient and ServerResponse.

      类型参数:
      T - the type of the body
      参数:
      producer - the source of body value(s).
      elementTypeRef - the type of values to be produced
      返回:
      the inserter to write a producer
    • fromPublisher

      public static <T, P extends org.reactivestreams.Publisher<T>> BodyInserter<P,ReactiveHttpOutputMessage> fromPublisher(P publisher, Class<T> elementClass)
      Inserter to write the given Publisher.

      Alternatively, consider using the body shortcuts on WebClient and ServerResponse.

      类型参数:
      T - the type of the elements contained in the publisher
      P - the Publisher type
      参数:
      publisher - the publisher to write with
      elementClass - the class of elements in the publisher
      返回:
      the inserter to write a Publisher
    • fromPublisher

      public static <T, P extends org.reactivestreams.Publisher<T>> BodyInserter<P,ReactiveHttpOutputMessage> fromPublisher(P publisher, cn.taketoday.core.ParameterizedTypeReference<T> elementTypeRef)
      Inserter to write the given Publisher.

      Alternatively, consider using the body shortcuts on WebClient and ServerResponse.

      类型参数:
      T - the type of the elements contained in the publisher
      P - the Publisher type
      参数:
      publisher - the publisher to write with
      elementTypeRef - the type of elements contained in the publisher
      返回:
      the inserter to write a Publisher
    • fromResource

      public static <T extends cn.taketoday.core.io.Resource> BodyInserter<T,ReactiveHttpOutputMessage> fromResource(T resource)
      Inserter to write 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 message
      返回:
      the inserter to write a Publisher
    • fromServerSentEvents

      public static <T, S extends org.reactivestreams.Publisher<ServerSentEvent<T>>> BodyInserter<S,ServerHttpResponse> fromServerSentEvents(S eventsPublisher)
      Inserter to write the given ServerSentEvent publisher.

      Alternatively, you can provide event data objects via fromPublisher(Publisher, Class) or fromProducer(Object, Class), and set the "Content-Type" to text/event-stream.

      类型参数:
      T - the type of the data elements in the ServerSentEvent
      参数:
      eventsPublisher - the ServerSentEvent publisher to write to the response body
      返回:
      the inserter to write a ServerSentEvent publisher
      另请参阅:
    • fromFormData

      public static BodyInserters.FormInserter<String> fromFormData(cn.taketoday.util.MultiValueMap<String,String> formData)
      Return a BodyInserters.FormInserter to write the given MultiValueMap as URL-encoded form data. The returned inserter allows for additional entries to be added via BodyInserters.FormInserter.with(String, Object).

      Note that you can also use the bodyValue(Object) method in the request builders of both the WebClient and WebTestClient. In that case the setting of the request content type is also not required, just be sure the map contains String values only or otherwise it would be interpreted as a multipart request.

      参数:
      formData - the form data to write to the output message
      返回:
      the inserter that allows adding more form data
    • fromFormData

      public static BodyInserters.FormInserter<String> fromFormData(String name, String value)
      Return a BodyInserters.FormInserter to write the given key-value pair as URL-encoded form data. The returned inserter allows for additional entries to be added via BodyInserters.FormInserter.with(String, Object).
      参数:
      name - the key to add to the form
      value - the value to add to the form
      返回:
      the inserter that allows adding more form data
    • fromMultipartData

      public static BodyInserters.MultipartInserter fromMultipartData(cn.taketoday.util.MultiValueMap<String,?> multipartData)
      Return a BodyInserters.MultipartInserter to write the given MultiValueMap as multipart data. Values in the map can be an Object or an HttpEntity.

      Note that you can also build the multipart data externally with MultipartBodyBuilder, and pass the resulting map directly to the bodyValue(Object) shortcut method in WebClient.

      参数:
      multipartData - the form data to write to the output message
      返回:
      the inserter that allows adding more parts
      另请参阅:
    • fromMultipartData

      public static BodyInserters.MultipartInserter fromMultipartData(String name, Object value)
      Return a BodyInserters.MultipartInserter to write the given parts, as multipart data. Values in the map can be an Object or an HttpEntity.

      Note that you can also build the multipart data externally with MultipartBodyBuilder, and pass the resulting map directly to the bodyValue(Object) shortcut method in WebClient.

      参数:
      name - the part name
      value - the part value, an Object or HttpEntity
      返回:
      the inserter that allows adding more parts
    • fromMultipartAsyncData

      public static <T, P extends org.reactivestreams.Publisher<T>> BodyInserters.MultipartInserter fromMultipartAsyncData(String name, P publisher, Class<T> elementClass)
      Return a BodyInserters.MultipartInserter to write the given asynchronous parts, as multipart data.

      Note that you can also build the multipart data externally with MultipartBodyBuilder, and pass the resulting map directly to the bodyValue(Object) shortcut method in WebClient.

      参数:
      name - the part name
      publisher - the publisher that forms the part value
      elementClass - the class contained in the publisher
      返回:
      the inserter that allows adding more parts
    • fromMultipartAsyncData

      public static <T, P extends org.reactivestreams.Publisher<T>> BodyInserters.MultipartInserter fromMultipartAsyncData(String name, P publisher, cn.taketoday.core.ParameterizedTypeReference<T> typeReference)
      Variant of fromMultipartAsyncData(String, Publisher, Class) that accepts a ParameterizedTypeReference for the element type, which allows specifying generic type information.

      Note that you can also build the multipart data externally with MultipartBodyBuilder, and pass the resulting map directly to the bodyValue(Object) shortcut method in WebClient.

      参数:
      name - the part name
      publisher - the publisher that forms the part value
      typeReference - the type contained in the publisher
      返回:
      the inserter that allows adding more parts
    • fromDataBuffers

      public static <T extends org.reactivestreams.Publisher<cn.taketoday.core.io.buffer.DataBuffer>> BodyInserter<T,ReactiveHttpOutputMessage> fromDataBuffers(T publisher)
      Inserter to write the given Publisher<DataBuffer> to the body.
      类型参数:
      T - the type of the publisher
      参数:
      publisher - the data buffer publisher to write
      返回:
      the inserter to write directly to the body
      另请参阅:
    • writeWithMessageWriters

      private static <M extends ReactiveHttpOutputMessage> reactor.core.publisher.Mono<Void> writeWithMessageWriters(M outputMessage, BodyInserter.Context context, Object body, cn.taketoday.core.ResolvableType bodyType, @Nullable cn.taketoday.core.ReactiveAdapter adapter)
    • unsupportedError

      private static UnsupportedMediaTypeException unsupportedError(cn.taketoday.core.ResolvableType bodyType, BodyInserter.Context context, @Nullable MediaType mediaType)
    • write

      private static <T> reactor.core.publisher.Mono<Void> write(org.reactivestreams.Publisher<? extends T> input, cn.taketoday.core.ResolvableType type, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, BodyInserter.Context context, HttpMessageWriter<T> writer)
    • findWriter

      private static <T> HttpMessageWriter<T> findWriter(BodyInserter.Context context, cn.taketoday.core.ResolvableType elementType, @Nullable MediaType mediaType)
    • cast

      private static <T> HttpMessageWriter<T> cast(HttpMessageWriter<?> messageWriter)