121. 开发人员指南

TODO:编写自定义集成的概述

121.1 编写自定义路由谓词工厂

TODO:文档编写 Custom Route Predicate Factories

121.2 编写自定义 GatewayFilter 工厂

在编写 GatewayFilter 的 order 中,您需要实现GatewayFilterFactory。有一个名为AbstractGatewayFilterFactory的抽象 class 可以扩展。

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 change.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
	}

}

121.3 编写自定义全局过滤器

TODO:文档编写 Custom Global Filters

121.4 编写自定义路由定位器和 Writers

TODO:文档编写 Custom Route Locators 和 Writers