|
1 | 1 | package io.github.kimmking.gateway.inbound; |
2 | 2 |
|
| 3 | +import io.github.kimmking.gateway.filter.TokenFilter; |
3 | 4 | import io.github.kimmking.gateway.outbound.httpclient4.HttpOutboundHandler; |
4 | 5 | import io.github.kimmking.gateway.outbound.okhttp.HutoolhttpOutboundHandler; |
5 | 6 | import io.github.kimmking.gateway.router.HttpEndpointRouter; |
@@ -34,19 +35,20 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) { |
34 | 35 | try { |
35 | 36 |
|
36 | 37 | FullHttpRequest fullRequest = (FullHttpRequest) msg; |
| 38 | + TokenFilter tokenFilter = new TokenFilter(); |
| 39 | + //过滤 |
| 40 | + tokenFilter.filter(fullRequest,ctx); |
37 | 41 |
|
38 | 42 | String url = fullRequest.uri(); |
39 | | - HttpEndpointRouter router = new HttpEndpointRouter() { |
40 | | - @Override |
41 | | - public String route(List<String> endpoints, List<String> proxyServers) { |
42 | | - if (endpoints.stream().anyMatch(e->e.startsWith("/user"))) { |
43 | | - return proxyServers.get(0); |
44 | | - } else if (endpoints.stream().anyMatch(e->e.startsWith("/order"))) { |
45 | | - return proxyServers.get(1); |
46 | | - } |
47 | | - return null; |
| 43 | + HttpEndpointRouter router = (endpoints, proxyServers) -> { |
| 44 | + if (endpoints.stream().anyMatch(e->e.startsWith("/user"))) { |
| 45 | + return proxyServers.get(0); |
| 46 | + } else if (endpoints.stream().anyMatch(e->e.startsWith("/order"))) { |
| 47 | + return proxyServers.get(1); |
48 | 48 | } |
| 49 | + return null; |
49 | 50 | }; |
| 51 | + //路由 |
50 | 52 | String proxy = router.route(Arrays.asList(url), Arrays.asList(this.proxyServer.split(",").clone())); |
51 | 53 | HutoolhttpOutboundHandler handler = new HutoolhttpOutboundHandler(proxy); |
52 | 54 | handler.handle(fullRequest, ctx); |
|
0 commit comments