use of org.springframework.http.codec.ServerCodecConfigurer in project spring-framework by spring-projects.
the class ServerCodecConfigurerTests method cloneConfigurer.
@Test
public void cloneConfigurer() {
ServerCodecConfigurer clone = this.configurer.clone();
MultipartHttpMessageReader reader = new MultipartHttpMessageReader(new DefaultPartHttpMessageReader());
Jackson2JsonEncoder encoder = new Jackson2JsonEncoder();
clone.defaultCodecs().multipartReader(reader);
clone.defaultCodecs().serverSentEventEncoder(encoder);
// Clone has the customizations
HttpMessageReader<?> actualReader = findCodec(clone.getReaders(), MultipartHttpMessageReader.class);
ServerSentEventHttpMessageWriter actualWriter = findCodec(clone.getWriters(), ServerSentEventHttpMessageWriter.class);
assertThat(actualReader).isSameAs(reader);
assertThat(actualWriter.getEncoder()).isSameAs(encoder);
// Original does not have the customizations
actualReader = findCodec(this.configurer.getReaders(), MultipartHttpMessageReader.class);
actualWriter = findCodec(this.configurer.getWriters(), ServerSentEventHttpMessageWriter.class);
assertThat(actualReader).isNotSameAs(reader);
assertThat(actualWriter.getEncoder()).isNotSameAs(encoder);
}
use of org.springframework.http.codec.ServerCodecConfigurer in project spring-framework by spring-projects.
the class ControllerMethodResolverTests method setup.
@BeforeEach
public void setup() {
ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer();
resolvers.addCustomResolver(new CustomArgumentResolver());
resolvers.addCustomResolver(new CustomSyncArgumentResolver());
ServerCodecConfigurer codecs = ServerCodecConfigurer.create();
codecs.customCodecs().register(new ByteArrayDecoder());
codecs.customCodecs().register(new ByteBufferDecoder());
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
applicationContext.registerBean(TestControllerAdvice.class);
applicationContext.refresh();
this.methodResolver = new ControllerMethodResolver(resolvers, ReactiveAdapterRegistry.getSharedInstance(), applicationContext, codecs.getReaders());
Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::handle).method();
this.handlerMethod = new HandlerMethod(new TestController(), method);
}
use of org.springframework.http.codec.ServerCodecConfigurer in project spring-framework by spring-projects.
the class DelegatingWebFluxConfigurationTests method requestMappingHandlerAdapter.
@Test
public void requestMappingHandlerAdapter() {
delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
ReactiveAdapterRegistry reactiveAdapterRegistry = delegatingConfig.webFluxAdapterRegistry();
ServerCodecConfigurer serverCodecConfigurer = delegatingConfig.serverCodecConfigurer();
FormattingConversionService formattingConversionService = delegatingConfig.webFluxConversionService();
Validator validator = delegatingConfig.webFluxValidator();
ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) this.delegatingConfig.requestMappingHandlerAdapter(reactiveAdapterRegistry, serverCodecConfigurer, formattingConversionService, validator).getWebBindingInitializer();
verify(webFluxConfigurer).configureHttpMessageCodecs(codecsConfigurer.capture());
verify(webFluxConfigurer).getValidator();
verify(webFluxConfigurer).getMessageCodesResolver();
verify(webFluxConfigurer).addFormatters(formatterRegistry.capture());
verify(webFluxConfigurer).configureArgumentResolvers(any());
assertThat(initializer).isNotNull();
boolean condition = initializer.getValidator() instanceof LocalValidatorFactoryBean;
assertThat(condition).isTrue();
assertThat(initializer.getConversionService()).isSameAs(formatterRegistry.getValue());
assertThat(codecsConfigurer.getValue().getReaders().size()).isEqualTo(14);
}
use of org.springframework.http.codec.ServerCodecConfigurer in project spring-framework by spring-projects.
the class RequestMappingHandlerAdapter method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(this.applicationContext, "ApplicationContext is required");
if (CollectionUtils.isEmpty(this.messageReaders)) {
ServerCodecConfigurer codecConfigurer = ServerCodecConfigurer.create();
this.messageReaders = codecConfigurer.getReaders();
}
if (this.argumentResolverConfigurer == null) {
this.argumentResolverConfigurer = new ArgumentResolverConfigurer();
}
if (this.reactiveAdapterRegistry == null) {
this.reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
}
this.methodResolver = new ControllerMethodResolver(this.argumentResolverConfigurer, this.reactiveAdapterRegistry, this.applicationContext, this.messageReaders);
this.modelInitializer = new ModelInitializer(this.methodResolver, this.reactiveAdapterRegistry);
}
use of org.springframework.http.codec.ServerCodecConfigurer in project spring-framework by spring-projects.
the class WebFluxConfigurationSupport method serverCodecConfigurer.
/**
* Return the configurer for HTTP message readers and writers.
* <p>Use {@link #configureHttpMessageCodecs(ServerCodecConfigurer)} to
* configure the readers and writers.
*/
@Bean
public ServerCodecConfigurer serverCodecConfigurer() {
ServerCodecConfigurer serverCodecConfigurer = ServerCodecConfigurer.create();
configureHttpMessageCodecs(serverCodecConfigurer);
return serverCodecConfigurer;
}
Aggregations