|
@@ -10,6 +10,7 @@ import com.example.gateway.util.JsonToBean; |
|
@@ -10,6 +10,7 @@ import com.example.gateway.util.JsonToBean; |
10
|
import lombok.extern.slf4j.Slf4j;
|
10
|
import lombok.extern.slf4j.Slf4j;
|
11
|
import org.reactivestreams.Publisher;
|
11
|
import org.reactivestreams.Publisher;
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
13
|
+import org.springframework.beans.factory.annotation.Value;
|
13
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
14
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
14
|
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
15
|
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
15
|
import org.springframework.core.Ordered;
|
16
|
import org.springframework.core.Ordered;
|
|
@@ -43,6 +44,12 @@ public class WrapperResponseGlobalFilter implements GlobalFilter, Ordered { |
|
@@ -43,6 +44,12 @@ public class WrapperResponseGlobalFilter implements GlobalFilter, Ordered { |
43
|
@Autowired
|
44
|
@Autowired
|
44
|
private StringRedisTemplate stringRedisTemplate;
|
45
|
private StringRedisTemplate stringRedisTemplate;
|
45
|
|
46
|
|
|
|
47
|
+ @Value("${host.system-info}")
|
|
|
48
|
+ private String systemInfo;
|
|
|
49
|
+
|
|
|
50
|
+ //默认部署操作系统名称
|
|
|
51
|
+ private static final String DEFAULT_SYSTEM="linux";
|
|
|
52
|
+
|
46
|
private static AntPathMatcher pathMatcher = new AntPathMatcher();
|
53
|
private static AntPathMatcher pathMatcher = new AntPathMatcher();
|
47
|
|
54
|
|
48
|
@Override
|
55
|
@Override
|
|
@@ -87,8 +94,15 @@ public class WrapperResponseGlobalFilter implements GlobalFilter, Ordered { |
|
@@ -87,8 +94,15 @@ public class WrapperResponseGlobalFilter implements GlobalFilter, Ordered { |
87
|
// }
|
94
|
// }
|
88
|
// };
|
95
|
// };
|
89
|
|
96
|
|
90
|
- ServerHttpResponseDecorator decoratedResponseGBK= new GBKServerHttpResponseDecorator(response);
|
|
|
91
|
- return chain.filter(exchange.mutate().response(decoratedResponseGBK).build());
|
97
|
+ ServerHttpResponseDecorator decoratedResponse= new UTF8ServerHttpResponseDecorator(response);
|
|
|
98
|
+ if (DEFAULT_SYSTEM.equals(systemInfo)){
|
|
|
99
|
+ decoratedResponse= new UTF8ServerHttpResponseDecorator(response);
|
|
|
100
|
+ }else {
|
|
|
101
|
+ decoratedResponse= new GBKServerHttpResponseDecorator(response);
|
|
|
102
|
+ }
|
|
|
103
|
+//
|
|
|
104
|
+
|
|
|
105
|
+ return chain.filter(exchange.mutate().response(decoratedResponse).build());
|
92
|
//
|
106
|
//
|
93
|
// return chain.filter(exchange);
|
107
|
// return chain.filter(exchange);
|
94
|
}
|
108
|
}
|
|
@@ -131,6 +145,11 @@ public class WrapperResponseGlobalFilter implements GlobalFilter, Ordered { |
|
@@ -131,6 +145,11 @@ public class WrapperResponseGlobalFilter implements GlobalFilter, Ordered { |
131
|
return false;
|
145
|
return false;
|
132
|
}
|
146
|
}
|
133
|
|
147
|
|
|
|
148
|
+ /**
|
|
|
149
|
+ * 白名单接口访问判定
|
|
|
150
|
+ * @param request
|
|
|
151
|
+ * @return
|
|
|
152
|
+ */
|
134
|
public boolean anonymousUrlFilter(ServerHttpRequest request){
|
153
|
public boolean anonymousUrlFilter(ServerHttpRequest request){
|
135
|
//内部服务接口,不允许外部访问
|
154
|
//内部服务接口,不允许外部访问
|
136
|
if(pathMatcher.match("/**/anonymous/**", request.getPath().toString())) {
|
155
|
if(pathMatcher.match("/**/anonymous/**", request.getPath().toString())) {
|