This is an automated email from the ASF dual-hosted git repository.

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new adce9a8a3 fix sign plugin DataBufferLimitException error (#4016)
adce9a8a3 is described below

commit adce9a8a34dc703ff3f189027d13ea14e89f2418
Author: ableYang <[email protected]>
AuthorDate: Fri Sep 30 12:07:53 2022 +0800

    fix sign plugin DataBufferLimitException error (#4016)
    
    Co-authored-by: minzi.yang <[email protected]>
---
 .../main/java/org/apache/shenyu/plugin/sign/SignPlugin.java    | 10 +++++-----
 .../java/org/apache/shenyu/plugin/sign/SignPluginTest.java     |  3 ++-
 .../starter/plugin/sign/SignPluginConfiguration.java           |  8 +++++---
 .../starter/plugin/sign/SignPluginConfigurationTest.java       |  2 ++
 4 files changed, 14 insertions(+), 9 deletions(-)

diff --git 
a/shenyu-plugin/shenyu-plugin-sign/src/main/java/org/apache/shenyu/plugin/sign/SignPlugin.java
 
b/shenyu-plugin/shenyu-plugin-sign/src/main/java/org/apache/shenyu/plugin/sign/SignPlugin.java
index 46e65c059..ffdf756e9 100644
--- 
a/shenyu-plugin/shenyu-plugin-sign/src/main/java/org/apache/shenyu/plugin/sign/SignPlugin.java
+++ 
b/shenyu-plugin/shenyu-plugin-sign/src/main/java/org/apache/shenyu/plugin/sign/SignPlugin.java
@@ -44,7 +44,6 @@ import org.springframework.util.MultiValueMap;
 import org.springframework.util.ObjectUtils;
 import org.springframework.web.reactive.function.BodyInserter;
 import org.springframework.web.reactive.function.BodyInserters;
-import org.springframework.web.reactive.function.server.HandlerStrategies;
 import org.springframework.web.reactive.function.server.ServerRequest;
 import org.springframework.web.server.ServerWebExchange;
 import reactor.core.publisher.Mono;
@@ -58,17 +57,18 @@ import java.util.function.Function;
  */
 public class SignPlugin extends AbstractShenyuPlugin {
 
-    private static final List<HttpMessageReader<?>> MESSAGE_READERS = 
HandlerStrategies.builder().build().messageReaders();
+    private final List<HttpMessageReader<?>> messageReaders;
 
     private final SignService signService;
 
     /**
      * Instantiates a new Sign plugin.
-     *
+     * @param readers the sign use readers
      * @param signService the sign service
      */
-    public SignPlugin(final SignService signService) {
+    public SignPlugin(final List<HttpMessageReader<?>> readers, final 
SignService signService) {
         this.signService = signService;
+        messageReaders = readers;
     }
 
     @Override
@@ -86,7 +86,7 @@ public class SignPlugin extends AbstractShenyuPlugin {
     protected Mono<Void> doExecute(final ServerWebExchange exchange, final 
ShenyuPluginChain chain, final SelectorData selectorData, final RuleData rule) {
         SignRuleHandler ruleHandler = 
SignPluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(rule));
         if (!ObjectUtils.isEmpty(ruleHandler) && 
ruleHandler.getSignRequestBody()) {
-            ServerRequest serverRequest = ServerRequest.create(exchange, 
MESSAGE_READERS);
+            ServerRequest serverRequest = ServerRequest.create(exchange, 
messageReaders);
             Mono<String> mono = serverRequest.bodyToMono(String.class)
                     .switchIfEmpty(Mono.defer(() -> Mono.just("")))
                     .flatMap(originalBody -> signBody(originalBody, exchange));
diff --git 
a/shenyu-plugin/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/SignPluginTest.java
 
b/shenyu-plugin/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/SignPluginTest.java
index 68e9700f8..a35ab8a75 100644
--- 
a/shenyu-plugin/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/SignPluginTest.java
+++ 
b/shenyu-plugin/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/SignPluginTest.java
@@ -43,6 +43,7 @@ import org.springframework.http.HttpMethod;
 import org.springframework.http.MediaType;
 import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
 import org.springframework.mock.web.server.MockServerWebExchange;
+import org.springframework.web.reactive.function.server.HandlerStrategies;
 import org.springframework.web.server.ServerWebExchange;
 import reactor.core.publisher.Mono;
 import reactor.test.StepVerifier;
@@ -83,7 +84,7 @@ public final class SignPluginTest {
         this.ruleData.setName("test-sign-plugin");
         this.signPluginDataHandler = new SignPluginDataHandler();
         signService = mock(SignService.class);
-        this.signPlugin = new SignPlugin(signService);
+        this.signPlugin = new 
SignPlugin(HandlerStrategies.builder().build().messageReaders(), signService);
 
         ConfigurableApplicationContext context = 
mock(ConfigurableApplicationContext.class);
         SpringBeanUtils.getInstance().setApplicationContext(context);
diff --git 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-sign/src/main/java/org/apache/shenyu/springboot/starter/plugin/sign/SignPluginConfiguration.java
 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-sign/src/main/java/org/apache/shenyu/springboot/starter/plugin/sign/SignPluginConfiguration.java
index e6effe7d3..5141a7ddd 100644
--- 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-sign/src/main/java/org/apache/shenyu/springboot/starter/plugin/sign/SignPluginConfiguration.java
+++ 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-sign/src/main/java/org/apache/shenyu/springboot/starter/plugin/sign/SignPluginConfiguration.java
@@ -32,6 +32,7 @@ import 
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.boot.autoconfigure.condition.SearchStrategy;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.http.codec.ServerCodecConfigurer;
 
 /**
  * The type Sign plugin configuration.
@@ -65,14 +66,15 @@ public class SignPluginConfiguration {
     /**
      * sign plugin.
      *
+     * @param configurer the spring server codec config
      * @param signService the sign service
      * @return the shenyu plugin
      */
     @Bean
-    public ShenyuPlugin signPlugin(final SignService signService) {
-        return new SignPlugin(signService);
+    public ShenyuPlugin signPlugin(final SignService signService, final 
ServerCodecConfigurer configurer) {
+        return new SignPlugin(configurer.getReaders(), signService);
     }
-    
+
     /**
      * Sign auth data subscriber.
      *
diff --git 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-sign/src/test/java/org/apache/shenyu/springboot/starter/plugin/sign/SignPluginConfigurationTest.java
 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-sign/src/test/java/org/apache/shenyu/springboot/starter/plugin/sign/SignPluginConfigurationTest.java
index d0bc70892..821196967 100644
--- 
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-sign/src/test/java/org/apache/shenyu/springboot/starter/plugin/sign/SignPluginConfigurationTest.java
+++ 
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-sign/src/test/java/org/apache/shenyu/springboot/starter/plugin/sign/SignPluginConfigurationTest.java
@@ -28,6 +28,7 @@ import 
org.springframework.boot.autoconfigure.AutoConfigurations;
 import 
org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.boot.test.context.runner.ApplicationContextRunner;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.http.codec.support.DefaultServerCodecConfigurer;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -46,6 +47,7 @@ public class SignPluginConfigurationTest {
         applicationContextRunner = new ApplicationContextRunner()
             
.withConfiguration(AutoConfigurations.of(SignPluginConfiguration.class))
             .withBean(SignPluginConfigurationTest.class)
+            .withBean(DefaultServerCodecConfigurer.class)
             .withPropertyValues("debug=true");
     }
 

Reply via email to