1.x
tanghc 6 years ago
parent b21a02c4a5
commit c159d6f85c
  1. 2
      sop-common/pom.xml
  2. 4
      sop-common/sop-gateway-common/pom.xml
  3. 3
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultLimitConfigManager.java
  4. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/RouteRepository.java
  5. 12
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ApiParam.java
  6. 12
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/BaseParamBuilder.java
  7. 28
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/ApiValidator.java
  8. 8
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/route/ZuulRouteRepository.java
  9. 7
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/route/ZuulZookeeperRouteManager.java
  10. 4
      sop-common/sop-service-common/pom.xml

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.10.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>

@ -5,11 +5,11 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.10.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>sop-gateway-common</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.10.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sop-gateway-common</name>

@ -74,6 +74,9 @@ public class DefaultLimitConfigManager implements LimitConfigManager {
@Override
public ConfigLimitDto get(String limitKey) {
if (StringUtils.isBlank(limitKey)) {
return null;
}
return limitCache.get(limitKey);
}

@ -11,7 +11,7 @@ public interface RouteRepository<T extends TargetRoute> {
/**
* 获取路由信息
* @param id 路由id
* @return 返回路由信息
* @return 返回路由信息找不到返回null
*/
T get(String id);

@ -29,6 +29,15 @@ public class ApiParam extends JSONObject implements Param {
private transient ApiUploadContext apiUploadContext;
public void fitNameVersion() {
if (restName != null) {
this.put(ParamNames.API_NAME, restName);
}
if (restVersion != null) {
this.put(ParamNames.VERSION_NAME, restVersion);
}
}
public static ApiParam build(Map<String, ?> map) {
ApiParam apiParam = new ApiParam();
for (Map.Entry<String, ?> entry : map.entrySet()) {
@ -95,6 +104,9 @@ public class ApiParam extends JSONObject implements Param {
}
public static String buildNameVersion(String name, String version) {
if (name == null && version == null) {
return null;
}
if (StringUtils.isEmpty(version)) {
return name;
} else {

@ -7,8 +7,10 @@ import com.gitee.sop.gatewaycommon.manager.RouteRepositoryContext;
import com.gitee.sop.gatewaycommon.message.ErrorEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
import java.util.Optional;
/**
* @author tanghc
@ -34,7 +36,8 @@ public abstract class BaseParamBuilder<T> implements ParamBuilder<T> {
}
protected void initOtherProperty(ApiParam apiParam) {
if (apiParam.size() == 0) {
String nameVersion = apiParam.fetchNameVersion();
if (StringUtils.isBlank(nameVersion)) {
throw ErrorEnum.ISV_INVALID_METHOD.getErrorMeta().getException();
}
RouteRepository<? extends TargetRoute> routeRepository = RouteRepositoryContext.getRouteRepository();
@ -42,8 +45,10 @@ public abstract class BaseParamBuilder<T> implements ParamBuilder<T> {
log.error("RouteRepositoryContext.setRouteRepository()方法未使用");
throw ErrorEnum.AOP_UNKNOW_ERROR.getErrorMeta().getException();
}
TargetRoute targetRoute = routeRepository.get(apiParam.fetchNameVersion());
BaseRouteDefinition routeDefinition = targetRoute.getRouteDefinition();
TargetRoute targetRoute = routeRepository.get(nameVersion);
BaseRouteDefinition routeDefinition = Optional.ofNullable(targetRoute)
.map(t -> t.getRouteDefinition())
.orElse(null);
if (routeDefinition == null) {
throw ErrorEnum.ISV_INVALID_METHOD.getErrorMeta().getException();
}
@ -51,3 +56,4 @@ public abstract class BaseParamBuilder<T> implements ParamBuilder<T> {
}
}

@ -39,25 +39,23 @@ public class ApiValidator implements Validator {
@Override
public void validate(ApiParam param) {
ApiConfig apiConfig = ApiContext.getApiConfig();
if (apiConfig.isIgnoreValidate() || param.fetchIgnoreValidate()) {
if (logger.isDebugEnabled()) {
logger.debug("忽略所有验证(ignoreValidate=true), name:{}, version:{}", param.fetchName(), param.fetchVersion());
}
return;
}
if (param.fetchIgnoreSign()) {
if (logger.isDebugEnabled()) {
logger.debug("忽略签名验证, name:{}, version:{}", param.fetchName(), param.fetchVersion());
try {
ApiConfig apiConfig = ApiContext.getApiConfig();
if (apiConfig.isIgnoreValidate() || param.fetchIgnoreValidate()) {
if (logger.isDebugEnabled()) {
logger.debug("忽略所有验证(ignoreValidate=true), name:{}, version:{}", param.fetchName(), param.fetchVersion());
}
return;
}
} else {
// 需要验证签名,先校验appKey,后校验签名顺序不能变
// 需要验证签名,先校验appKey,后校验签名,顺序不能变
checkAppKey(param);
checkSign(param);
checkTimeout(param);
checkFormat(param);
checkUploadFile(param);
} finally {
param.fitNameVersion();
}
checkUploadFile(param);
checkTimeout(param);
checkFormat(param);
}

@ -1,9 +1,7 @@
package com.gitee.sop.gatewaycommon.zuul.route;
import com.gitee.sop.gatewaycommon.manager.RouteRepository;
import com.gitee.sop.gatewaycommon.message.ErrorEnum;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@ -23,11 +21,7 @@ public class ZuulRouteRepository implements RouteRepository<ZuulTargetRoute> {
@Override
public ZuulTargetRoute get(String id) {
ZuulTargetRoute route = nameVersionTargetRouteMap.get(id);
if (route == null) {
throw ErrorEnum.ISV_INVALID_METHOD.getErrorMeta().getException();
}
return route;
return nameVersionTargetRouteMap.get(id);
}
@Override

@ -15,6 +15,9 @@ import org.springframework.core.env.Environment;
@Slf4j
public class ZuulZookeeperRouteManager extends BaseRouteManager<ZuulServiceRouteInfo, ZuulRouteDefinition, ZuulTargetRoute> {
/** 路由重试 */
public static final boolean RETRYABLE = true;
public ZuulZookeeperRouteManager(Environment environment, RouteRepository<ZuulTargetRoute> routeRepository) {
super(environment, routeRepository);
}
@ -31,9 +34,7 @@ public class ZuulZookeeperRouteManager extends BaseRouteManager<ZuulServiceRoute
@Override
protected ZuulTargetRoute buildRouteDefinition(ZuulServiceRouteInfo serviceRouteInfo, ZuulRouteDefinition routeDefinition) {
// 路由重试
String retry = environment.getProperty("sop.route.retry", "true");
Route route = new Route(routeDefinition.getId(), routeDefinition.getPath(), RouteUtil.getZuulLocation(routeDefinition.getUri()), null, Boolean.valueOf(retry), null);
Route route = new Route(routeDefinition.getId(), routeDefinition.getPath(), RouteUtil.getZuulLocation(routeDefinition.getUri()), null, RETRYABLE, null);
return new ZuulTargetRoute(serviceRouteInfo, routeDefinition, route);
}
}

@ -6,11 +6,11 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.10.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>sop-service-common</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.10.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sop-service-common</name>

Loading…
Cancel
Save