Plugin can extend RequestBodyPlugin to modify request
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -78,7 +78,7 @@ public class ApiConfig {
|
||||
@JsonProperty(
|
||||
access = JsonProperty.Access.WRITE_ONLY
|
||||
)
|
||||
public String firstGatewayGroup;
|
||||
public String firstGatewayGroup = GatewayGroup.DEFAULT;
|
||||
|
||||
public String service;
|
||||
|
||||
|
||||
@@ -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<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) {
|
||||
return getApiConfig(null, app, service, method, path);
|
||||
public ApiConfig getApiConfig(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> 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);
|
||||
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<ApiConfig> appCanAccess = ThreadContext.getArrayList(macs);
|
||||
// List<ApiConfig> appCanAccess = ThreadContext.getArrayList(macs);
|
||||
List<ApiConfig> 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<ApiConfig> r = getApiConfig(app, service, method, path);
|
||||
Result<ApiConfig> r = get(app, service, method, path);
|
||||
if (r.code == Result.FAIL) {
|
||||
if (apiConfigServiceProperties.isNeedAuth()) {
|
||||
return Mono.just(r);
|
||||
|
||||
@@ -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<ApiConfig> result = ThreadContext.getArrayList(gmpT);
|
||||
// ArrayList<ApiConfig> result = ThreadContext.getArrayList(gmpT);
|
||||
ArrayList<ApiConfig> result = ThreadContext.getArrayList();
|
||||
Map<String, ApiConfig> pathPattern2apiConfigMap = method2pathPattenMap.get(method);
|
||||
if (pathPattern2apiConfigMap != null) {
|
||||
checkPathPattern(pathPattern2apiConfigMap, path, result);
|
||||
|
||||
@@ -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<Void> doFilter(ServerWebExchange exchange, Map<String, Object> config) {
|
||||
return FizzPluginFilterChain.next(exchange);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ public class CallbackService {
|
||||
|
||||
HashSet<String> gatewayGroups = new HashSet<>();
|
||||
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;
|
||||
if (ac == null) {
|
||||
return Mono.just(ReactiveResult.fail("no api config for " + req.path));
|
||||
|
||||
Reference in New Issue
Block a user