Merge pull request #345 from wehotel/develop

This commit is contained in:
hongqiaowei
2021-10-15 12:37:26 +08:00
committed by GitHub
7 changed files with 57 additions and 16 deletions

View File

@@ -177,7 +177,7 @@ public abstract class WebClientConfig {
if (trustInsecureSSL != null && trustInsecureSSL) { if (trustInsecureSSL != null && trustInsecureSSL) {
try { try {
SslContext sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build(); SslContext sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
httpClient = httpClient.secure(t -> t.sslContext(sslContext)); httpClient = httpClient.secure(spec -> spec.sslContext(sslContext));
log.warn("disable SSL verification"); log.warn("disable SSL verification");
} catch (SSLException e) { } catch (SSLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);

View File

@@ -29,6 +29,7 @@ import we.fizz.StepContext;
import we.fizz.exception.FizzRuntimeException; import we.fizz.exception.FizzRuntimeException;
import we.fizz.function.FuncExecutor; import we.fizz.function.FuncExecutor;
import we.fizz.function.IFunc; import we.fizz.function.IFunc;
import we.global_resource.GlobalResourceService;
import we.util.MapUtil; import we.util.MapUtil;
/** /**
@@ -37,6 +38,8 @@ import we.util.MapUtil;
* *
*/ */
public class PathMapping { public class PathMapping {
private static final String GLOBAL_RESOURCE_PREFIX = "g.";
private static List<String> typeList = Arrays.asList("Integer", "int", "Boolean", "boolean", "Float", "float", private static List<String> typeList = Arrays.asList("Integer", "int", "Boolean", "boolean", "Float", "float",
"Double", "double", "String", "string", "Long", "long", "Number", "number"); "Double", "double", "String", "string", "Long", "long", "Number", "number");
@@ -195,6 +198,9 @@ public class PathMapping {
} }
private static Object getRefValue(ONode ctxNode, String type, String path) { private static Object getRefValue(ONode ctxNode, String type, String path) {
if (StringUtils.isBlank(path)) {
return null;
}
Object obj = null; Object obj = null;
// check if it is a function // check if it is a function
if (path.startsWith(IFunc.NAME_SPACE_PREFIX)) { if (path.startsWith(IFunc.NAME_SPACE_PREFIX)) {
@@ -210,7 +216,12 @@ public class PathMapping {
p = path.substring(0, path.indexOf("|")); p = path.substring(0, path.indexOf("|"));
defaultValue = path.substring(path.indexOf("|") + 1); defaultValue = path.substring(path.indexOf("|") + 1);
} }
ONode val = select(ctxNode, handlePath(p)); ONode val = null;
if (path.startsWith(GLOBAL_RESOURCE_PREFIX)) {
val = select(GlobalResourceService.resNode, p);
} else {
val = select(ctxNode, handlePath(p));
}
if (val != null && !val.isNull()) { if (val != null && !val.isNull()) {
obj = val; obj = val;
} else { } else {
@@ -331,7 +342,12 @@ public class PathMapping {
p = path.substring(0, path.indexOf("|")); p = path.substring(0, path.indexOf("|"));
defaultValue = path.substring(path.indexOf("|") + 1); defaultValue = path.substring(path.indexOf("|") + 1);
} }
ONode val = select(ctxNode, handlePath(p)); ONode val = null;
if (path.startsWith(GLOBAL_RESOURCE_PREFIX)) {
val = select(GlobalResourceService.resNode, p);
} else {
val = select(ctxNode, handlePath(p));
}
if (val != null && !val.isNull()) { if (val != null && !val.isNull()) {
return val.toData(); return val.toData();
} }

View File

@@ -78,7 +78,7 @@ public class ApiConfig {
@JsonProperty( @JsonProperty(
access = JsonProperty.Access.WRITE_ONLY access = JsonProperty.Access.WRITE_ONLY
) )
public String firstGatewayGroup; public String firstGatewayGroup = GatewayGroup.DEFAULT;
public String service; public String service;

View File

@@ -32,7 +32,6 @@ import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import we.Fizz; import we.Fizz;
import we.FizzAppContext;
import we.config.AggregateRedisConfig; import we.config.AggregateRedisConfig;
import we.config.SystemConfig; import we.config.SystemConfig;
import we.flume.clients.log4j2appender.LogService; import we.flume.clients.log4j2appender.LogService;
@@ -55,7 +54,7 @@ public class ApiConfigService {
private static final Logger log = LoggerFactory.getLogger(ApiConfigService.class); private static final Logger log = LoggerFactory.getLogger(ApiConfigService.class);
private static final String macs = "macsT"; // private static final String macs = "macsT";
public Map<String, ServiceConfig> serviceConfigMap = new HashMap<>(128); public Map<String, ServiceConfig> serviceConfigMap = new HashMap<>(128);
@@ -346,11 +345,27 @@ public class ApiConfigService {
} }
} }
public Result<ApiConfig> getApiConfig(String app, String service, HttpMethod method, String path) { public ApiConfig getApiConfig(String app, String service, HttpMethod method, String path) {
return getApiConfig(null, app, service, method, path); Result<ApiConfig> result = get(null, app, service, method, path);
if (result.code == Result.SUCC) {
return result.data;
}
return null;
} }
public Result<ApiConfig> getApiConfig(Set<String> gatewayGroups, String app, String service, HttpMethod method, String path) { public Result<ApiConfig> get(String app, String service, HttpMethod method, String path) {
return get(null, app, service, method, path);
}
public ApiConfig getApiConfig(Set<String> gatewayGroups, String app, String service, HttpMethod method, String path) {
Result<ApiConfig> result = get(null, app, service, method, path);
if (result.code == Result.SUCC) {
return result.data;
}
return null;
}
public Result<ApiConfig> get(Set<String> gatewayGroups, String app, String service, HttpMethod method, String path) {
ServiceConfig sc = serviceConfigMap.get(service); ServiceConfig sc = serviceConfigMap.get(service);
if (sc == null) { if (sc == null) {
return Result.fail("no " + service + " config"); return Result.fail("no " + service + " config");
@@ -364,7 +379,8 @@ public class ApiConfigService {
b.append(service).append(" don't have api config matching ").append(gatewayGroups).append(" group ").append(method).append(" method ").append(path).append(" path"); b.append(service).append(" don't have api config matching ").append(gatewayGroups).append(" group ").append(method).append(" method ").append(path).append(" path");
return Result.fail(b.toString()); return Result.fail(b.toString());
} }
List<ApiConfig> appCanAccess = ThreadContext.getArrayList(macs); // List<ApiConfig> appCanAccess = ThreadContext.getArrayList(macs);
List<ApiConfig> appCanAccess = ThreadContext.getArrayList();
for (int i = 0; i < apiConfigs.size(); i++) { for (int i = 0; i < apiConfigs.size(); i++) {
ApiConfig ac = apiConfigs.get(i); ApiConfig ac = apiConfigs.get(i);
if (ac.checkApp) { if (ac.checkApp) {
@@ -419,7 +435,7 @@ public class ApiConfigService {
} }
} }
Result<ApiConfig> r = getApiConfig(app, service, method, path); Result<ApiConfig> r = get(app, service, method, path);
if (r.code == Result.FAIL) { if (r.code == Result.FAIL) {
if (apiConfigServiceProperties.isNeedAuth()) { if (apiConfigServiceProperties.isNeedAuth()) {
return Mono.just(r); return Mono.just(r);

View File

@@ -34,7 +34,7 @@ public class ServiceConfig {
private static final Logger log = LoggerFactory.getLogger(ServiceConfig.class); private static final Logger log = LoggerFactory.getLogger(ServiceConfig.class);
private static final String gmpT = "gmpT"; // private static final String gmpT = "gmpT";
private static final String gsmpT = "gsmpT"; private static final String gsmpT = "gsmpT";
@@ -122,7 +122,8 @@ public class ServiceConfig {
if (method2pathPattenMap == null) { if (method2pathPattenMap == null) {
return Collections.emptyList(); return Collections.emptyList();
} else { } else {
ArrayList<ApiConfig> result = ThreadContext.getArrayList(gmpT); // ArrayList<ApiConfig> result = ThreadContext.getArrayList(gmpT);
ArrayList<ApiConfig> result = ThreadContext.getArrayList();
Map<String, ApiConfig> pathPattern2apiConfigMap = method2pathPattenMap.get(method); Map<String, ApiConfig> pathPattern2apiConfigMap = method2pathPattenMap.get(method);
if (pathPattern2apiConfigMap != null) { if (pathPattern2apiConfigMap != null) {
checkPathPattern(pathPattern2apiConfigMap, path, result); checkPathPattern(pathPattern2apiConfigMap, path, result);

View File

@@ -36,6 +36,9 @@ import we.util.WebUtils;
import java.util.Map; import java.util.Map;
/** /**
* Your plugin P can extend this class and override the doFilter method, then you can modify the request later.
* warn: P and @Component(RequestBodyPlugin.REQUEST_BODY_PLUGIN) can't be applied at the same time.
*
* @author hongqiaowei * @author hongqiaowei
*/ */
@@ -71,10 +74,15 @@ public class RequestBodyPlugin implements FizzPluginFilter {
} }
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
String traceId = WebUtils.getTraceId(exchange); String traceId = WebUtils.getTraceId(exchange);
log.debug(traceId + " request is decorated", LogService.BIZ_ID, traceId); log.debug("{} request is decorated", traceId, LogService.BIZ_ID, traceId);
} }
return FizzPluginFilterChain.next(newExchange); // return FizzPluginFilterChain.next(newExchange);
return doFilter(newExchange, config);
} }
); );
} }
public Mono<Void> doFilter(ServerWebExchange exchange, Map<String, Object> config) {
return FizzPluginFilterChain.next(exchange);
}
} }

View File

@@ -208,7 +208,7 @@ public class CallbackService {
HashSet<String> gatewayGroups = new HashSet<>(); HashSet<String> gatewayGroups = new HashSet<>();
gatewayGroups.add(req.gatewayGroup); gatewayGroups.add(req.gatewayGroup);
Result<ApiConfig> result = apiConfigService.getApiConfig(gatewayGroups, req.app, req.service, req.method, req.path); Result<ApiConfig> result = apiConfigService.get(gatewayGroups, req.app, req.service, req.method, req.path);
ApiConfig ac = result.data; ApiConfig ac = result.data;
if (ac == null) { if (ac == null) {
return Mono.just(ReactiveResult.fail("no api config for " + req.path)); return Mono.just(ReactiveResult.fail("no api config for " + req.path));