diff --git a/fizz-common/src/main/java/we/config/WebClientConfig.java b/fizz-common/src/main/java/we/config/WebClientConfig.java index f5428dd..98efd99 100644 --- a/fizz-common/src/main/java/we/config/WebClientConfig.java +++ b/fizz-common/src/main/java/we/config/WebClientConfig.java @@ -177,7 +177,7 @@ public abstract class WebClientConfig { if (trustInsecureSSL != null && trustInsecureSSL) { try { 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"); } catch (SSLException e) { throw new RuntimeException(e); diff --git a/fizz-core/src/main/java/we/fizz/input/PathMapping.java b/fizz-core/src/main/java/we/fizz/input/PathMapping.java index 04fd086..06a7b11 100644 --- a/fizz-core/src/main/java/we/fizz/input/PathMapping.java +++ b/fizz-core/src/main/java/we/fizz/input/PathMapping.java @@ -29,6 +29,7 @@ import we.fizz.StepContext; import we.fizz.exception.FizzRuntimeException; import we.fizz.function.FuncExecutor; import we.fizz.function.IFunc; +import we.global_resource.GlobalResourceService; import we.util.MapUtil; /** @@ -37,6 +38,8 @@ import we.util.MapUtil; * */ public class PathMapping { + + private static final String GLOBAL_RESOURCE_PREFIX = "g."; private static List typeList = Arrays.asList("Integer", "int", "Boolean", "boolean", "Float", "float", "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) { + if (StringUtils.isBlank(path)) { + return null; + } Object obj = null; // check if it is a function if (path.startsWith(IFunc.NAME_SPACE_PREFIX)) { @@ -210,7 +216,12 @@ public class PathMapping { p = path.substring(0, path.indexOf("|")); 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()) { obj = val; } else { @@ -331,7 +342,12 @@ public class PathMapping { p = path.substring(0, path.indexOf("|")); 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()) { return val.toData(); } diff --git a/fizz-core/src/main/java/we/plugin/auth/ApiConfig.java b/fizz-core/src/main/java/we/plugin/auth/ApiConfig.java index d5c1eba..e5f7e1c 100644 --- a/fizz-core/src/main/java/we/plugin/auth/ApiConfig.java +++ b/fizz-core/src/main/java/we/plugin/auth/ApiConfig.java @@ -78,7 +78,7 @@ public class ApiConfig { @JsonProperty( access = JsonProperty.Access.WRITE_ONLY ) - public String firstGatewayGroup; + public String firstGatewayGroup = GatewayGroup.DEFAULT; public String service; diff --git a/fizz-core/src/main/java/we/plugin/auth/ApiConfigService.java b/fizz-core/src/main/java/we/plugin/auth/ApiConfigService.java index e84fc45..35f68e1 100644 --- a/fizz-core/src/main/java/we/plugin/auth/ApiConfigService.java +++ b/fizz-core/src/main/java/we/plugin/auth/ApiConfigService.java @@ -32,7 +32,6 @@ import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import we.Fizz; -import we.FizzAppContext; import we.config.AggregateRedisConfig; import we.config.SystemConfig; 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 String macs = "macsT"; +// private static final String macs = "macsT"; public Map serviceConfigMap = new HashMap<>(128); @@ -346,11 +345,27 @@ public class ApiConfigService { } } - public Result getApiConfig(String app, String service, HttpMethod method, String path) { - return getApiConfig(null, app, service, method, path); + public ApiConfig getApiConfig(String app, String service, HttpMethod method, String path) { + Result result = get(null, app, service, method, path); + if (result.code == Result.SUCC) { + return result.data; + } + return null; } - public Result getApiConfig(Set gatewayGroups, String app, String service, HttpMethod method, String path) { + public Result get(String app, String service, HttpMethod method, String path) { + return get(null, app, service, method, path); + } + + public ApiConfig getApiConfig(Set gatewayGroups, String app, String service, HttpMethod method, String path) { + Result result = get(null, app, service, method, path); + if (result.code == Result.SUCC) { + return result.data; + } + return null; + } + + public Result get(Set gatewayGroups, String app, String service, HttpMethod method, String path) { ServiceConfig sc = serviceConfigMap.get(service); if (sc == null) { 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"); return Result.fail(b.toString()); } - List appCanAccess = ThreadContext.getArrayList(macs); +// List appCanAccess = ThreadContext.getArrayList(macs); + List appCanAccess = ThreadContext.getArrayList(); for (int i = 0; i < apiConfigs.size(); i++) { ApiConfig ac = apiConfigs.get(i); if (ac.checkApp) { @@ -419,7 +435,7 @@ public class ApiConfigService { } } - Result r = getApiConfig(app, service, method, path); + Result r = get(app, service, method, path); if (r.code == Result.FAIL) { if (apiConfigServiceProperties.isNeedAuth()) { return Mono.just(r); diff --git a/fizz-core/src/main/java/we/plugin/auth/ServiceConfig.java b/fizz-core/src/main/java/we/plugin/auth/ServiceConfig.java index 0ba7d67..3d3e227 100644 --- a/fizz-core/src/main/java/we/plugin/auth/ServiceConfig.java +++ b/fizz-core/src/main/java/we/plugin/auth/ServiceConfig.java @@ -34,7 +34,7 @@ public class ServiceConfig { 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"; @@ -122,7 +122,8 @@ public class ServiceConfig { if (method2pathPattenMap == null) { return Collections.emptyList(); } else { - ArrayList result = ThreadContext.getArrayList(gmpT); +// ArrayList result = ThreadContext.getArrayList(gmpT); + ArrayList result = ThreadContext.getArrayList(); Map pathPattern2apiConfigMap = method2pathPattenMap.get(method); if (pathPattern2apiConfigMap != null) { checkPathPattern(pathPattern2apiConfigMap, path, result); diff --git a/fizz-core/src/main/java/we/plugin/requestbody/RequestBodyPlugin.java b/fizz-core/src/main/java/we/plugin/requestbody/RequestBodyPlugin.java index 8e85452..ab757f3 100644 --- a/fizz-core/src/main/java/we/plugin/requestbody/RequestBodyPlugin.java +++ b/fizz-core/src/main/java/we/plugin/requestbody/RequestBodyPlugin.java @@ -36,6 +36,9 @@ import we.util.WebUtils; 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 */ @@ -71,10 +74,15 @@ public class RequestBodyPlugin implements FizzPluginFilter { } if (log.isDebugEnabled()) { 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 doFilter(ServerWebExchange exchange, Map config) { + return FizzPluginFilterChain.next(exchange); + } } diff --git a/fizz-core/src/main/java/we/proxy/CallbackService.java b/fizz-core/src/main/java/we/proxy/CallbackService.java index ee083df..a08c5cf 100644 --- a/fizz-core/src/main/java/we/proxy/CallbackService.java +++ b/fizz-core/src/main/java/we/proxy/CallbackService.java @@ -208,7 +208,7 @@ public class CallbackService { HashSet gatewayGroups = new HashSet<>(); gatewayGroups.add(req.gatewayGroup); - Result result = apiConfigService.getApiConfig(gatewayGroups, req.app, req.service, req.method, req.path); + Result result = apiConfigService.get(gatewayGroups, req.app, req.service, req.method, req.path); ApiConfig ac = result.data; if (ac == null) { return Mono.just(ReactiveResult.fail("no api config for " + req.path));