Search in sources :

Example 6 with CodecCustomizer

use of org.springframework.boot.web.codec.CodecCustomizer in project spring-boot by spring-projects.

the class CodecsAutoConfigurationTests method autoConfigShouldProvideALoggingRequestDetailsCustomizer.

@Test
void autoConfigShouldProvideALoggingRequestDetailsCustomizer() {
    this.contextRunner.run((context) -> {
        CodecCustomizer customizer = context.getBean(CodecCustomizer.class);
        CodecConfigurer configurer = new DefaultClientCodecConfigurer();
        customizer.customize(configurer);
        assertThat(configurer.defaultCodecs()).hasFieldOrPropertyWithValue("enableLoggingRequestDetails", false);
    });
}
Also used : DefaultClientCodecConfigurer(org.springframework.http.codec.support.DefaultClientCodecConfigurer) CodecCustomizer(org.springframework.boot.web.codec.CodecCustomizer) CodecConfigurer(org.springframework.http.codec.CodecConfigurer) DefaultClientCodecConfigurer(org.springframework.http.codec.support.DefaultClientCodecConfigurer) Test(org.junit.jupiter.api.Test)

Example 7 with CodecCustomizer

use of org.springframework.boot.web.codec.CodecCustomizer in project spring-boot by spring-projects.

the class ReactiveMultipartAutoConfiguration method defaultPartHttpMessageReaderCustomizer.

@Bean
@Order(0)
CodecCustomizer defaultPartHttpMessageReaderCustomizer(ReactiveMultipartProperties multipartProperties) {
    return (configurer) -> configurer.defaultCodecs().configureDefaultCodec((codec) -> {
        if (codec instanceof DefaultPartHttpMessageReader) {
            DefaultPartHttpMessageReader defaultPartHttpMessageReader = (DefaultPartHttpMessageReader) codec;
            PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
            map.from(multipartProperties::getMaxInMemorySize).asInt(DataSize::toBytes).to(defaultPartHttpMessageReader::setMaxInMemorySize);
            map.from(multipartProperties::getMaxHeadersSize).asInt(DataSize::toBytes).to(defaultPartHttpMessageReader::setMaxHeadersSize);
            map.from(multipartProperties::getMaxDiskUsagePerPart).asInt(DataSize::toBytes).to(defaultPartHttpMessageReader::setMaxDiskUsagePerPart);
            map.from(multipartProperties::getMaxParts).to(defaultPartHttpMessageReader::setMaxParts);
            map.from(multipartProperties::getStreaming).to(defaultPartHttpMessageReader::setStreaming);
            map.from(multipartProperties::getFileStorageDirectory).as(Paths::get).to((dir) -> configureFileStorageDirectory(defaultPartHttpMessageReader, dir));
            map.from(multipartProperties::getHeadersCharset).to(defaultPartHttpMessageReader::setHeadersCharset);
        }
    });
}
Also used : Order(org.springframework.core.annotation.Order) WebFluxConfigurer(org.springframework.web.reactive.config.WebFluxConfigurer) DefaultPartHttpMessageReader(org.springframework.http.codec.multipart.DefaultPartHttpMessageReader) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper) EnableAutoConfiguration(org.springframework.boot.autoconfigure.EnableAutoConfiguration) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) IOException(java.io.IOException) Paths(java.nio.file.Paths) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Bean(org.springframework.context.annotation.Bean) AutoConfiguration(org.springframework.boot.autoconfigure.AutoConfiguration) Path(java.nio.file.Path) ConditionalOnWebApplication(org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication) Type(org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type) CodecCustomizer(org.springframework.boot.web.codec.CodecCustomizer) DataSize(org.springframework.util.unit.DataSize) DefaultPartHttpMessageReader(org.springframework.http.codec.multipart.DefaultPartHttpMessageReader) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper) Order(org.springframework.core.annotation.Order) Bean(org.springframework.context.annotation.Bean)

Aggregations

CodecCustomizer (org.springframework.boot.web.codec.CodecCustomizer)7 Test (org.junit.jupiter.api.Test)6 CodecConfigurer (org.springframework.http.codec.CodecConfigurer)4 DefaultClientCodecConfigurer (org.springframework.http.codec.support.DefaultClientCodecConfigurer)3 DefaultPartHttpMessageReader (org.springframework.http.codec.multipart.DefaultPartHttpMessageReader)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 AutoConfiguration (org.springframework.boot.autoconfigure.AutoConfiguration)1 EnableAutoConfiguration (org.springframework.boot.autoconfigure.EnableAutoConfiguration)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 ConditionalOnWebApplication (org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication)1 Type (org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type)1 EnableConfigurationProperties (org.springframework.boot.context.properties.EnableConfigurationProperties)1 PropertyMapper (org.springframework.boot.context.properties.PropertyMapper)1 Bean (org.springframework.context.annotation.Bean)1 Order (org.springframework.core.annotation.Order)1 ServerCodecConfigurer (org.springframework.http.codec.ServerCodecConfigurer)1 DefaultServerCodecConfigurer (org.springframework.http.codec.support.DefaultServerCodecConfigurer)1