From 2ced9cf894358acf373bc4861531578466d1365d Mon Sep 17 00:00:00 2001 From: tanghc Date: Mon, 2 Sep 2019 10:34:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Gateway=E9=99=90=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gateway/configuration/BaseGatewayConfiguration.java | 6 ++++++ .../sop/gatewaycommon/gateway/filter/LimitFilter.java | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/configuration/BaseGatewayConfiguration.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/configuration/BaseGatewayConfiguration.java index badbd26f..52e3d1d2 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/configuration/BaseGatewayConfiguration.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/configuration/BaseGatewayConfiguration.java @@ -2,6 +2,7 @@ package com.gitee.sop.gatewaycommon.gateway.configuration; import com.gitee.sop.gatewaycommon.bean.ApiConfig; import com.gitee.sop.gatewaycommon.gateway.filter.GatewayModifyResponseGatewayFilter; +import com.gitee.sop.gatewaycommon.gateway.filter.LimitFilter; import com.gitee.sop.gatewaycommon.gateway.filter.LoadBalancerClientExtFilter; import com.gitee.sop.gatewaycommon.gateway.filter.ParameterFormatterFilter; import com.gitee.sop.gatewaycommon.gateway.filter.ValidateFilter; @@ -90,6 +91,11 @@ public class BaseGatewayConfiguration extends AbstractConfiguration { return new ValidateFilter(); } + @Bean + LimitFilter limitFilter() { + return new LimitFilter(); + } + @Bean LoadBalancerClientExtFilter loadBalancerClientExtFilter() { return new LoadBalancerClientExtFilter(); diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/LimitFilter.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/LimitFilter.java index c24ef5d3..efb2c379 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/LimitFilter.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/LimitFilter.java @@ -17,7 +17,6 @@ import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -41,7 +40,7 @@ public class LimitFilter implements GlobalFilter, Ordered { } // 单个限流功能未开启 if (configLimitDto.getLimitStatus() == ConfigLimitDto.LIMIT_STATUS_CLOSE) { - return null; + return chain.filter(exchange); } byte limitType = configLimitDto.getLimitType().byteValue(); LimitManager limitManager = ApiConfig.getInstance().getLimitManager(); @@ -82,12 +81,15 @@ public class LimitFilter implements GlobalFilter, Ordered { List limitConfigList = new ArrayList<>(); for (String limitKey : limitKeys) { ConfigLimitDto configLimitDto = limitConfigManager.get(limitKey); + if (configLimitDto == null) { + continue; + } limitConfigList.add(configLimitDto); } if (limitConfigList.isEmpty()) { return null; } - Collections.sort(limitConfigList, Comparator.comparing(ConfigLimitDto::getOrderIndex)); + limitConfigList.sort(Comparator.comparing(ConfigLimitDto::getOrderIndex)); return limitConfigList.get(0); } }