org.zodiac.autoconfigure.web.ReactiveHttpMessageAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.web;
import java.util.Arrays;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.codec.ByteArrayDecoder;
import org.springframework.core.codec.ByteArrayEncoder;
import org.springframework.core.codec.ResourceDecoder;
import org.springframework.core.codec.ResourceEncoder;
import org.springframework.core.codec.ResourceRegionEncoder;
import org.springframework.core.codec.StringDecoder;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.http.codec.json.AbstractJackson2Decoder;
import org.springframework.http.codec.json.AbstractJackson2Encoder;
import org.springframework.util.MimeType;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer;
import org.zodiac.autoconfigure.jackson.PlatformJacksonOptionProperties;
import org.zodiac.commons.util.DateTimes;
import org.zodiac.core.web.http.codec.json.MappingApiJackson2JsonDecoder;
import org.zodiac.core.web.http.codec.json.MappingApiJackson2JsonEncoder;
import org.zodiac.core.web.reactive.ConventionalMethodArgumentResolver;
import com.fasterxml.jackson.databind.ObjectMapper;
@SpringBootConfiguration
@Order(value = Ordered.HIGHEST_PRECEDENCE)
@ConditionalOnWebApplication(type = Type.REACTIVE)
@ConditionalOnClass(value = {org.springframework.web.server.WebHandler.class, org.springframework.web.reactive.DispatcherHandler.class})
public class ReactiveHttpMessageAutoConfiguration implements WebFluxConfigurer {
private static final MimeType[] EMPTY_MIME_TYPES = {};
private final ObjectMapper objectMapper;
private final PlatformJacksonOptionProperties platformJacksonOptionProperties;
public ReactiveHttpMessageAutoConfiguration(ObjectMapper objectMapper, PlatformJacksonOptionProperties platformJacksonOptionProperties) {
this.objectMapper = objectMapper;
this.platformJacksonOptionProperties = platformJacksonOptionProperties;
}
/*使用 JACKSON 作为JSON MessageConverter 消息转换,内置断点续传,下载和字符串。*/
@Override
public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
ObjectMapper readObjectMapper = objectMapper;
/*拷贝 readObjectMapper*/
//ObjectMapper writeObjectMapper = readObjectMapper.copy();
StringDecoder stringDecoder = StringDecoder.textPlainOnly(Arrays.asList(",", "\n"), false);
//Decoder