Search in sources :

Example 1 with ReactiveAdapterRegistry

use of org.springframework.core.ReactiveAdapterRegistry in project spring-framework by spring-projects.

the class ModelInitializerTests method toInvocable.

private InvocableHandlerMethod toInvocable(Object controller, Method method) {
    ModelArgumentResolver resolver = new ModelArgumentResolver(new ReactiveAdapterRegistry());
    InvocableHandlerMethod handlerMethod = new InvocableHandlerMethod(controller, method);
    handlerMethod.setArgumentResolvers(Collections.singletonList(resolver));
    return handlerMethod;
}
Also used : InvocableHandlerMethod(org.springframework.web.reactive.result.method.InvocableHandlerMethod) SyncInvocableHandlerMethod(org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry)

Example 2 with ReactiveAdapterRegistry

use of org.springframework.core.ReactiveAdapterRegistry in project spring-framework by spring-projects.

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 org.springframework.web.reactive.function.client.WebClient WebClient} and
 * {@link org.springframework.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 5.2
 */
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.forClass(elementClass), adapter);
}
Also used : ReactiveAdapter(org.springframework.core.ReactiveAdapter) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) Publisher(org.reactivestreams.Publisher) MediaType(org.springframework.http.MediaType) MultiValueMap(org.springframework.util.MultiValueMap) Mono(reactor.core.publisher.Mono) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Collectors(java.util.stream.Collectors) ReactiveHttpOutputMessage(org.springframework.http.ReactiveHttpOutputMessage) List(java.util.List) HttpEntity(org.springframework.http.HttpEntity) ServerSentEvent(org.springframework.http.codec.ServerSentEvent) MultipartBodyBuilder(org.springframework.http.client.MultipartBodyBuilder) ClientHttpRequest(org.springframework.http.client.reactive.ClientHttpRequest) Nullable(org.springframework.lang.Nullable) ResolvableType(org.springframework.core.ResolvableType) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) HttpMessageWriter(org.springframework.http.codec.HttpMessageWriter) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Resource(org.springframework.core.io.Resource) Assert(org.springframework.util.Assert) ReactiveAdapter(org.springframework.core.ReactiveAdapter)

Example 3 with ReactiveAdapterRegistry

use of org.springframework.core.ReactiveAdapterRegistry in project spring-framework by spring-projects.

the class ModelInitializerTests method setup.

@BeforeEach
public void setup() {
    ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
    ArgumentResolverConfigurer resolverConfigurer = new ArgumentResolverConfigurer();
    resolverConfigurer.addCustomResolver(new ModelMethodArgumentResolver(adapterRegistry));
    ControllerMethodResolver methodResolver = new ControllerMethodResolver(resolverConfigurer, adapterRegistry, new StaticApplicationContext(), Collections.emptyList());
    this.modelInitializer = new ModelInitializer(methodResolver, adapterRegistry);
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ReactiveAdapterRegistry

use of org.springframework.core.ReactiveAdapterRegistry in project spring-framework by spring-projects.

the class RequestHeaderMethodArgumentResolverTests method setup.

@BeforeEach
@SuppressWarnings("resource")
public void setup() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.refresh();
    ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
    this.resolver = new RequestHeaderMethodArgumentResolver(context.getBeanFactory(), adapterRegistry);
    ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
    initializer.setConversionService(new DefaultFormattingConversionService());
    this.bindingContext = new BindingContext(initializer);
    Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null);
    this.paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 0);
    this.paramNamedValueStringArray = new SynthesizingMethodParameter(method, 1);
    this.paramSystemProperty = new SynthesizingMethodParameter(method, 2);
    this.paramResolvedNameWithExpression = new SynthesizingMethodParameter(method, 3);
    this.paramResolvedNameWithPlaceholder = new SynthesizingMethodParameter(method, 4);
    this.paramNamedValueMap = new SynthesizingMethodParameter(method, 5);
    this.paramDate = new SynthesizingMethodParameter(method, 6);
    this.paramInstant = new SynthesizingMethodParameter(method, 7);
    this.paramMono = new SynthesizingMethodParameter(method, 8);
}
Also used : SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) Method(java.lang.reflect.Method) BindingContext(org.springframework.web.reactive.BindingContext) DefaultFormattingConversionService(org.springframework.format.support.DefaultFormattingConversionService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ReactiveAdapterRegistry

use of org.springframework.core.ReactiveAdapterRegistry in project spring-framework by spring-projects.

the class CookieValueMethodArgumentResolverTests method setup.

@BeforeEach
@SuppressWarnings("resource")
public void setup() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.refresh();
    ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
    this.resolver = new CookieValueMethodArgumentResolver(context.getBeanFactory(), adapterRegistry);
    this.bindingContext = new BindingContext();
    Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null);
    this.cookieParameter = new SynthesizingMethodParameter(method, 0);
    this.cookieStringParameter = new SynthesizingMethodParameter(method, 1);
    this.stringParameter = new SynthesizingMethodParameter(method, 2);
    this.cookieMonoParameter = new SynthesizingMethodParameter(method, 3);
}
Also used : SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) Method(java.lang.reflect.Method) BindingContext(org.springframework.web.reactive.BindingContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)24 BeforeEach (org.junit.jupiter.api.BeforeEach)9 Test (org.junit.jupiter.api.Test)7 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 BindingContext (org.springframework.web.reactive.BindingContext)5 ReactiveAdapter (org.springframework.core.ReactiveAdapter)4 ByteArrayDecoder (org.springframework.core.codec.ByteArrayDecoder)4 ByteArrayEncoder (org.springframework.core.codec.ByteArrayEncoder)4 AntPathMatcher (org.springframework.util.AntPathMatcher)4 SimpleRouteMatcher (org.springframework.util.SimpleRouteMatcher)4 Method (java.lang.reflect.Method)3 List (java.util.List)3 StringDecoder (org.springframework.core.codec.StringDecoder)3 MediaType (org.springframework.http.MediaType)3 HttpMessageWriter (org.springframework.http.codec.HttpMessageWriter)3 Nullable (org.springframework.lang.Nullable)3 Assert (org.springframework.util.Assert)3 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 Publisher (org.reactivestreams.Publisher)2