From b87d0eaacb05a1e7eb8df7ccec4f62c442d797d6 Mon Sep 17 00:00:00 2001 From: tanghc Date: Mon, 29 Jul 2019 19:59:52 +0800 Subject: [PATCH] 1.13.4 --- .../com/gitee/sop/gatewaycommon/bean/ApiConfig.java | 2 ++ .../gitee/sop/gatewaycommon/bean/ConfigLimitDto.java | 2 +- .../com/gitee/sop/gatewaycommon/bean/RouteConfig.java | 2 +- .../configuration/BaseGatewayConfiguration.java | 5 ++--- .../manager/DefaultRouteConfigManager.java | 10 ++++++---- .../com/gitee/sop/gatewaycommon/message/ErrorMeta.java | 4 ++-- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java index 6ff941de..89afbc9b 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java @@ -181,6 +181,8 @@ public class ApiConfig { */ private int storeErrorCapacity = 20; + private boolean useGateway; + public void addAppSecret(Map appSecretPair) { for (Map.Entry entry : appSecretPair.entrySet()) { this.isvManager.update(new IsvDefinition(entry.getKey(), entry.getValue())); diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ConfigLimitDto.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ConfigLimitDto.java index 2b2b72be..92ed0866 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ConfigLimitDto.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ConfigLimitDto.java @@ -94,7 +94,7 @@ public class ConfigLimitDto { */ public RateLimiter fetchRateLimiter() { if (rateLimiter == null) { - synchronized (this.id) { + synchronized (this) { if (rateLimiter == null) { rateLimiter = RateLimiter.create(tokenBucketCount); } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/RouteConfig.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/RouteConfig.java index 08e99ed2..1d48f262 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/RouteConfig.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/RouteConfig.java @@ -18,7 +18,7 @@ public class RouteConfig { /** * 状态,0:待审核,1:启用,2:禁用。默认启用 */ - private Byte status = STATUS_ENABLE; + private Byte status; /** * 是否启用 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 dee3c08f..1224ae05 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 @@ -1,5 +1,6 @@ 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.LoadBalancerClientExtFilter; import com.gitee.sop.gatewaycommon.gateway.filter.ValidateFilter; @@ -30,10 +31,8 @@ import java.util.List; */ public class BaseGatewayConfiguration extends AbstractConfiguration { - public static boolean USE_GATEWAY; - public BaseGatewayConfiguration() { - USE_GATEWAY = true; + ApiConfig.getInstance().setUseGateway(true); } /** diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultRouteConfigManager.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultRouteConfigManager.java index 1989082e..0ee215cc 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultRouteConfigManager.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultRouteConfigManager.java @@ -1,6 +1,7 @@ package com.gitee.sop.gatewaycommon.manager; import com.gitee.sop.gatewaycommon.bean.RouteConfig; +import com.gitee.sop.gatewaycommon.bean.RouteStatus; import com.gitee.sop.gatewaycommon.util.MyBeanUtil; import java.util.Map; @@ -15,10 +16,11 @@ public class DefaultRouteConfigManager implements RouteConfigManager { */ protected static Map routeConfigMap = new ConcurrentHashMap<>(64); - private static RouteConfig DEFAULT_CONFIG; + private static final RouteConfig DEFAULT_ROUTE_CONFIG; - public DefaultRouteConfigManager() { - DEFAULT_CONFIG = this.newRouteConfig(); + static { + DEFAULT_ROUTE_CONFIG = new RouteConfig(); + DEFAULT_ROUTE_CONFIG.setStatus(RouteStatus.ENABLE.getStatus()); } @Override @@ -47,6 +49,6 @@ public class DefaultRouteConfigManager implements RouteConfigManager { @Override public RouteConfig get(String routeId) { - return routeConfigMap.getOrDefault(routeId, DEFAULT_CONFIG); + return routeConfigMap.getOrDefault(routeId, DEFAULT_ROUTE_CONFIG); } } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorMeta.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorMeta.java index 10a26973..b9cb1ffe 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorMeta.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorMeta.java @@ -1,7 +1,7 @@ package com.gitee.sop.gatewaycommon.message; +import com.gitee.sop.gatewaycommon.bean.ApiConfig; import com.gitee.sop.gatewaycommon.exception.ApiException; -import com.gitee.sop.gatewaycommon.gateway.configuration.BaseGatewayConfiguration; import com.netflix.zuul.context.RequestContext; import lombok.Getter; @@ -55,7 +55,7 @@ public class ErrorMeta { } protected Locale getLocale() { - if (BaseGatewayConfiguration.USE_GATEWAY) { + if (ApiConfig.getInstance().isUseGateway()) { return ZH_CN; } RequestContext currentContext = RequestContext.getCurrentContext();