Doc set path can be ant path
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
<commons-pool2.version>2.11.1</commons-pool2.version>
|
||||
<gson.version>2.8.8</gson.version>
|
||||
<netty-tcnative.version>2.0.44.Final</netty-tcnative.version>
|
||||
<spring-cloud.version>2.2.9.RELEASE</spring-cloud.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -54,8 +55,24 @@
|
||||
<groupId>com.fizzgate</groupId>
|
||||
<artifactId>fizz-input-mysql</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency> -->
|
||||
</dependencies>
|
||||
</dependency> -->
|
||||
|
||||
<!--<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-circuitbreaker</artifactId>
|
||||
<version>1.0.6.RELEASE</version>
|
||||
</dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-context</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
<!--<profile>
|
||||
|
||||
@@ -31,6 +31,7 @@ import we.plugin.auth.ApiConfig;
|
||||
import we.util.JacksonUtils;
|
||||
import we.util.ReactiveResult;
|
||||
import we.util.Result;
|
||||
import we.util.UrlTransformUtils;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
@@ -46,13 +47,13 @@ public class ApiPairingDocSetService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ApiPairingDocSetService.class);
|
||||
|
||||
private Map<Long /* doc set id */, ApiPairingDocSet> docSetMap = new HashMap<>(64);
|
||||
private Map<Long /* doc set id */, ApiPairingDocSet> docSetMap = new HashMap<>(64);
|
||||
|
||||
private Map<String /* app id */, Set<ApiPairingDocSet>> appDocSetMap = new HashMap<>(64);
|
||||
private Map<String /* app id */, Set<ApiPairingDocSet>> appDocSetMap = new HashMap<>(64);
|
||||
|
||||
private Map<String /* service */, Set<ApiPairingDocSet>> serviceExistsInDocSetMap = new HashMap<>(64);
|
||||
private Map<String /* service */, Set<ApiPairingDocSet>> serviceExistsInDocSetMap = new HashMap<>(64);
|
||||
|
||||
private Map<String /* path */, Map<Object /* method */, Set<ApiPairingDocSet>>> pathMethodExistsInDocSetMap = new HashMap<>(64);
|
||||
private Map<Object /* method */, Map<String /* path pattern */, Set<ApiPairingDocSet>>> methodPathExistsInDocSetMap = new HashMap<>();
|
||||
|
||||
@Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE)
|
||||
private ReactiveStringRedisTemplate rt;
|
||||
@@ -163,15 +164,15 @@ public class ApiPairingDocSetService {
|
||||
}
|
||||
}
|
||||
for (Api api : doc.apis) {
|
||||
Map<Object, Set<ApiPairingDocSet>> methodDocSetMap = pathMethodExistsInDocSetMap.get(api.path);
|
||||
if (methodDocSetMap != null) {
|
||||
dss = methodDocSetMap.get(api.method);
|
||||
Map<String, Set<ApiPairingDocSet>> pathDocSetMap = methodPathExistsInDocSetMap.get(api.method);
|
||||
if (pathDocSetMap != null) {
|
||||
dss = pathDocSetMap.get(api.path);
|
||||
if (dss != null) {
|
||||
dss.remove(docSet);
|
||||
if (dss.isEmpty()) {
|
||||
methodDocSetMap.remove(api.method);
|
||||
if (methodDocSetMap.isEmpty()) {
|
||||
pathMethodExistsInDocSetMap.remove(api.path);
|
||||
pathDocSetMap.remove(api.path);
|
||||
if (pathDocSetMap.isEmpty()) {
|
||||
methodPathExistsInDocSetMap.remove(api.method);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,33 +186,17 @@ public class ApiPairingDocSetService {
|
||||
docSetMap.put(docSet.id, docSet);
|
||||
docSet.appIds.forEach(
|
||||
appId -> {
|
||||
Set<ApiPairingDocSet> dss = appDocSetMap.get(appId);
|
||||
if (dss == null) {
|
||||
dss = new HashSet<>();
|
||||
appDocSetMap.put(appId, dss);
|
||||
}
|
||||
Set<ApiPairingDocSet> dss = appDocSetMap.computeIfAbsent(appId, k -> new HashSet<>());
|
||||
dss.add(docSet);
|
||||
}
|
||||
);
|
||||
docSet.docs.forEach(
|
||||
doc -> {
|
||||
Set<ApiPairingDocSet> dss = serviceExistsInDocSetMap.get(doc.service);
|
||||
if (dss == null) {
|
||||
dss = new HashSet<>();
|
||||
serviceExistsInDocSetMap.put(doc.service, dss);
|
||||
}
|
||||
Set<ApiPairingDocSet> dss = serviceExistsInDocSetMap.computeIfAbsent(doc.service, k -> new HashSet<>());
|
||||
dss.add(docSet);
|
||||
for (Api api : doc.apis) {
|
||||
Map<Object, Set<ApiPairingDocSet>> methodDocSetMap = pathMethodExistsInDocSetMap.get(api.path);
|
||||
if (methodDocSetMap == null) {
|
||||
methodDocSetMap = new HashMap<>(8);
|
||||
pathMethodExistsInDocSetMap.put(api.path, methodDocSetMap);
|
||||
}
|
||||
dss = methodDocSetMap.get(api.method);
|
||||
if (dss == null) {
|
||||
dss = new HashSet<>();
|
||||
methodDocSetMap.put(api.method, dss);
|
||||
}
|
||||
Map<String, Set<ApiPairingDocSet>> pathDocSetMap = methodPathExistsInDocSetMap.computeIfAbsent(api.method, k -> new HashMap<>());
|
||||
dss = pathDocSetMap.computeIfAbsent(api.path, k -> new HashSet<>());
|
||||
dss.add(docSet);
|
||||
}
|
||||
}
|
||||
@@ -236,8 +221,8 @@ public class ApiPairingDocSetService {
|
||||
return serviceExistsInDocSetMap;
|
||||
}
|
||||
|
||||
public Map<String, Map<Object, Set<ApiPairingDocSet>>> getPathMethodExistsInDocSetMap() {
|
||||
return pathMethodExistsInDocSetMap;
|
||||
public Map<Object, Map<String, Set<ApiPairingDocSet>>> getMethodPathExistsInDocSetMap() {
|
||||
return methodPathExistsInDocSetMap;
|
||||
}
|
||||
|
||||
public boolean existsDocSetMatch(String appId, HttpMethod method, String service, String path) {
|
||||
@@ -249,26 +234,39 @@ public class ApiPairingDocSetService {
|
||||
if (serviceDocSets == null) {
|
||||
return false;
|
||||
}
|
||||
Map<Object, Set<ApiPairingDocSet>> methodDocSetMap = pathMethodExistsInDocSetMap.get(path);
|
||||
if (methodDocSetMap == null) {
|
||||
|
||||
Set<ApiPairingDocSet> s = new HashSet<>();
|
||||
Map<String, Set<ApiPairingDocSet>> pathDocSetMap = methodPathExistsInDocSetMap.get(method);
|
||||
if (pathDocSetMap != null) {
|
||||
checkPathPattern(pathDocSetMap, path, s);
|
||||
}
|
||||
pathDocSetMap = methodPathExistsInDocSetMap.get(ApiConfig.ALL_METHOD);
|
||||
if (pathDocSetMap != null) {
|
||||
checkPathPattern(pathDocSetMap, path, s);
|
||||
}
|
||||
if (s.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
Set<ApiPairingDocSet> pathMethodDocSets = methodDocSetMap.get(method);
|
||||
if (pathMethodDocSets == null) {
|
||||
pathMethodDocSets = methodDocSetMap.get(ApiConfig.ALL_METHOD);
|
||||
if (pathMethodDocSets == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
s.retainAll(appDocSets);
|
||||
if (s.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
Set<ApiPairingDocSet> s = new HashSet<>(appDocSets);
|
||||
s.retainAll(serviceDocSets);
|
||||
if (s.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
s.retainAll(pathMethodDocSets);
|
||||
if (s.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void checkPathPattern(Map<String, Set<ApiPairingDocSet>> pathDocSetMap, String path, Set<ApiPairingDocSet> result) {
|
||||
Set<Map.Entry<String, Set<ApiPairingDocSet>>> entries = pathDocSetMap.entrySet();
|
||||
for (Map.Entry<String, Set<ApiPairingDocSet>> entry : entries) {
|
||||
String pathPattern = entry.getKey();
|
||||
if (pathPattern.equals(path) || UrlTransformUtils.ANT_PATH_MATCHER.match(pathPattern, path)) {
|
||||
result.addAll(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,9 +113,12 @@ class FizzApiPairingHttpHandler implements HttpHandler {
|
||||
|
||||
StringBuilder b = ThreadContext.getStringBuilder();
|
||||
b.append(apiPairingInfo.url).append(path);
|
||||
String rawQuery = requestURI.getRawQuery();
|
||||
if (StringUtils.hasText(rawQuery)) {
|
||||
b.append(Consts.S.QUESTION).append(rawQuery);
|
||||
String qry = requestURI.getQuery();
|
||||
if (StringUtils.hasText(qry)) {
|
||||
if (org.apache.commons.lang3.StringUtils.indexOfAny(qry, Consts.S.LEFT_BRACE, Consts.S.FORWARD_SLASH, Consts.S.HASH) > 0) {
|
||||
qry = requestURI.getRawQuery();
|
||||
}
|
||||
b.append(Consts.S.QUESTION).append(qry);
|
||||
}
|
||||
String targetUrl = b.toString();
|
||||
String appId = apiPairingInfo.appId;
|
||||
|
||||
@@ -34,10 +34,6 @@ public class ServiceConfig {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ServiceConfig.class);
|
||||
|
||||
// private static final String gmpT = "gmpT";
|
||||
|
||||
// private static final String gsmpT = "gsmpT";
|
||||
|
||||
private String id;
|
||||
|
||||
public Map<String/*gateway group*/,
|
||||
@@ -122,7 +118,6 @@ public class ServiceConfig {
|
||||
if (method2pathPattenMap == null) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
// ArrayList<ApiConfig> result = ThreadContext.getArrayList(gmpT);
|
||||
ArrayList<ApiConfig> result = ThreadContext.getArrayList();
|
||||
Map<String, ApiConfig> pathPattern2apiConfigMap = method2pathPattenMap.get(method);
|
||||
if (pathPattern2apiConfigMap != null) {
|
||||
@@ -145,6 +140,7 @@ public class ServiceConfig {
|
||||
if (apiConfig.exactMatch) {
|
||||
if (pathPattern.equals(path)) {
|
||||
result.add(apiConfig);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (UrlTransformUtils.ANT_PATH_MATCHER.match(pathPattern, path)) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import we.Fizz;
|
||||
import we.redis.RedisProperties;
|
||||
import we.redis.RedisServerConfiguration;
|
||||
import we.redis.RedisTemplateConfiguration;
|
||||
import we.util.JacksonUtils;
|
||||
import we.util.ReflectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -59,11 +60,11 @@ public class ApiPairingDocSetServiceTests {
|
||||
Map<Long, ApiPairingDocSet> docSetMap = apiPairingDocSetService.getDocSetMap();
|
||||
Map<String, Set<ApiPairingDocSet>> appDocSetMap = apiPairingDocSetService.getAppDocSetMap();
|
||||
Map<String, Set<ApiPairingDocSet>> serviceExistsInDocSetMap = apiPairingDocSetService.getServiceExistsInDocSetMap();
|
||||
Map<String, Map<Object, Set<ApiPairingDocSet>>> pathMethodExistsInDocSetMap = apiPairingDocSetService.getPathMethodExistsInDocSetMap();
|
||||
Map<Object, Map<String, Set<ApiPairingDocSet>>> methodPathExistsInDocSetMap = apiPairingDocSetService.getMethodPathExistsInDocSetMap();
|
||||
// System.err.println("docSetMap: " + JacksonUtils.writeValueAsString(docSetMap));
|
||||
// System.err.println("appDocSetMap: " + JacksonUtils.writeValueAsString(appDocSetMap));
|
||||
// System.err.println("serviceExistsInDocSetMap: " + JacksonUtils.writeValueAsString(serviceExistsInDocSetMap));
|
||||
// System.err.println("pathMethodExistsInDocSetMap: " + JacksonUtils.writeValueAsString(pathMethodExistsInDocSetMap));
|
||||
// System.err.println("methodPathExistsInDocSetMap: " + JacksonUtils.writeValueAsString(methodPathExistsInDocSetMap));
|
||||
|
||||
boolean b = apiPairingDocSetService.existsDocSetMatch("app1", HttpMethod.GET, "we-meb", "/getMebInfo");
|
||||
Assert.assertTrue(b);
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
import we.config.SystemConfig;
|
||||
import we.flume.clients.log4j2appender.LogService;
|
||||
import we.plugin.FizzPluginFilter;
|
||||
import we.plugin.FizzPluginFilterChain;
|
||||
import we.plugin.auth.App;
|
||||
@@ -61,6 +62,7 @@ public class ApiPairingPluginFilter implements FizzPluginFilter {
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, Map<String, Object> config) {
|
||||
try {
|
||||
LogService.setBizId(WebUtils.getTraceId(exchange));
|
||||
String appid = WebUtils.getAppId(exchange);
|
||||
App app = appService.getApp(appid);
|
||||
String ts = WebUtils.getTimestamp(exchange);
|
||||
|
||||
14
pom.xml
14
pom.xml
@@ -23,6 +23,7 @@
|
||||
<reflections.version>0.9.11</reflections.version>
|
||||
<commons-pool2.version>2.11.1</commons-pool2.version>
|
||||
<netty-tcnative.version>2.0.44.Final</netty-tcnative.version>
|
||||
<spring-cloud.version>2.2.9.RELEASE</spring-cloud.version>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
@@ -202,7 +203,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
<version>2.2.9.RELEASE</version>
|
||||
<version>${spring-cloud.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -229,6 +230,17 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-context</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user