|
|
@@ -17,6 +17,7 @@ import org.springframework.http.HttpStatus;
|
|
17
|
17
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
18
|
18
|
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
|
|
19
|
19
|
import org.springframework.stereotype.Component;
|
|
|
20
|
+import org.springframework.util.AntPathMatcher;
|
|
20
|
21
|
import org.springframework.util.MultiValueMap;
|
|
21
|
22
|
import org.springframework.web.server.ServerWebExchange;
|
|
22
|
23
|
import reactor.core.publisher.Flux;
|
|
|
@@ -24,6 +25,7 @@ import reactor.core.publisher.Mono;
|
|
24
|
25
|
|
|
25
|
26
|
import java.net.URI;
|
|
26
|
27
|
import java.nio.charset.StandardCharsets;
|
|
|
28
|
+import java.util.Collections;
|
|
27
|
29
|
import java.util.List;
|
|
28
|
30
|
|
|
29
|
31
|
@Component
|
|
|
@@ -35,6 +37,20 @@ public class ApiRequestFilter implements GlobalFilter, Ordered {
|
|
35
|
37
|
|
|
36
|
38
|
JSONObject jsonObject=new JSONObject();
|
|
37
|
39
|
|
|
|
40
|
+ private final AntPathMatcher pathMatcher = new AntPathMatcher();
|
|
|
41
|
+
|
|
|
42
|
+ private static final List<String> EXTERNAL_PATHS = Collections.singletonList(
|
|
|
43
|
+ "/external/**"
|
|
|
44
|
+ );
|
|
|
45
|
+
|
|
|
46
|
+ private boolean isExternalPath(String path) {
|
|
|
47
|
+ for (String pattern : EXTERNAL_PATHS) {
|
|
|
48
|
+ if (pathMatcher.match(pattern, path)) {
|
|
|
49
|
+ return true;
|
|
|
50
|
+ }
|
|
|
51
|
+ }
|
|
|
52
|
+ return false;
|
|
|
53
|
+ }
|
|
38
|
54
|
|
|
39
|
55
|
@Override
|
|
40
|
56
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
|
|
@@ -47,6 +63,12 @@ public class ApiRequestFilter implements GlobalFilter, Ordered {
|
|
47
|
63
|
String path = request.getPath().value();
|
|
48
|
64
|
String method = request.getMethodValue();
|
|
49
|
65
|
HttpHeaders header = request.getHeaders();
|
|
|
66
|
+
|
|
|
67
|
+ // 检查是否为外部API路径
|
|
|
68
|
+ if (isExternalPath(path)) {
|
|
|
69
|
+ return chain.filter(exchange); // 跳过当前过滤器
|
|
|
70
|
+ }
|
|
|
71
|
+
|
|
50
|
72
|
log.info("***********************************请求信息**********************************");
|
|
51
|
73
|
|
|
52
|
74
|
jsonObject.set("URI",URIPath);
|