122. 开发人员指南
TODO:编写定制集成概述
122.1 编写自定义 Route 谓词工厂
TODO:编写自定义 Route 谓词工厂的文档
122.2 编写自定义 GatewayFilter 工厂
为了编写 GatewayFilter,您将需要实现GatewayFilterFactory
。您可以扩展一个名为AbstractGatewayFilterFactory
的抽象类。
PreGatewayFilterFactory.java.
public class PreGatewayFilterFactory extends AbstractGatewayFilterFactory<PreGatewayFilterFactory.Config> {
public PreGatewayFilterFactory() {
super(Config.class);
}
@Override
public GatewayFilter apply(Config config) {
// grab configuration from Config object
return (exchange, chain) -> {
//If you want to build a "pre" filter you need to manipulate the
//request before calling chain.filter
ServerHttpRequest.Builder builder = exchange.getRequest().mutate();
//use builder to manipulate the request
return chain.filter(exchange.mutate().request(request).build());
};
}
public static class Config {
//Put the configuration properties for your filter here
}
}
PostGatewayFilterFactory.java.
public class PostGatewayFilterFactory extends AbstractGatewayFilterFactory<PostGatewayFilterFactory.Config> {
public PostGatewayFilterFactory() {
super(Config.class);
}
@Override
public GatewayFilter apply(Config config) {
// grab configuration from Config object
return (exchange, chain) -> {
return chain.filter(exchange).then(Mono.fromRunnable(() -> {
ServerHttpResponse response = exchange.getResponse();
//Manipulate the response in some way
}));
};
}
public static class Config {
//Put the configuration properties for your filter here
}
}
122.3 编写自定义全局filter
TODO:编写自定义全局filter的文档
122.4 编写自定义 Route 定位器和编写器
TODO:编写自定义 Route 定位器和编写器的文档