From 40e81cb34692368712370805949d3aa58f55cc52 Mon Sep 17 00:00:00 2001 From: "lancer.hong" Date: Sun, 10 Oct 2021 23:41:41 +0800 Subject: [PATCH] Rename WebFluxConfig to WebServerConfig --- .../main/java/we/config/WebFluxConfig.java | 157 ------------------ .../main/java/we/config/WebServerConfig.java | 71 ++++++++ ...es.java => WebServerConfigProperties.java} | 91 +++++----- .../main/resources/META-INF/spring.factories | 2 +- 4 files changed, 119 insertions(+), 202 deletions(-) delete mode 100644 fizz-core/src/main/java/we/config/WebFluxConfig.java create mode 100644 fizz-core/src/main/java/we/config/WebServerConfig.java rename fizz-core/src/main/java/we/config/{WebFluxConfigProperties.java => WebServerConfigProperties.java} (92%) diff --git a/fizz-core/src/main/java/we/config/WebFluxConfig.java b/fizz-core/src/main/java/we/config/WebFluxConfig.java deleted file mode 100644 index df04c8c..0000000 --- a/fizz-core/src/main/java/we/config/WebFluxConfig.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2020 the original author or authors. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package we.config; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.autoconfigure.web.ServerProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.codec.ServerCodecConfigurer; -import org.springframework.http.codec.multipart.MultipartHttpMessageReader; -import org.springframework.http.codec.multipart.SynchronossPartHttpMessageReader; -import org.springframework.web.reactive.config.EnableWebFlux; -import org.springframework.web.reactive.config.ResourceHandlerRegistry; -import org.springframework.web.reactive.config.WebFluxConfigurer; - -import javax.annotation.Resource; - -/** - * @author hongqiaowei - */ - -@Configuration -@ConfigurationProperties(prefix = "server") -@EnableConfigurationProperties(ServerProperties.class) -public class WebFluxConfig { - - private static final Logger log = LoggerFactory.getLogger(WebFluxConfig.class); - - // @NacosValue(value = "${server.connection-pool.max-connections:500}", autoRefreshed = true) - // @Value( "${server.connection-pool.max-connections:500}" ) - // private int maxConnections; - // - // @NacosValue(value = "${server.connection-pool.max-idle-time:30000}", autoRefreshed = true) - // @Value( "${server.connection-pool.max-idle-time:30000}" ) - // private long maxIdleTime; - - // private ConnectionProvider connectionProvider() { - // ConnectionProvider connectionProvider = ConnectionProvider.builder("fizz-cp") - // .maxConnections(maxConnections) - // .maxIdleTime(Duration.ofMillis(maxIdleTime)) - // .pendingAcquireMaxCount(-1) - // .build(); - // log.info("server connection provider: maxConnections={}, maxIdleTime={}", maxConnections, maxIdleTime); - // return connectionProvider; - // } - - // @ConditionalOnBean(ReactorResourceFactory.class) - // @Bean(name = "$dummyObject") - // public Object dummyObject() { - // ConnectionProvider provider = connectionProvider(); - // HttpResources.set(provider); - // log.info("replace default connection provider with: " + provider); - // return new Object(); - // } - - // private LoopResources loopResources() { - // LoopResources loopResources = LoopResources.create("fizz-lrs"); - // log.info("server loop resources: " + loopResources); - // return loopResources; - // } - - // @Bean - // public ReactorResourceFactory reactorServerResourceFactory() { - // ReactorResourceFactory rrf = new ReactorResourceFactory(); - // rrf.setUseGlobalResources(false); - // rrf.setLoopResources(loopResources()); - // rrf.setConnectionProvider(connectionProvider()); - // log.info("server reactor resource factory: " + rrf); - // return rrf; - // } - - // @Bean - // public NettyReactiveWebServerFactory nettyReactiveWebServerFactory(ServerProperties serverProperties/*, ReactorResourceFactory reactorResourceFactory*/) { - // NettyReactiveWebServerFactory httpServerFactory = new NettyReactiveWebServerFactory(); - // httpServerFactory.setResourceFactory(null); - // // httpServerFactory.setResourceFactory(reactorResourceFactory); - // // LoopResources lr = LoopResources.create("fizz-el", 1, Runtime.getRuntime().availableProcessors(), true); - // httpServerFactory.addServerCustomizers( - // httpServer -> ( - // httpServer.tcpConfiguration( - // tcpServer -> { - // return ( - // tcpServer - // // .runOn(lr, true) - // // .runOn(lr) - // // .selectorOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000) - // // .port(7777) - // .bootstrap( - // serverBootstrap -> ( - // serverBootstrap - // // .group(parentGroup, childGroup) - // // .channel(NioServerSocketChannel.class) - // // .handler(new LoggingHandler(LogLevel.DEBUG)) - // // .childHandler(new ChannelInitializer() { - // // @Override - // // public void initChannel(final SocketChannel socketChannel) { - // // socketChannel.pipeline().addLast(new BufferingInboundHandler()); - // // } - // // }) - // // .channel(NioServerSocketChannel.class) - // // .option(ChannelOption.ALLOCATOR, UnpooledByteBufAllocator.DEFAULT) - // // .option(ChannelOption.SO_BACKLOG, 8192) - // // .childOption(ChannelOption.ALLOCATOR, UnpooledByteBufAllocator.DEFAULT) - // .childOption(ChannelOption.SO_KEEPALIVE, true) - // .childOption(ChannelOption.TCP_NODELAY, true) - // ) - // ) - // ); - // } - // ) - // ) - // ); - // - // return httpServerFactory; - // } - - @Configuration - @EnableWebFlux - public static class FizzWebFluxConfigurer implements WebFluxConfigurer { - - @Resource - private WebFluxConfigProperties webFluxConfigProperties; - - @Override - public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) { - configurer.defaultCodecs().maxInMemorySize(-1); - SynchronossPartHttpMessageReader partReader = new SynchronossPartHttpMessageReader(); - partReader.setMaxParts(webFluxConfigProperties.getMaxParts()); - partReader.setMaxDiskUsagePerPart(webFluxConfigProperties.getMaxDiskUsagePerPart()); - MultipartHttpMessageReader multipartReader = new MultipartHttpMessageReader(partReader); - configurer.defaultCodecs().multipartReader(multipartReader); - } - - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/*.*") - .addResourceLocations("classpath:/static/"); - } - } -} diff --git a/fizz-core/src/main/java/we/config/WebServerConfig.java b/fizz-core/src/main/java/we/config/WebServerConfig.java new file mode 100644 index 0000000..7cb9750 --- /dev/null +++ b/fizz-core/src/main/java/we/config/WebServerConfig.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2020 the original author or authors. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package we.config; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.codec.ServerCodecConfigurer; +import org.springframework.http.codec.multipart.MultipartHttpMessageReader; +import org.springframework.http.codec.multipart.SynchronossPartHttpMessageReader; +import org.springframework.web.reactive.config.EnableWebFlux; +import org.springframework.web.reactive.config.ResourceHandlerRegistry; +import org.springframework.web.reactive.config.WebFluxConfigurer; + +import javax.annotation.Resource; + +/** + * @author hongqiaowei + */ + +@Configuration +@ConfigurationProperties(prefix = "server") +@EnableConfigurationProperties(ServerProperties.class) +public class WebServerConfig { + + private static final Logger log = LoggerFactory.getLogger(WebServerConfig.class); + + @Configuration + @EnableWebFlux + public static class FizzWebFluxConfigurer implements WebFluxConfigurer { + + @Resource + private WebServerConfigProperties webServerConfigProperties; + + @Override + public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) { + ServerCodecConfigurer.ServerDefaultCodecs serverDefaultCodecs = configurer.defaultCodecs(); + serverDefaultCodecs.maxInMemorySize(-1); + + SynchronossPartHttpMessageReader partReader = new SynchronossPartHttpMessageReader(); + partReader.setMaxParts(webServerConfigProperties.getMaxParts()); + partReader.setMaxDiskUsagePerPart(webServerConfigProperties.getMaxDiskUsagePerPart()); + MultipartHttpMessageReader multipartReader = new MultipartHttpMessageReader(partReader); + serverDefaultCodecs.multipartReader(multipartReader); + } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/*.*") + .addResourceLocations("classpath:/static/"); + } + } +} diff --git a/fizz-core/src/main/java/we/config/WebFluxConfigProperties.java b/fizz-core/src/main/java/we/config/WebServerConfigProperties.java similarity index 92% rename from fizz-core/src/main/java/we/config/WebFluxConfigProperties.java rename to fizz-core/src/main/java/we/config/WebServerConfigProperties.java index f8b81b8..3286434 100644 --- a/fizz-core/src/main/java/we/config/WebFluxConfigProperties.java +++ b/fizz-core/src/main/java/we/config/WebServerConfigProperties.java @@ -1,44 +1,47 @@ -/* - * Copyright (C) 2020 the original author or authors. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package we.config; - -import lombok.Data; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.cloud.context.config.annotation.RefreshScope; -import org.springframework.stereotype.Component; - -/** - * {@link WebFluxConfig} properties - * - * @author zhongjie - */ -@RefreshScope -@Component -@Data -public class WebFluxConfigProperties { - /** - * Configure the maximum amount of disk space allowed for file parts. Default 100M (104857600) - */ - @Value( "${server.fileUpload.maxDiskUsagePerPart:104857600}" ) - private long maxDiskUsagePerPart; - - /** - * Maximum parts of multipart form-data, including form field parts; Default -1 no limit - */ - @Value( "${server.fileUpload.maxParts:-1}" ) - private int maxParts; -} +/* + * Copyright (C) 2020 the original author or authors. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package we.config; + +import lombok.Data; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.stereotype.Component; + +/** + * {@link WebServerConfig} properties + * + * @author zhongjie + */ + +@RefreshScope +@Component +@Data +public class WebServerConfigProperties { + + /** + * Configure the maximum amount of disk space allowed for file parts. Default 100M (104857600) + */ + @Value( "${server.fileUpload.maxDiskUsagePerPart:104857600}" ) + private long maxDiskUsagePerPart; + + /** + * Maximum parts of multipart form-data, including form field parts; Default -1 no limit + */ + @Value( "${server.fileUpload.maxParts:-1}" ) + private int maxParts; +} diff --git a/fizz-spring-boot-starter/src/main/resources/META-INF/spring.factories b/fizz-spring-boot-starter/src/main/resources/META-INF/spring.factories index ebaad25..cf6374b 100644 --- a/fizz-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/fizz-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -7,7 +7,7 @@ we.config.FlowStatSchedConfig,\ we.config.ProxyWebClientConfig,\ we.config.RefreshLocalCacheConfig,\ we.config.SystemConfig,\ -we.config.WebFluxConfig,\ +we.config.WebServerConfig,\ we.controller.HealthCheckController,\ we.controller.CacheCheckController,\ we.controller.CallbackController,\