RoutePredicateFactory 是一组专为路由匹配检测设计的接口,以完成匹配检测处理。对应 predicates 配置。
1、内置的匹配检测器
| 匹配检测器工厂 | 本置前缀 | 说明与示例 |
|---|---|---|
| AfterPredicateFactory | After= | After 时间检测器,ZonedDateTime 格式 ( After=2017-01-20T17:42:47.789-07:00[America/Denver]) |
| BeforePredicateFactory | Before= | After 时间检测器,ZonedDateTime 格式 ( Before=2017-01-20T17:42:47.789-07:00[America/Denver]) |
| CookiePredicateFactory | Cookie= | Cookie 检测器 ( Cookie=token)(Cookie=token, ^user.) |
| HeaderPredicateFactory | Header= | Header 检测器 ( Header=token)(Header=token, ^user.) |
| MethodPredicateFactory | Method= | Method 检测器 ( Method=GET,POST) |
| PathPredicateFactory | Path= | Path 检测器(支持多路径匹配,以","号隔开) ( Path=/demo/**) ,(Path=/demo/**,/hello/**) |
2、定制示例
- Path 检测器定制示例(配置例:
Path=/demo/**)
@Component
public class PathPredicateFactory implements RoutePredicateFactory {@Overridepublic String prefix() {return "Path";}@Overridepublic ExPredicate create(String config) {return new PathPredicate(config);}public static class PathPredicate implements ExPredicate {private PathRule rule;/*** @param config (Path=/demo/**)* */public PathPredicate(String config) {if (Utils.isBlank(config)) {throw new IllegalArgumentException("PathPredicate config cannot be blank");}rule = new PathRule();rule.include(config);}@Overridepublic boolean test(ExContext ctx) {return rule.test(ctx.rawPath());}}
}
