This commit is contained in:
tanghc
2019-07-29 19:59:52 +08:00
parent f828ce40e8
commit b87d0eaacb
6 changed files with 14 additions and 11 deletions

View File

@@ -181,6 +181,8 @@ public class ApiConfig {
*/
private int storeErrorCapacity = 20;
private boolean useGateway;
public void addAppSecret(Map<String, String> appSecretPair) {
for (Map.Entry<String, String> entry : appSecretPair.entrySet()) {
this.isvManager.update(new IsvDefinition(entry.getKey(), entry.getValue()));

View File

@@ -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);
}

View File

@@ -18,7 +18,7 @@ public class RouteConfig {
/**
* 状态0待审核1启用2禁用。默认启用
*/
private Byte status = STATUS_ENABLE;
private Byte status;
/**
* 是否启用

View File

@@ -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);
}
/**

View File

@@ -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<String, RouteConfig> 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);
}
}

View File

@@ -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();