Search in sources :

Example 1 with ReactiveAdapterRegistry

use of cn.taketoday.core.ReactiveAdapterRegistry in project today-infrastructure by TAKETODAY.

the class BodyInserters method fromProducer.

/**
 * Inserter to write the given producer of value(s) which must be a {@link Publisher}
 * or another producer adaptable to a {@code Publisher} via
 * {@link ReactiveAdapterRegistry}.
 * <p>Alternatively, consider using the {@code body} shortcuts on
 * {@link WebClient WebClient} and
 * {@link cn.taketoday.web.reactive.function.server.ServerResponse ServerResponse}.
 *
 * @param <T> the type of the body
 * @param producer the source of body value(s).
 * @param elementClass the class of values to be produced
 * @return the inserter to write a producer
 * @since 4.0
 */
public static <T> BodyInserter<T, ReactiveHttpOutputMessage> fromProducer(T producer, Class<?> elementClass) {
    Assert.notNull(producer, "'producer' must not be null");
    Assert.notNull(elementClass, "'elementClass' must not be null");
    ReactiveAdapter adapter = ReactiveAdapterRegistry.getSharedInstance().getAdapter(producer.getClass());
    Assert.notNull(adapter, "'producer' type is unknown to ReactiveAdapterRegistry");
    return (message, context) -> writeWithMessageWriters(message, context, producer, ResolvableType.fromClass(elementClass), adapter);
}
Also used : LinkedMultiValueMap(cn.taketoday.core.LinkedMultiValueMap) Assert(cn.taketoday.lang.Assert) WebClient(cn.taketoday.web.reactive.function.client.WebClient) ServerSentEvent(cn.taketoday.http.codec.ServerSentEvent) Publisher(org.reactivestreams.Publisher) ReactiveAdapterRegistry(cn.taketoday.core.ReactiveAdapterRegistry) ResolvableType(cn.taketoday.core.ResolvableType) Resource(cn.taketoday.core.io.Resource) MultipartBodyBuilder(cn.taketoday.http.client.MultipartBodyBuilder) HttpMessageWriter(cn.taketoday.http.codec.HttpMessageWriter) ServerHttpResponse(cn.taketoday.http.server.reactive.ServerHttpResponse) Mono(reactor.core.publisher.Mono) Collectors(java.util.stream.Collectors) List(java.util.List) ReactiveAdapter(cn.taketoday.core.ReactiveAdapter) ReactiveHttpOutputMessage(cn.taketoday.http.ReactiveHttpOutputMessage) Nullable(cn.taketoday.lang.Nullable) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) MultiValueMap(cn.taketoday.core.MultiValueMap) HttpEntity(cn.taketoday.http.HttpEntity) TypeReference(cn.taketoday.core.TypeReference) MediaType(cn.taketoday.http.MediaType) ClientHttpRequest(cn.taketoday.http.client.reactive.ClientHttpRequest) ReactiveAdapter(cn.taketoday.core.ReactiveAdapter)

Example 2 with ReactiveAdapterRegistry

use of cn.taketoday.core.ReactiveAdapterRegistry in project today-infrastructure by TAKETODAY.

the class ReactiveTypeHandlerTests method setup.

@BeforeEach
public void setup() throws Exception {
    ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean();
    factoryBean.afterPropertiesSet();
    ContentNegotiationManager manager = factoryBean.getObject();
    ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
    this.handler = new ReactiveTypeHandler(adapterRegistry, new SyncTaskExecutor(), manager);
    resetRequest();
}
Also used : ContentNegotiationManagerFactoryBean(cn.taketoday.web.accept.ContentNegotiationManagerFactoryBean) SyncTaskExecutor(cn.taketoday.core.task.SyncTaskExecutor) ContentNegotiationManager(cn.taketoday.web.accept.ContentNegotiationManager) ReactiveAdapterRegistry(cn.taketoday.core.ReactiveAdapterRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ReactiveAdapterRegistry

use of cn.taketoday.core.ReactiveAdapterRegistry in project today-framework by TAKETODAY.

the class ReactiveTypeHandlerTests method setup.

@BeforeEach
public void setup() throws Exception {
    ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean();
    factoryBean.afterPropertiesSet();
    ContentNegotiationManager manager = factoryBean.getObject();
    ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
    this.handler = new ReactiveTypeHandler(adapterRegistry, new SyncTaskExecutor(), manager);
    resetRequest();
}
Also used : ContentNegotiationManagerFactoryBean(cn.taketoday.web.accept.ContentNegotiationManagerFactoryBean) SyncTaskExecutor(cn.taketoday.core.task.SyncTaskExecutor) ContentNegotiationManager(cn.taketoday.web.accept.ContentNegotiationManager) ReactiveAdapterRegistry(cn.taketoday.core.ReactiveAdapterRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ReactiveAdapterRegistry

use of cn.taketoday.core.ReactiveAdapterRegistry in project today-framework by TAKETODAY.

the class BodyInserters method fromProducer.

/**
 * Inserter to write the given producer of value(s) which must be a {@link Publisher}
 * or another producer adaptable to a {@code Publisher} via
 * {@link ReactiveAdapterRegistry}.
 * <p>Alternatively, consider using the {@code body} shortcuts on
 * {@link WebClient WebClient} and
 * {@link cn.taketoday.web.reactive.function.server.ServerResponse ServerResponse}.
 *
 * @param <T> the type of the body
 * @param producer the source of body value(s).
 * @param elementTypeRef the type of values to be produced
 * @return the inserter to write a producer
 * @since 4.0
 */
public static <T> BodyInserter<T, ReactiveHttpOutputMessage> fromProducer(T producer, TypeReference<?> elementTypeRef) {
    Assert.notNull(producer, "'producer' must not be null");
    Assert.notNull(elementTypeRef, "'elementTypeRef' must not be null");
    ReactiveAdapter adapter = ReactiveAdapterRegistry.getSharedInstance().getAdapter(producer.getClass());
    Assert.notNull(adapter, "'producer' type is unknown to ReactiveAdapterRegistry");
    return (message, context) -> writeWithMessageWriters(message, context, producer, ResolvableType.fromType(elementTypeRef), adapter);
}
Also used : LinkedMultiValueMap(cn.taketoday.core.LinkedMultiValueMap) Assert(cn.taketoday.lang.Assert) WebClient(cn.taketoday.web.reactive.function.client.WebClient) ServerSentEvent(cn.taketoday.http.codec.ServerSentEvent) Publisher(org.reactivestreams.Publisher) ReactiveAdapterRegistry(cn.taketoday.core.ReactiveAdapterRegistry) ResolvableType(cn.taketoday.core.ResolvableType) Resource(cn.taketoday.core.io.Resource) MultipartBodyBuilder(cn.taketoday.http.client.MultipartBodyBuilder) HttpMessageWriter(cn.taketoday.http.codec.HttpMessageWriter) ServerHttpResponse(cn.taketoday.http.server.reactive.ServerHttpResponse) Mono(reactor.core.publisher.Mono) Collectors(java.util.stream.Collectors) List(java.util.List) ReactiveAdapter(cn.taketoday.core.ReactiveAdapter) ReactiveHttpOutputMessage(cn.taketoday.http.ReactiveHttpOutputMessage) Nullable(cn.taketoday.lang.Nullable) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) MultiValueMap(cn.taketoday.core.MultiValueMap) HttpEntity(cn.taketoday.http.HttpEntity) TypeReference(cn.taketoday.core.TypeReference) MediaType(cn.taketoday.http.MediaType) ClientHttpRequest(cn.taketoday.http.client.reactive.ClientHttpRequest) ReactiveAdapter(cn.taketoday.core.ReactiveAdapter)

Example 5 with ReactiveAdapterRegistry

use of cn.taketoday.core.ReactiveAdapterRegistry in project today-framework by TAKETODAY.

the class BodyInserters method fromProducer.

/**
 * Inserter to write the given producer of value(s) which must be a {@link Publisher}
 * or another producer adaptable to a {@code Publisher} via
 * {@link ReactiveAdapterRegistry}.
 * <p>Alternatively, consider using the {@code body} shortcuts on
 * {@link WebClient WebClient} and
 * {@link cn.taketoday.web.reactive.function.server.ServerResponse ServerResponse}.
 *
 * @param <T> the type of the body
 * @param producer the source of body value(s).
 * @param elementClass the class of values to be produced
 * @return the inserter to write a producer
 * @since 4.0
 */
public static <T> BodyInserter<T, ReactiveHttpOutputMessage> fromProducer(T producer, Class<?> elementClass) {
    Assert.notNull(producer, "'producer' must not be null");
    Assert.notNull(elementClass, "'elementClass' must not be null");
    ReactiveAdapter adapter = ReactiveAdapterRegistry.getSharedInstance().getAdapter(producer.getClass());
    Assert.notNull(adapter, "'producer' type is unknown to ReactiveAdapterRegistry");
    return (message, context) -> writeWithMessageWriters(message, context, producer, ResolvableType.fromClass(elementClass), adapter);
}
Also used : LinkedMultiValueMap(cn.taketoday.core.LinkedMultiValueMap) Assert(cn.taketoday.lang.Assert) WebClient(cn.taketoday.web.reactive.function.client.WebClient) ServerSentEvent(cn.taketoday.http.codec.ServerSentEvent) Publisher(org.reactivestreams.Publisher) ReactiveAdapterRegistry(cn.taketoday.core.ReactiveAdapterRegistry) ResolvableType(cn.taketoday.core.ResolvableType) Resource(cn.taketoday.core.io.Resource) MultipartBodyBuilder(cn.taketoday.http.client.MultipartBodyBuilder) HttpMessageWriter(cn.taketoday.http.codec.HttpMessageWriter) ServerHttpResponse(cn.taketoday.http.server.reactive.ServerHttpResponse) Mono(reactor.core.publisher.Mono) Collectors(java.util.stream.Collectors) List(java.util.List) ReactiveAdapter(cn.taketoday.core.ReactiveAdapter) ReactiveHttpOutputMessage(cn.taketoday.http.ReactiveHttpOutputMessage) Nullable(cn.taketoday.lang.Nullable) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) MultiValueMap(cn.taketoday.core.MultiValueMap) HttpEntity(cn.taketoday.http.HttpEntity) TypeReference(cn.taketoday.core.TypeReference) MediaType(cn.taketoday.http.MediaType) ClientHttpRequest(cn.taketoday.http.client.reactive.ClientHttpRequest) ReactiveAdapter(cn.taketoday.core.ReactiveAdapter)

Aggregations

ReactiveAdapterRegistry (cn.taketoday.core.ReactiveAdapterRegistry)6 LinkedMultiValueMap (cn.taketoday.core.LinkedMultiValueMap)4 MultiValueMap (cn.taketoday.core.MultiValueMap)4 ReactiveAdapter (cn.taketoday.core.ReactiveAdapter)4 ResolvableType (cn.taketoday.core.ResolvableType)4 TypeReference (cn.taketoday.core.TypeReference)4 Resource (cn.taketoday.core.io.Resource)4 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)4 HttpEntity (cn.taketoday.http.HttpEntity)4 MediaType (cn.taketoday.http.MediaType)4 ReactiveHttpOutputMessage (cn.taketoday.http.ReactiveHttpOutputMessage)4 MultipartBodyBuilder (cn.taketoday.http.client.MultipartBodyBuilder)4 ClientHttpRequest (cn.taketoday.http.client.reactive.ClientHttpRequest)4 HttpMessageWriter (cn.taketoday.http.codec.HttpMessageWriter)4 ServerSentEvent (cn.taketoday.http.codec.ServerSentEvent)4 ServerHttpResponse (cn.taketoday.http.server.reactive.ServerHttpResponse)4 Assert (cn.taketoday.lang.Assert)4 Nullable (cn.taketoday.lang.Nullable)4 WebClient (cn.taketoday.web.reactive.function.client.WebClient)4 List (java.util.List)4