删除冗余代码
mock代码还原
This commit is contained in:
parent
6fac2783bf
commit
48d64a869a
@ -20,6 +20,4 @@ public class SACConstants {
|
|||||||
* 业务码 key
|
* 业务码 key
|
||||||
*/
|
*/
|
||||||
public static final String GATEWAY_SERVICE_CODE = "serviceCode";
|
public static final String GATEWAY_SERVICE_CODE = "serviceCode";
|
||||||
|
|
||||||
public static final String GATEWAY_BODY_CODE = "httpBody";
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.sf.vertx.handle;
|
package com.sf.vertx.handle;
|
||||||
|
|
||||||
|
import static com.sf.vertx.constans.SACConstants.CACHE_KEY_CONNECTOR;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -34,6 +36,7 @@ import com.sf.vertx.pojo.ClusterEventMsg;
|
|||||||
import com.sf.vertx.pojo.SacCircuitBreaker;
|
import com.sf.vertx.pojo.SacCircuitBreaker;
|
||||||
import com.sf.vertx.pojo.SacCurrentLimiting;
|
import com.sf.vertx.pojo.SacCurrentLimiting;
|
||||||
import com.sf.vertx.security.MainSecurity;
|
import com.sf.vertx.security.MainSecurity;
|
||||||
|
import com.sf.vertx.utils.AppUtils;
|
||||||
import com.sf.vertx.utils.ProxyTool;
|
import com.sf.vertx.utils.ProxyTool;
|
||||||
|
|
||||||
import cn.hutool.core.collection.ConcurrentHashSet;
|
import cn.hutool.core.collection.ConcurrentHashSet;
|
||||||
@ -45,6 +48,7 @@ import io.vertx.core.Future;
|
|||||||
import io.vertx.core.Vertx;
|
import io.vertx.core.Vertx;
|
||||||
import io.vertx.core.VertxOptions;
|
import io.vertx.core.VertxOptions;
|
||||||
import io.vertx.core.http.HttpClient;
|
import io.vertx.core.http.HttpClient;
|
||||||
|
import io.vertx.core.http.HttpMethod;
|
||||||
import io.vertx.core.http.HttpServer;
|
import io.vertx.core.http.HttpServer;
|
||||||
import io.vertx.core.http.HttpServerOptions;
|
import io.vertx.core.http.HttpServerOptions;
|
||||||
import io.vertx.core.net.JksOptions;
|
import io.vertx.core.net.JksOptions;
|
||||||
@ -276,7 +280,7 @@ public class AppConfigHandler {
|
|||||||
String keyCircuitBreaker = key + ":" + "CIRCUIT_BREAKER";
|
String keyCircuitBreaker = key + ":" + "CIRCUIT_BREAKER";
|
||||||
SacCircuitBreaker sacCircuitBreaker = APICODE_CONFIG_CIRCUIT_BREAKER_MAP.get(key);
|
SacCircuitBreaker sacCircuitBreaker = APICODE_CONFIG_CIRCUIT_BREAKER_MAP.get(key);
|
||||||
if (sacCircuitBreaker != null) {
|
if (sacCircuitBreaker != null) {
|
||||||
if(sacCircuitBreaker.getCircuitBreaker() != null) {
|
if (sacCircuitBreaker.getCircuitBreaker() != null) {
|
||||||
sacCircuitBreaker.getCircuitBreaker().close();
|
sacCircuitBreaker.getCircuitBreaker().close();
|
||||||
}
|
}
|
||||||
APICODE_CONFIG_CIRCUIT_BREAKER_MAP.remove(keyCircuitBreaker);
|
APICODE_CONFIG_CIRCUIT_BREAKER_MAP.remove(keyCircuitBreaker);
|
||||||
@ -551,6 +555,16 @@ public class AppConfigHandler {
|
|||||||
// // 会跳转到 RestfulFailureHandlerImpl
|
// // 会跳转到 RestfulFailureHandlerImpl
|
||||||
// throw new HttpException(10003);
|
// throw new HttpException(10003);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// apiconfig uri rewrite
|
||||||
|
String appCode = context.request().headers().get(getAppCodeHeaderKey());
|
||||||
|
String apiCode = context.request().headers().get(getApiCodeHeaderKey());
|
||||||
|
String key = appCode + CACHE_KEY_CONNECTOR + apiCode;
|
||||||
|
if (isServiceTypeSac(key)) {
|
||||||
|
String uri = APICODE_CONFIG_MAP.get(key).getUri();
|
||||||
|
String method = APICODE_CONFIG_MAP.get(key).getMethod();
|
||||||
|
context.request().setURI(uri).setMethod(HttpMethod.valueOf(method));
|
||||||
|
}
|
||||||
return context.sendRequest();
|
return context.sendRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -604,7 +618,7 @@ public class AppConfigHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// blockedThreadCheckInterval = 1000000L;
|
blockedThreadCheckInterval = 1000000L;
|
||||||
if (blockedThreadCheckInterval != -1) {
|
if (blockedThreadCheckInterval != -1) {
|
||||||
vertxOptions.setBlockedThreadCheckInterval(blockedThreadCheckInterval); // 不打印Thread blocked 阻塞日志
|
vertxOptions.setBlockedThreadCheckInterval(blockedThreadCheckInterval); // 不打印Thread blocked 阻塞日志
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
package com.sf.vertx.handle;
|
package com.sf.vertx.handle;
|
||||||
|
|
||||||
import static com.sf.vertx.constans.SACConstants.GATEWAY_BODY_CODE;
|
|
||||||
|
|
||||||
import com.sf.vertx.api.pojo.AppConfig;
|
|
||||||
import com.sf.vertx.enums.GatewayError;
|
import com.sf.vertx.enums.GatewayError;
|
||||||
import com.sf.vertx.exception.ServiceException;
|
import com.sf.vertx.exception.ServiceException;
|
||||||
import com.sf.vertx.utils.AppUtils;
|
|
||||||
|
|
||||||
import io.vertx.ext.web.RoutingContext;
|
import io.vertx.ext.web.RoutingContext;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -16,13 +12,7 @@ public class BodyPostAnalysisHandlerImpl implements BodyPostAnalysisHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
try {
|
try {
|
||||||
// body加解密
|
|
||||||
AppConfig appConfig = AppUtils.getAppConfigFromRoutingContext(ctx);
|
|
||||||
if (AppUtils.isEnableDataSecurity(appConfig)) {
|
|
||||||
// 解密
|
|
||||||
String bodyStr = AppConfigHandler.bodyDecrypt(ctx.body().asString(), appConfig.getAppCode());
|
|
||||||
ctx.put(GATEWAY_BODY_CODE, bodyStr);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("BodyPostAnalysisHandlerImpl:",e);
|
log.error("BodyPostAnalysisHandlerImpl:",e);
|
||||||
ctx.fail(new ServiceException(GatewayError.DEFAULT_SERVICE_ERROR));
|
ctx.fail(new ServiceException(GatewayError.DEFAULT_SERVICE_ERROR));
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.sf.vertx.handle;
|
package com.sf.vertx.handle;
|
||||||
|
|
||||||
|
|
||||||
import com.sf.vertx.api.pojo.ApiConfig;
|
|
||||||
import com.sf.vertx.api.pojo.MockResponse;
|
import com.sf.vertx.api.pojo.MockResponse;
|
||||||
import com.sf.vertx.enums.GatewayError;
|
import com.sf.vertx.enums.GatewayError;
|
||||||
import com.sf.vertx.exception.MockException;
|
import com.sf.vertx.exception.MockException;
|
||||||
import com.sf.vertx.exception.ServiceException;
|
import com.sf.vertx.exception.ServiceException;
|
||||||
import com.sf.vertx.utils.AppUtils;
|
import com.sf.vertx.utils.AppUtils;
|
||||||
|
|
||||||
import io.vertx.ext.web.RoutingContext;
|
import io.vertx.ext.web.RoutingContext;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@ -16,9 +16,8 @@ public class BodyPostCheckHandlerImpl implements BodyPostCheckHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
try {
|
try {
|
||||||
ApiConfig apiConfig = AppUtils.getApiConfigFromRoutingContext(ctx);
|
|
||||||
// mock
|
// mock
|
||||||
MockResponse mockResponse = AppUtils.mock(ctx, apiConfig);
|
MockResponse mockResponse = AppUtils.mock(ctx);
|
||||||
if (mockResponse != null) {
|
if (mockResponse != null) {
|
||||||
ctx.fail(new MockException(mockResponse.getHttpStatus(), mockResponse.getMockResponse()));
|
ctx.fail(new MockException(mockResponse.getHttpStatus(), mockResponse.getMockResponse()));
|
||||||
return;
|
return;
|
||||||
|
@ -131,10 +131,7 @@ public class RSAUtil {
|
|||||||
log.info("publicKey = " + publicKey);
|
log.info("publicKey = " + publicKey);
|
||||||
log.info("privateKey = " + privateKey);
|
log.info("privateKey = " + privateKey);
|
||||||
String originValue = "{\n"
|
String originValue = "{\n"
|
||||||
+ " \"data\": {\n"
|
+ " \"data\": 1,\n"
|
||||||
+ " \"a\": 1,\n"
|
|
||||||
+ " \"b\": \"dd\"\n"
|
|
||||||
+ " },\n"
|
|
||||||
+ " \"divideHttpUrl\": {\n"
|
+ " \"divideHttpUrl\": {\n"
|
||||||
+ " \"company\": {\n"
|
+ " \"company\": {\n"
|
||||||
+ " \"aesKey\": \"dadddsdfadfadsfa33323223\"\n"
|
+ " \"aesKey\": \"dadddsdfadfadsfa33323223\"\n"
|
||||||
@ -146,7 +143,7 @@ public class RSAUtil {
|
|||||||
|
|
||||||
String encrypt = encrypt(originValue, publicKey);
|
String encrypt = encrypt(originValue, publicKey);
|
||||||
log.info("加密后:" + encrypt);
|
log.info("加密后:" + encrypt);
|
||||||
encrypt = "Rk3UOW4UG+a/MmnddEvv03mdcv5B2+Rhu7A7mRuu9MgBTBTYrX8RVRgLwXkQq5Wuo8O33/b9n6qGhLX/GDWQ4unuO0IR4wkYwbL5EOXkOmozxScfSyiypu1zD+hSw+B4uMO5LZql+jRJeCtEjph9RZK5EFD186qktUWP1QcKHzGGIM7Ex1YZogWdn6g2I3iyYTStJrofWfUtMQzEj2UUbaAJ/KuCKSXBAJ1oBjmfT856R9TZrHxVXLf5+jNgoUQrSit6ca/hZ8HSZ+rRLf9r+pgAsU0zYLmifRVDc+F819I3XIdi/FNNm9fwNuX7ZpXyKAGP93j8V35uQ6p1ZMw+xQ==";
|
encrypt = "Rh8k/Aj5vnmlsNhc9QxO8UoCxz9r6vrJASKbZMC61cuY4QVp8ECaNI70z7aEK3wugKYp9FPCgYXtfn/erhkWOD+np9mTZ+XU4DT6/Qa7atv92vTt9TYQLmY2TLXvPbdH5qT7LrI4dKZAlBZSV36krHi0MSkX9che90TAyy0pGqpcy1dz9nJ8XAiRsfgCy1rYQp7Tt8FwaS2q367ukmK8rTD/pHngEXXoRWlkzclFfPkwQuT43YBaRgnHAAIGgWcHGILiTXdbe1y1mUxVZavrvzPPbOZtwjTBsa2uV2YCo9K4HNTvFLA2SHhMp0YAcxy1bU7FjctBli9UW32R1d3H1A==";
|
||||||
String decrypt = decrypt(encrypt, privateKey);
|
String decrypt = decrypt(encrypt, privateKey);
|
||||||
log.info("解密后:" + decrypt);
|
log.info("解密后:" + decrypt);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package com.sf.vertx.utils;
|
package com.sf.vertx.utils;
|
||||||
|
|
||||||
import static com.sf.vertx.constans.SACConstants.CACHE_KEY_CONNECTOR;
|
|
||||||
import static com.sf.vertx.constans.SACConstants.API_CONFIG;
|
import static com.sf.vertx.constans.SACConstants.API_CONFIG;
|
||||||
import static com.sf.vertx.constans.SACConstants.API_SERVICE_TYPE;
|
import static com.sf.vertx.constans.SACConstants.API_SERVICE_TYPE;
|
||||||
import static com.sf.vertx.constans.SACConstants.APP_CONFIG;
|
import static com.sf.vertx.constans.SACConstants.APP_CONFIG;
|
||||||
import static com.sf.vertx.constans.SACConstants.GATEWAY_BODY_CODE;
|
import static com.sf.vertx.constans.SACConstants.CACHE_KEY_CONNECTOR;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -20,13 +19,12 @@ import com.sf.vertx.enums.GatewayError;
|
|||||||
import com.sf.vertx.enums.GatewayServiceType;
|
import com.sf.vertx.enums.GatewayServiceType;
|
||||||
import com.sf.vertx.enums.MatchType;
|
import com.sf.vertx.enums.MatchType;
|
||||||
import com.sf.vertx.enums.RequestMethod;
|
import com.sf.vertx.enums.RequestMethod;
|
||||||
import com.sf.vertx.exception.ServiceException;
|
|
||||||
import com.sf.vertx.handle.AppConfigHandler;
|
import com.sf.vertx.handle.AppConfigHandler;
|
||||||
import com.sf.vertx.pojo.SacCircuitBreaker;
|
import com.sf.vertx.pojo.SacCircuitBreaker;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.NumberUtil;
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import io.vertx.circuitbreaker.CircuitBreaker;
|
import io.vertx.core.http.HttpServerRequest;
|
||||||
import io.vertx.core.json.JsonObject;
|
import io.vertx.core.json.JsonObject;
|
||||||
import io.vertx.ext.web.RoutingContext;
|
import io.vertx.ext.web.RoutingContext;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
@ -41,7 +39,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class AppUtils {
|
public class AppUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将AppConfig设置到上下文中 配合getAppConfigFromRoutingContext(RoutingContext rc)使用
|
* 将AppConfig设置到上下文中 配合getAppConfigFromRoutingContext(RoutingContext rc)使用
|
||||||
*
|
*
|
||||||
@ -100,138 +98,121 @@ public class AppUtils {
|
|||||||
return appConfig != null && appConfig.getDataSecurity() != null;
|
return appConfig != null && appConfig.getDataSecurity() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MockResponse mock(RoutingContext rc, ApiConfig apiConfig) {
|
public static MockResponse mock(RoutingContext rc) {
|
||||||
String apiServiceType = rc.get(API_SERVICE_TYPE);
|
AppConfig appConfig = getAppConfigFromRoutingContext(rc);
|
||||||
if (AppUtils.isEnableMockApi(apiConfig)) {
|
ApiConfig apiConfig = getApiConfigFromRoutingContext(rc);
|
||||||
// 如果是sac服务,query和body参数都从body中取
|
String apiServiceType = rc.get(API_SERVICE_TYPE);
|
||||||
Integer httpStatus = apiConfig.getMockDefaultHttpStatus();
|
if (AppUtils.isEnableMockApi(apiConfig)) {
|
||||||
String mockResponse = apiConfig.getMockDefaultResponse();
|
// 如果是sac服务,query和body参数都从body中取
|
||||||
List<MockExpectation> mockExpectations = apiConfig.getMockExpectations();
|
Integer httpStatus = apiConfig.getMockDefaultHttpStatus();
|
||||||
if (mockExpectations != null && !mockExpectations.isEmpty()) {
|
String mockResponse = apiConfig.getMockDefaultResponse();
|
||||||
for (MockExpectation mockExpectation : mockExpectations) {
|
List<MockExpectation> mockExpectations = apiConfig.getMockExpectations();
|
||||||
// 匹配条件需要全部匹配成功
|
if (mockExpectations != null && !mockExpectations.isEmpty()) {
|
||||||
boolean matchSuccess = true;
|
String bodyStr = rc.body().asString();
|
||||||
for (MockMatchCondition matchCondition : mockExpectation.getMatchConditions()) {
|
if (AppUtils.isEnableDataSecurity(appConfig)) {
|
||||||
if (!matchSuccess) {
|
bodyStr = AppConfigHandler.bodyDecrypt(bodyStr, appConfig.getAppCode());
|
||||||
break;
|
}
|
||||||
}
|
JsonObject jsonBody = new JsonObject(bodyStr);
|
||||||
MatchType matchType = MatchType.getByCode(matchCondition.getMatchType());
|
for (MockExpectation mockExpectation : mockExpectations) {
|
||||||
if (matchType == null) {
|
// 匹配条件需要全部匹配成功
|
||||||
matchSuccess = false;
|
boolean matchSuccess = true;
|
||||||
break;
|
for (MockMatchCondition matchCondition : mockExpectation.getMatchConditions()) {
|
||||||
}
|
if (!matchSuccess) {
|
||||||
String parameterPosition = matchCondition.getParameterPosition();
|
break;
|
||||||
String parameterKey = matchCondition.getParameterKey();
|
}
|
||||||
List<String> parameterValue = matchCondition.getParameterValue();
|
MatchType matchType = MatchType.getByCode(matchCondition.getMatchType());
|
||||||
String requestParameterValue = getRequestParameterValue(rc,
|
if (matchType == null) {
|
||||||
AppUtils.isSACServiceType(apiServiceType), parameterPosition, parameterKey);
|
matchSuccess = false;
|
||||||
if (!MatchType.IS_NULL.equals(matchType) && !MatchType.NOT_NULL.equals(matchType)) {
|
break;
|
||||||
// 需要值而没有设置值,直接匹配失败
|
}
|
||||||
if (CollectionUtil.isEmpty(parameterValue) || requestParameterValue == null) {
|
String parameterPosition = matchCondition.getParameterPosition();
|
||||||
matchSuccess = false;
|
String parameterKey = matchCondition.getParameterKey();
|
||||||
break;
|
List<String> parameterValue = matchCondition.getParameterValue();
|
||||||
}
|
String requestParameterValue = getRequestParameterValue(AppUtils.isSACServiceType(apiServiceType), parameterPosition, parameterKey, rc.request(), jsonBody);
|
||||||
}
|
if (!MatchType.IS_NULL.equals(matchType) && !MatchType.NOT_NULL.equals(matchType)) {
|
||||||
|
// 需要值而没有设置值,直接匹配失败
|
||||||
|
if (CollectionUtil.isEmpty(parameterValue) || requestParameterValue == null) {
|
||||||
|
matchSuccess = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (matchType) {
|
switch (matchType) {
|
||||||
case EQ:
|
case EQ:
|
||||||
matchSuccess = parameterValue.get(0).equals(requestParameterValue);
|
matchSuccess = parameterValue.get(0).equals(requestParameterValue);
|
||||||
break;
|
break;
|
||||||
case NOT_EQ:
|
case NOT_EQ:
|
||||||
matchSuccess = !parameterValue.get(0).equals(requestParameterValue);
|
matchSuccess = !parameterValue.get(0).equals(requestParameterValue);
|
||||||
break;
|
break;
|
||||||
case GT:
|
case GT:
|
||||||
if (NumberUtil.isNumber(requestParameterValue)
|
if (NumberUtil.isNumber(requestParameterValue) && NumberUtil.isNumber(parameterValue.get(0))) {
|
||||||
&& NumberUtil.isNumber(parameterValue.get(0))) {
|
matchSuccess = new BigDecimal(requestParameterValue).compareTo(new BigDecimal(parameterValue.get(0))) > 0;
|
||||||
matchSuccess = new BigDecimal(requestParameterValue)
|
} else {
|
||||||
.compareTo(new BigDecimal(parameterValue.get(0))) > 0;
|
matchSuccess = requestParameterValue.compareTo(parameterValue.get(0)) > 0;
|
||||||
} else {
|
}
|
||||||
matchSuccess = requestParameterValue.compareTo(parameterValue.get(0)) > 0;
|
break;
|
||||||
}
|
case GE:
|
||||||
break;
|
if (NumberUtil.isNumber(requestParameterValue) && NumberUtil.isNumber(parameterValue.get(0))) {
|
||||||
case GE:
|
matchSuccess = new BigDecimal(requestParameterValue).compareTo(new BigDecimal(parameterValue.get(0))) >= 0;
|
||||||
if (NumberUtil.isNumber(requestParameterValue)
|
} else {
|
||||||
&& NumberUtil.isNumber(parameterValue.get(0))) {
|
matchSuccess = requestParameterValue.compareTo(parameterValue.get(0)) >= 0;
|
||||||
matchSuccess = new BigDecimal(requestParameterValue)
|
}
|
||||||
.compareTo(new BigDecimal(parameterValue.get(0))) >= 0;
|
break;
|
||||||
} else {
|
case LT:
|
||||||
matchSuccess = requestParameterValue.compareTo(parameterValue.get(0)) >= 0;
|
if (NumberUtil.isNumber(requestParameterValue) && NumberUtil.isNumber(parameterValue.get(0))) {
|
||||||
}
|
matchSuccess = new BigDecimal(requestParameterValue).compareTo(new BigDecimal(parameterValue.get(0))) < 0;
|
||||||
break;
|
} else {
|
||||||
case LT:
|
matchSuccess = requestParameterValue.compareTo(parameterValue.get(0)) < 0;
|
||||||
if (NumberUtil.isNumber(requestParameterValue)
|
}
|
||||||
&& NumberUtil.isNumber(parameterValue.get(0))) {
|
break;
|
||||||
matchSuccess = new BigDecimal(requestParameterValue)
|
case LE:
|
||||||
.compareTo(new BigDecimal(parameterValue.get(0))) < 0;
|
if (NumberUtil.isNumber(requestParameterValue) && NumberUtil.isNumber(parameterValue.get(0))) {
|
||||||
} else {
|
matchSuccess = new BigDecimal(requestParameterValue).compareTo(new BigDecimal(parameterValue.get(0))) <= 0;
|
||||||
matchSuccess = requestParameterValue.compareTo(parameterValue.get(0)) < 0;
|
} else {
|
||||||
}
|
matchSuccess = requestParameterValue.compareTo(parameterValue.get(0)) <= 0;
|
||||||
break;
|
}
|
||||||
case LE:
|
break;
|
||||||
if (NumberUtil.isNumber(requestParameterValue)
|
case IN:
|
||||||
&& NumberUtil.isNumber(parameterValue.get(0))) {
|
matchSuccess = parameterValue.contains(requestParameterValue);
|
||||||
matchSuccess = new BigDecimal(requestParameterValue)
|
break;
|
||||||
.compareTo(new BigDecimal(parameterValue.get(0))) <= 0;
|
case NOT_IN:
|
||||||
} else {
|
matchSuccess = !parameterValue.contains(requestParameterValue);
|
||||||
matchSuccess = requestParameterValue.compareTo(parameterValue.get(0)) <= 0;
|
break;
|
||||||
}
|
case IS_NULL:
|
||||||
break;
|
matchSuccess = requestParameterValue == null;
|
||||||
case IN:
|
break;
|
||||||
matchSuccess = parameterValue.contains(requestParameterValue);
|
case NOT_NULL:
|
||||||
break;
|
matchSuccess = requestParameterValue != null;
|
||||||
case NOT_IN:
|
break;
|
||||||
matchSuccess = !parameterValue.contains(requestParameterValue);
|
default:
|
||||||
break;
|
break;
|
||||||
case IS_NULL:
|
}
|
||||||
matchSuccess = requestParameterValue == null;
|
|
||||||
break;
|
|
||||||
case NOT_NULL:
|
|
||||||
matchSuccess = requestParameterValue != null;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (matchSuccess) {
|
if (matchSuccess) {
|
||||||
httpStatus = mockExpectation.getHttpStatus();
|
httpStatus = mockExpectation.getHttpStatus();
|
||||||
mockResponse = mockExpectation.getMockResponse();
|
mockResponse = mockExpectation.getMockResponse();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new MockResponse(httpStatus, mockResponse);
|
return new MockResponse(httpStatus, mockResponse);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
private static String getRequestParameterValue(Boolean isServiceTypeSac, String parameterPosition,
|
||||||
* BodyPostAnalysisHandler之后调用
|
String parameterKey, HttpServerRequest request, JsonObject jsonBody) {
|
||||||
* @param rc
|
|
||||||
* @param parameterKey
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static String mockBodyVal(RoutingContext rc, String parameterKey) {
|
|
||||||
String bodyStr = rc.get(GATEWAY_BODY_CODE);
|
|
||||||
if(StringUtils.isBlank(bodyStr)) {
|
|
||||||
throw new ServiceException(GatewayError.DEFAULT_SERVICE_ERROR);
|
|
||||||
}
|
|
||||||
JsonObject jsonBody = new JsonObject(bodyStr);
|
|
||||||
return jsonBody.getString(parameterKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getRequestParameterValue(RoutingContext rc, Boolean isServiceTypeSac,
|
|
||||||
String parameterPosition, String parameterKey) {
|
|
||||||
switch (parameterPosition) {
|
switch (parameterPosition) {
|
||||||
case "query":
|
case "query":
|
||||||
if (isServiceTypeSac) {
|
if (isServiceTypeSac) {
|
||||||
return mockBodyVal(rc, parameterKey);
|
return jsonBody.getString(parameterKey);
|
||||||
}
|
}
|
||||||
return rc.request().getParam(parameterKey);
|
return request.getParam(parameterKey);
|
||||||
case "header":
|
case "header":
|
||||||
return rc.request().getHeader(parameterKey);
|
return request.getHeader(parameterKey);
|
||||||
case "body":
|
case "body":
|
||||||
return mockBodyVal(rc, parameterKey);
|
return jsonBody.getString(parameterKey);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -254,36 +235,36 @@ public class AppUtils {
|
|||||||
}
|
}
|
||||||
return getResponseJsonByGatewayError(GatewayError.DEFAULT_SERVICE_ERROR);
|
return getResponseJsonByGatewayError(GatewayError.DEFAULT_SERVICE_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAnalysisBody(AppConfig appConfig, ApiConfig apiConfig,String apiServiceType, String contentType) {
|
public static boolean isAnalysisBody(AppConfig appConfig, ApiConfig apiConfig, String apiServiceType,
|
||||||
// 不是Mock(是mock模式的话,存在body就解析。)
|
String contentType) {
|
||||||
if (AppUtils.isEnableMockApi(apiConfig)) {
|
// mock模式,存在body就解析。
|
||||||
return true;
|
if (AppUtils.isEnableMockApi(apiConfig)) {
|
||||||
}
|
return true;
|
||||||
// 文件上传不走加解密
|
}
|
||||||
if (StringUtils.startsWith(contentType, "multipart")) {
|
// 文件上传不走加解密
|
||||||
return false;
|
if (StringUtils.startsWith(contentType, "multipart")) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
// uri不能模糊匹配
|
|
||||||
if (StringUtils.equals(apiConfig.getUri(), "*")) {
|
// uri不能模糊匹配
|
||||||
return false;
|
if (StringUtils.equals(apiConfig.getUri(), "*")) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
// SAC模式,实际API请求方式GET,DELETE,HEAD请求需要解析body,可能需要二次处理。(SAC模式请求方式参数统一使用body传递)
|
|
||||||
// SAC模式,如果是POST或者PUT,并且没有设置数据加密则跳过
|
// SAC模式,实际API请求方式GET,DELETE,HEAD请求需要解析body,可能需要二次处理。(SAC模式请求方式参数统一使用body传递)
|
||||||
if (AppUtils.isSACServiceType(apiServiceType)) {
|
// SAC模式,如果是POST或者PUT,并且没有设置数据加密则跳过
|
||||||
RequestMethod requestMethod = RequestMethod.getByCode(apiConfig.getMethod());
|
if (AppUtils.isSACServiceType(apiServiceType)) {
|
||||||
if (RequestMethod.GET.equals(requestMethod)
|
RequestMethod requestMethod = RequestMethod.getByCode(apiConfig.getMethod());
|
||||||
|| RequestMethod.DELETE.equals(requestMethod)
|
if (RequestMethod.GET.equals(requestMethod) || RequestMethod.DELETE.equals(requestMethod)
|
||||||
|| RequestMethod.HEAD.equals(requestMethod)) {
|
|| RequestMethod.HEAD.equals(requestMethod)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String keyCircuitBreaker = appConfig.getAppCode() + CACHE_KEY_CONNECTOR + apiConfig.getApiCode();
|
String keyCircuitBreaker = appConfig.getAppCode() + CACHE_KEY_CONNECTOR + apiConfig.getApiCode();
|
||||||
SacCircuitBreaker sacCircuitBreaker = AppConfigHandler.getApiCodeCircuitBreaker(keyCircuitBreaker);
|
SacCircuitBreaker sacCircuitBreaker = AppConfigHandler.getApiCodeCircuitBreaker(keyCircuitBreaker);
|
||||||
boolean isDataSecurity = AppUtils.isEnableDataSecurity(appConfig);
|
boolean isDataSecurity = AppUtils.isEnableDataSecurity(appConfig);
|
||||||
return (isDataSecurity || sacCircuitBreaker != null);
|
return (isDataSecurity || sacCircuitBreaker != null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user