diff --git a/fizz-bootstrap/pom.xml b/fizz-bootstrap/pom.xml index 0cb813a..c38791d 100644 --- a/fizz-bootstrap/pom.xml +++ b/fizz-bootstrap/pom.xml @@ -20,7 +20,7 @@ Dragonfruit-SR3 Dysprosium-SR22 5.3.7.RELEASE - 4.1.67.Final + 4.1.68.Final 4.4.14 2.14.1 1.7.32 diff --git a/fizz-bootstrap/src/main/java/we/FizzBootstrapApplication.java b/fizz-bootstrap/src/main/java/we/FizzBootstrapApplication.java index 08e6e68..4e5b27a 100644 --- a/fizz-bootstrap/src/main/java/we/FizzBootstrapApplication.java +++ b/fizz-bootstrap/src/main/java/we/FizzBootstrapApplication.java @@ -14,6 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + package we; import org.slf4j.Logger; diff --git a/fizz-common/src/main/java/we/config/WebClientBuilderConfig.java b/fizz-common/src/main/java/we/config/WebClientBuilderConfig.java new file mode 100644 index 0000000..516725f --- /dev/null +++ b/fizz-common/src/main/java/we/config/WebClientBuilderConfig.java @@ -0,0 +1,52 @@ +/* + * 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.springframework.beans.factory.ObjectProvider; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration; +import org.springframework.boot.autoconfigure.web.reactive.function.client.ClientHttpConnectorAutoConfiguration; +import org.springframework.boot.web.reactive.function.client.WebClientCustomizer; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.reactive.function.client.WebClient; + +/** + * @author hongqiaowei + */ + +@Configuration(proxyBeanMethods = false) +@ConditionalOnClass(WebClient.class) +@AutoConfigureAfter({CodecsAutoConfiguration.class, ClientHttpConnectorAutoConfiguration.class}) +public class WebClientBuilderConfig { + + private final WebClient.Builder webClientBuilder; + + public WebClientBuilderConfig(ObjectProvider customizerProvider) { + this.webClientBuilder = WebClient.builder(); + customizerProvider.orderedStream().forEach( + (customizer) -> { + customizer.customize(this.webClientBuilder); + } + ); + } + + public WebClient.Builder getBuilder() { + return this.webClientBuilder.clone(); + } +} diff --git a/fizz-common/src/main/java/we/config/WebClientConfig.java b/fizz-common/src/main/java/we/config/WebClientConfig.java index 9404819..4ff3e34 100644 --- a/fizz-common/src/main/java/we/config/WebClientConfig.java +++ b/fizz-common/src/main/java/we/config/WebClientConfig.java @@ -31,6 +31,7 @@ import org.springframework.web.reactive.function.client.WebClient; import reactor.netty.http.client.HttpClient; import reactor.netty.tcp.TcpClient; +import javax.annotation.Resource; import javax.net.ssl.SSLException; import java.util.concurrent.TimeUnit; @@ -125,7 +126,13 @@ public abstract class WebClientConfig { // @Resource // ReactorClientHttpConnector reactorClientHttpConnector; - public WebClient webClient(WebClient.Builder webClientBuilder) { + // @Resource + // WebClient.Builder webClientBuilder; + + @Resource + WebClientBuilderConfig webClientBuilderConfig; + + public WebClient webClient() { HttpClient httpClient = HttpClient.create() .tcpConfiguration( @@ -170,9 +177,10 @@ public abstract class WebClientConfig { } } - return webClientBuilder.exchangeStrategies( - ExchangeStrategies.builder().codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(-1)) - .build() + return webClientBuilderConfig.getBuilder() + .exchangeStrategies( + ExchangeStrategies.builder().codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(-1)) + .build() ) .clientConnector(new ReactorClientHttpConnector(httpClient)) .build(); diff --git a/fizz-common/src/main/java/we/spring/http/server/reactive/ext/FizzServerHttpRequestDecorator.java b/fizz-common/src/main/java/we/spring/http/server/reactive/ext/FizzServerHttpRequestDecorator.java index a660e76..3c46cdc 100644 --- a/fizz-common/src/main/java/we/spring/http/server/reactive/ext/FizzServerHttpRequestDecorator.java +++ b/fizz-common/src/main/java/we/spring/http/server/reactive/ext/FizzServerHttpRequestDecorator.java @@ -73,13 +73,13 @@ public class FizzServerHttpRequestDecorator extends ServerHttpRequestDecorator { return body; } - public DataBuffer getRawBody() { - final DataBuffer[] raw = {null}; - body.subscribe( - dataBuffer -> { - raw[0] = dataBuffer; - } - ); - return raw[0]; - } +// public DataBuffer getRawBody() { +// final DataBuffer[] raw = {null}; +// body.subscribe( +// dataBuffer -> { +// raw[0] = dataBuffer; +// } +// ); +// return raw[0]; +// } } diff --git a/fizz-core/src/main/java/we/filter/AggregateFilter.java b/fizz-core/src/main/java/we/filter/AggregateFilter.java index af82024..1aa5f18 100644 --- a/fizz-core/src/main/java/we/filter/AggregateFilter.java +++ b/fizz-core/src/main/java/we/filter/AggregateFilter.java @@ -82,11 +82,6 @@ public class AggregateFilter implements WebFilter { @Override public Mono filter(ServerWebExchange exchange, WebFilterChain chain) { - FilterResult pfr = WebUtils.getPrevFilterResult(exchange); - if (!pfr.success) { - return WebUtils.getDirectResponse(exchange); - } - String serviceId = WebUtils.getBackendService(exchange); if (serviceId == null) { return chain.filter(exchange); @@ -106,6 +101,11 @@ public class AggregateFilter implements WebFilter { } } + FilterResult pfr = WebUtils.getPrevFilterResult(exchange); + if (!pfr.success) { + return WebUtils.getDirectResponse(exchange); + } + long start = System.currentTimeMillis(); ServerHttpRequest request = exchange.getRequest(); ServerHttpResponse serverHttpResponse = exchange.getResponse(); diff --git a/fizz-core/src/main/java/we/filter/FilterExceptionHandlerConfig.java b/fizz-core/src/main/java/we/filter/FilterExceptionHandlerConfig.java index bdcfb82..1e37bda 100644 --- a/fizz-core/src/main/java/we/filter/FilterExceptionHandlerConfig.java +++ b/fizz-core/src/main/java/we/filter/FilterExceptionHandlerConfig.java @@ -96,7 +96,7 @@ public class FilterExceptionHandlerConfig { } } Mono vm; - Object fc = exchange.getAttributes().get(WebUtils.FILTER_CONTEXT); + Object fc = exchange.getAttribute(WebUtils.FILTER_CONTEXT); if (fc == null) { // t came from flow control filter StringBuilder b = ThreadContext.getStringBuilder(); WebUtils.request2stringBuilder(exchange, b); diff --git a/fizz-core/src/main/java/we/plugin/FizzPluginFilterChain.java b/fizz-core/src/main/java/we/plugin/FizzPluginFilterChain.java index cdea449..62ceea3 100644 --- a/fizz-core/src/main/java/we/plugin/FizzPluginFilterChain.java +++ b/fizz-core/src/main/java/we/plugin/FizzPluginFilterChain.java @@ -84,4 +84,11 @@ public final class FizzPluginFilterChain { return chain.filter(exchange); } } + + public static Mono next(ServerWebExchange exchange, List pcs) { + Iterator it = pcs.iterator(); + Map attris = exchange.getAttributes(); + attris.put(pluginConfigsIt, it); + return next(exchange); + } } diff --git a/pom.xml b/pom.xml index 609b11b..70272c4 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ Dysprosium-SR22 5.3.7.RELEASE 2.2.5.RELEASE - 4.1.67.Final + 4.1.68.Final 4.4.14 2.14.1 1.7.32