mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-12 07:02:14 +08:00
BUG修复
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-common</artifactId>
|
<artifactId>sop-common</artifactId>
|
||||||
<version>1.10.0-SNAPSHOT</version>
|
<version>1.10.1-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@@ -5,11 +5,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-common</artifactId>
|
<artifactId>sop-common</artifactId>
|
||||||
<version>1.10.0-SNAPSHOT</version>
|
<version>1.10.1-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>sop-gateway-common</artifactId>
|
<artifactId>sop-gateway-common</artifactId>
|
||||||
<version>1.10.0-SNAPSHOT</version>
|
<version>1.10.1-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>sop-gateway-common</name>
|
<name>sop-gateway-common</name>
|
||||||
|
@@ -74,6 +74,9 @@ public class DefaultLimitConfigManager implements LimitConfigManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConfigLimitDto get(String limitKey) {
|
public ConfigLimitDto get(String limitKey) {
|
||||||
|
if (StringUtils.isBlank(limitKey)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return limitCache.get(limitKey);
|
return limitCache.get(limitKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,7 +11,7 @@ public interface RouteRepository<T extends TargetRoute> {
|
|||||||
/**
|
/**
|
||||||
* 获取路由信息
|
* 获取路由信息
|
||||||
* @param id 路由id
|
* @param id 路由id
|
||||||
* @return 返回路由信息
|
* @return 返回路由信息,找不到返回null
|
||||||
*/
|
*/
|
||||||
T get(String id);
|
T get(String id);
|
||||||
|
|
||||||
|
@@ -29,6 +29,15 @@ public class ApiParam extends JSONObject implements Param {
|
|||||||
|
|
||||||
private transient ApiUploadContext apiUploadContext;
|
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) {
|
public static ApiParam build(Map<String, ?> map) {
|
||||||
ApiParam apiParam = new ApiParam();
|
ApiParam apiParam = new ApiParam();
|
||||||
for (Map.Entry<String, ?> entry : map.entrySet()) {
|
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) {
|
public static String buildNameVersion(String name, String version) {
|
||||||
|
if (name == null && version == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (StringUtils.isEmpty(version)) {
|
if (StringUtils.isEmpty(version)) {
|
||||||
return name;
|
return name;
|
||||||
} else {
|
} else {
|
||||||
|
@@ -7,8 +7,10 @@ import com.gitee.sop.gatewaycommon.manager.RouteRepositoryContext;
|
|||||||
import com.gitee.sop.gatewaycommon.message.ErrorEnum;
|
import com.gitee.sop.gatewaycommon.message.ErrorEnum;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tanghc
|
* @author tanghc
|
||||||
@@ -34,7 +36,8 @@ public abstract class BaseParamBuilder<T> implements ParamBuilder<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void initOtherProperty(ApiParam apiParam) {
|
protected void initOtherProperty(ApiParam apiParam) {
|
||||||
if (apiParam.size() == 0) {
|
String nameVersion = apiParam.fetchNameVersion();
|
||||||
|
if (StringUtils.isBlank(nameVersion)) {
|
||||||
throw ErrorEnum.ISV_INVALID_METHOD.getErrorMeta().getException();
|
throw ErrorEnum.ISV_INVALID_METHOD.getErrorMeta().getException();
|
||||||
}
|
}
|
||||||
RouteRepository<? extends TargetRoute> routeRepository = RouteRepositoryContext.getRouteRepository();
|
RouteRepository<? extends TargetRoute> routeRepository = RouteRepositoryContext.getRouteRepository();
|
||||||
@@ -42,8 +45,10 @@ public abstract class BaseParamBuilder<T> implements ParamBuilder<T> {
|
|||||||
log.error("RouteRepositoryContext.setRouteRepository()方法未使用");
|
log.error("RouteRepositoryContext.setRouteRepository()方法未使用");
|
||||||
throw ErrorEnum.AOP_UNKNOW_ERROR.getErrorMeta().getException();
|
throw ErrorEnum.AOP_UNKNOW_ERROR.getErrorMeta().getException();
|
||||||
}
|
}
|
||||||
TargetRoute targetRoute = routeRepository.get(apiParam.fetchNameVersion());
|
TargetRoute targetRoute = routeRepository.get(nameVersion);
|
||||||
BaseRouteDefinition routeDefinition = targetRoute.getRouteDefinition();
|
BaseRouteDefinition routeDefinition = Optional.ofNullable(targetRoute)
|
||||||
|
.map(t -> t.getRouteDefinition())
|
||||||
|
.orElse(null);
|
||||||
if (routeDefinition == null) {
|
if (routeDefinition == null) {
|
||||||
throw ErrorEnum.ISV_INVALID_METHOD.getErrorMeta().getException();
|
throw ErrorEnum.ISV_INVALID_METHOD.getErrorMeta().getException();
|
||||||
}
|
}
|
||||||
@@ -51,3 +56,4 @@ public abstract class BaseParamBuilder<T> implements ParamBuilder<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -39,6 +39,7 @@ public class ApiValidator implements Validator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validate(ApiParam param) {
|
public void validate(ApiParam param) {
|
||||||
|
try {
|
||||||
ApiConfig apiConfig = ApiContext.getApiConfig();
|
ApiConfig apiConfig = ApiContext.getApiConfig();
|
||||||
if (apiConfig.isIgnoreValidate() || param.fetchIgnoreValidate()) {
|
if (apiConfig.isIgnoreValidate() || param.fetchIgnoreValidate()) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
@@ -46,18 +47,15 @@ public class ApiValidator implements Validator {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (param.fetchIgnoreSign()) {
|
// 需要验证签名,先校验appKey,后校验签名,顺序不能变
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug("忽略签名验证, name:{}, version:{}", param.fetchName(), param.fetchVersion());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 需要验证签名,先校验appKey,后校验签名顺序不能变
|
|
||||||
checkAppKey(param);
|
checkAppKey(param);
|
||||||
checkSign(param);
|
checkSign(param);
|
||||||
}
|
|
||||||
checkUploadFile(param);
|
|
||||||
checkTimeout(param);
|
checkTimeout(param);
|
||||||
checkFormat(param);
|
checkFormat(param);
|
||||||
|
checkUploadFile(param);
|
||||||
|
} finally {
|
||||||
|
param.fitNameVersion();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,9 +1,7 @@
|
|||||||
package com.gitee.sop.gatewaycommon.zuul.route;
|
package com.gitee.sop.gatewaycommon.zuul.route;
|
||||||
|
|
||||||
import com.gitee.sop.gatewaycommon.manager.RouteRepository;
|
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.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -23,11 +21,7 @@ public class ZuulRouteRepository implements RouteRepository<ZuulTargetRoute> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZuulTargetRoute get(String id) {
|
public ZuulTargetRoute get(String id) {
|
||||||
ZuulTargetRoute route = nameVersionTargetRouteMap.get(id);
|
return nameVersionTargetRouteMap.get(id);
|
||||||
if (route == null) {
|
|
||||||
throw ErrorEnum.ISV_INVALID_METHOD.getErrorMeta().getException();
|
|
||||||
}
|
|
||||||
return route;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -15,6 +15,9 @@ import org.springframework.core.env.Environment;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class ZuulZookeeperRouteManager extends BaseRouteManager<ZuulServiceRouteInfo, ZuulRouteDefinition, ZuulTargetRoute> {
|
public class ZuulZookeeperRouteManager extends BaseRouteManager<ZuulServiceRouteInfo, ZuulRouteDefinition, ZuulTargetRoute> {
|
||||||
|
|
||||||
|
/** 路由重试 */
|
||||||
|
public static final boolean RETRYABLE = true;
|
||||||
|
|
||||||
public ZuulZookeeperRouteManager(Environment environment, RouteRepository<ZuulTargetRoute> routeRepository) {
|
public ZuulZookeeperRouteManager(Environment environment, RouteRepository<ZuulTargetRoute> routeRepository) {
|
||||||
super(environment, routeRepository);
|
super(environment, routeRepository);
|
||||||
}
|
}
|
||||||
@@ -31,9 +34,7 @@ public class ZuulZookeeperRouteManager extends BaseRouteManager<ZuulServiceRoute
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ZuulTargetRoute buildRouteDefinition(ZuulServiceRouteInfo serviceRouteInfo, ZuulRouteDefinition routeDefinition) {
|
protected ZuulTargetRoute buildRouteDefinition(ZuulServiceRouteInfo serviceRouteInfo, ZuulRouteDefinition routeDefinition) {
|
||||||
// 路由重试
|
Route route = new Route(routeDefinition.getId(), routeDefinition.getPath(), RouteUtil.getZuulLocation(routeDefinition.getUri()), null, RETRYABLE, null);
|
||||||
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);
|
|
||||||
return new ZuulTargetRoute(serviceRouteInfo, routeDefinition, route);
|
return new ZuulTargetRoute(serviceRouteInfo, routeDefinition, route);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,11 +6,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-common</artifactId>
|
<artifactId>sop-common</artifactId>
|
||||||
<version>1.10.0-SNAPSHOT</version>
|
<version>1.10.1-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>sop-service-common</artifactId>
|
<artifactId>sop-service-common</artifactId>
|
||||||
<version>1.10.0-SNAPSHOT</version>
|
<version>1.10.1-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>sop-service-common</name>
|
<name>sop-service-common</name>
|
||||||
|
Reference in New Issue
Block a user