Merge branch 'master' into registry-nacos

pull/1/head
tanghc 5 years ago
commit f244575976
  1. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java
  2. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ConfigLimitDto.java
  3. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/RouteConfig.java
  4. 5
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/configuration/BaseGatewayConfiguration.java
  5. 10
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultRouteConfigManager.java
  6. 4
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorMeta.java

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

@ -94,7 +94,7 @@ public class ConfigLimitDto {
*/ */
public RateLimiter fetchRateLimiter() { public RateLimiter fetchRateLimiter() {
if (rateLimiter == null) { if (rateLimiter == null) {
synchronized (this.id) { synchronized (this) {
if (rateLimiter == null) { if (rateLimiter == null) {
rateLimiter = RateLimiter.create(tokenBucketCount); rateLimiter = RateLimiter.create(tokenBucketCount);
} }

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

@ -1,5 +1,6 @@
package com.gitee.sop.gatewaycommon.gateway.configuration; 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.GatewayModifyResponseGatewayFilter;
import com.gitee.sop.gatewaycommon.gateway.filter.LoadBalancerClientExtFilter; import com.gitee.sop.gatewaycommon.gateway.filter.LoadBalancerClientExtFilter;
import com.gitee.sop.gatewaycommon.gateway.filter.ValidateFilter; import com.gitee.sop.gatewaycommon.gateway.filter.ValidateFilter;
@ -30,10 +31,8 @@ import java.util.List;
*/ */
public class BaseGatewayConfiguration extends AbstractConfiguration { public class BaseGatewayConfiguration extends AbstractConfiguration {
public static boolean USE_GATEWAY;
public BaseGatewayConfiguration() { public BaseGatewayConfiguration() {
USE_GATEWAY = true; ApiConfig.getInstance().setUseGateway(true);
} }
/** /**

@ -1,6 +1,7 @@
package com.gitee.sop.gatewaycommon.manager; package com.gitee.sop.gatewaycommon.manager;
import com.gitee.sop.gatewaycommon.bean.RouteConfig; import com.gitee.sop.gatewaycommon.bean.RouteConfig;
import com.gitee.sop.gatewaycommon.bean.RouteStatus;
import com.gitee.sop.gatewaycommon.util.MyBeanUtil; import com.gitee.sop.gatewaycommon.util.MyBeanUtil;
import java.util.Map; import java.util.Map;
@ -15,10 +16,11 @@ public class DefaultRouteConfigManager implements RouteConfigManager {
*/ */
protected static Map<String, RouteConfig> routeConfigMap = new ConcurrentHashMap<>(64); protected static Map<String, RouteConfig> routeConfigMap = new ConcurrentHashMap<>(64);
private static RouteConfig DEFAULT_CONFIG; private static final RouteConfig DEFAULT_ROUTE_CONFIG;
public DefaultRouteConfigManager() { static {
DEFAULT_CONFIG = this.newRouteConfig(); DEFAULT_ROUTE_CONFIG = new RouteConfig();
DEFAULT_ROUTE_CONFIG.setStatus(RouteStatus.ENABLE.getStatus());
} }
@Override @Override
@ -47,6 +49,6 @@ public class DefaultRouteConfigManager implements RouteConfigManager {
@Override @Override
public RouteConfig get(String routeId) { public RouteConfig get(String routeId) {
return routeConfigMap.getOrDefault(routeId, DEFAULT_CONFIG); return routeConfigMap.getOrDefault(routeId, DEFAULT_ROUTE_CONFIG);
} }
} }

@ -1,7 +1,7 @@
package com.gitee.sop.gatewaycommon.message; 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.exception.ApiException;
import com.gitee.sop.gatewaycommon.gateway.configuration.BaseGatewayConfiguration;
import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.context.RequestContext;
import lombok.Getter; import lombok.Getter;
@ -55,7 +55,7 @@ public class ErrorMeta {
} }
protected Locale getLocale() { protected Locale getLocale() {
if (BaseGatewayConfiguration.USE_GATEWAY) { if (ApiConfig.getInstance().isUseGateway()) {
return ZH_CN; return ZH_CN;
} }
RequestContext currentContext = RequestContext.getCurrentContext(); RequestContext currentContext = RequestContext.getCurrentContext();

Loading…
Cancel
Save