Search in sources :

Example 1 with RequestMappingHandlerAdapter

use of org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter in project spring-framework by spring-projects.

the class WebFluxConfigurationSupport method requestMappingHandlerAdapter.

@Bean
public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
    RequestMappingHandlerAdapter adapter = createRequestMappingHandlerAdapter();
    adapter.setMessageReaders(getMessageReaders());
    adapter.setWebBindingInitializer(getConfigurableWebBindingInitializer());
    adapter.setReactiveAdapterRegistry(webFluxAdapterRegistry());
    List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
    addArgumentResolvers(resolvers);
    if (!resolvers.isEmpty()) {
        adapter.setCustomArgumentResolvers(resolvers);
    }
    return adapter;
}
Also used : ArrayList(java.util.ArrayList) HandlerMethodArgumentResolver(org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver) RequestMappingHandlerAdapter(org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter) Bean(org.springframework.context.annotation.Bean)

Example 2 with RequestMappingHandlerAdapter

use of org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter in project spring-framework by spring-projects.

the class WebFluxConfigurationSupportTests method requestMappingHandlerAdapter.

@Test
public void requestMappingHandlerAdapter() {
    ApplicationContext context = loadConfig(WebFluxConfig.class);
    String name = "requestMappingHandlerAdapter";
    RequestMappingHandlerAdapter adapter = context.getBean(name, RequestMappingHandlerAdapter.class);
    assertThat(adapter).isNotNull();
    List<HttpMessageReader<?>> readers = adapter.getMessageReaders();
    assertThat(readers.size()).isEqualTo(14);
    ResolvableType multiValueMapType = forClassWithGenerics(MultiValueMap.class, String.class, String.class);
    assertHasMessageReader(readers, forClass(byte[].class), APPLICATION_OCTET_STREAM);
    assertHasMessageReader(readers, forClass(ByteBuffer.class), APPLICATION_OCTET_STREAM);
    assertHasMessageReader(readers, forClass(String.class), TEXT_PLAIN);
    assertHasMessageReader(readers, forClass(Resource.class), IMAGE_PNG);
    assertHasMessageReader(readers, forClass(Message.class), new MediaType("application", "x-protobuf"));
    assertHasMessageReader(readers, multiValueMapType, APPLICATION_FORM_URLENCODED);
    assertHasMessageReader(readers, forClass(TestBean.class), APPLICATION_XML);
    assertHasMessageReader(readers, forClass(TestBean.class), APPLICATION_JSON);
    assertHasMessageReader(readers, forClass(TestBean.class), new MediaType("application", "x-jackson-smile"));
    assertHasMessageReader(readers, forClass(TestBean.class), null);
    WebBindingInitializer bindingInitializer = adapter.getWebBindingInitializer();
    assertThat(bindingInitializer).isNotNull();
    WebExchangeDataBinder binder = new WebExchangeDataBinder(new Object());
    bindingInitializer.initBinder(binder);
    name = "webFluxConversionService";
    ConversionService service = context.getBean(name, ConversionService.class);
    assertThat(binder.getConversionService()).isSameAs(service);
    name = "webFluxValidator";
    Validator validator = context.getBean(name, Validator.class);
    assertThat(binder.getValidator()).isSameAs(validator);
}
Also used : Message(com.google.protobuf.Message) Resource(org.springframework.core.io.Resource) ByteBuffer(java.nio.ByteBuffer) WebExchangeDataBinder(org.springframework.web.bind.support.WebExchangeDataBinder) HttpMessageReader(org.springframework.http.codec.HttpMessageReader) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ConversionService(org.springframework.core.convert.ConversionService) MediaType(org.springframework.http.MediaType) ResolvableType(org.springframework.core.ResolvableType) RequestMappingHandlerAdapter(org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter) Validator(org.springframework.validation.Validator) WebBindingInitializer(org.springframework.web.bind.support.WebBindingInitializer) Test(org.junit.jupiter.api.Test)

Example 3 with RequestMappingHandlerAdapter

use of org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter in project spring-framework by spring-projects.

the class WebFluxConfigurationSupportTests method customMessageConverterConfig.

@Test
public void customMessageConverterConfig() {
    ApplicationContext context = loadConfig(CustomMessageConverterConfig.class);
    String name = "requestMappingHandlerAdapter";
    RequestMappingHandlerAdapter adapter = context.getBean(name, RequestMappingHandlerAdapter.class);
    assertThat(adapter).isNotNull();
    List<HttpMessageReader<?>> messageReaders = adapter.getMessageReaders();
    assertThat(messageReaders.size()).isEqualTo(2);
    assertHasMessageReader(messageReaders, forClass(String.class), TEXT_PLAIN);
    assertHasMessageReader(messageReaders, forClass(TestBean.class), APPLICATION_XML);
}
Also used : HttpMessageReader(org.springframework.http.codec.HttpMessageReader) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) RequestMappingHandlerAdapter(org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter) Test(org.junit.jupiter.api.Test)

Example 4 with RequestMappingHandlerAdapter

use of org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter in project spring-framework by spring-projects.

the class DelegatingWebFluxConfigurationIntegrationTests method requestMappingHandlerAdapterWithPrimaryUsesQualifiedValidator.

@Test
void requestMappingHandlerAdapterWithPrimaryUsesQualifiedValidator() {
    load(registerPrimaryBean("testValidator", Validator.class));
    RequestMappingHandlerAdapter mappingHandlerAdapter = this.context.getBean(RequestMappingHandlerAdapter.class);
    assertThat(mappingHandlerAdapter.getWebBindingInitializer()).hasFieldOrPropertyWithValue("validator", this.context.getBean("webFluxValidator"));
    assertThat(this.context.getBeansOfType(Validator.class)).containsOnlyKeys("webFluxValidator", "testValidator");
}
Also used : RequestMappingHandlerAdapter(org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter) Validator(org.springframework.validation.Validator) Test(org.junit.jupiter.api.Test)

Example 5 with RequestMappingHandlerAdapter

use of org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter in project spring-framework by spring-projects.

the class DelegatingWebFluxConfigurationIntegrationTests method requestMappingHandlerAdapterUsesWebFluxInfrastructureByDefault.

@Test
void requestMappingHandlerAdapterUsesWebFluxInfrastructureByDefault() {
    load(context -> {
    });
    RequestMappingHandlerAdapter mappingHandlerAdapter = this.context.getBean(RequestMappingHandlerAdapter.class);
    assertThat(mappingHandlerAdapter.getReactiveAdapterRegistry()).isSameAs(this.context.getBean("webFluxAdapterRegistry"));
    assertThat(mappingHandlerAdapter.getWebBindingInitializer()).hasFieldOrPropertyWithValue("conversionService", this.context.getBean("webFluxConversionService"));
    assertThat(mappingHandlerAdapter.getWebBindingInitializer()).hasFieldOrPropertyWithValue("validator", this.context.getBean("webFluxValidator"));
}
Also used : RequestMappingHandlerAdapter(org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter) Test(org.junit.jupiter.api.Test)

Aggregations

RequestMappingHandlerAdapter (org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter)10 Test (org.junit.jupiter.api.Test)7 HandlerMethodArgumentResolver (org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver)3 ApplicationContext (org.springframework.context.ApplicationContext)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 Bean (org.springframework.context.annotation.Bean)2 HttpMessageReader (org.springframework.http.codec.HttpMessageReader)2 Validator (org.springframework.validation.Validator)2 Message (com.google.protobuf.Message)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)1 ResolvableType (org.springframework.core.ResolvableType)1 ConversionService (org.springframework.core.convert.ConversionService)1 Resource (org.springframework.core.io.Resource)1 FormattingConversionService (org.springframework.format.support.FormattingConversionService)1 MediaType (org.springframework.http.MediaType)1