From 3b8f440f27c45cce3bf13ab1ea087696b35f6984 Mon Sep 17 00:00:00 2001
From: buildmaster TODO: overview of writing custom integrations In order to write a GatewayFilter you will need to implement PreGatewayFilterFactory.java.
-
- } PostGatewayFilterFactory.java.
-
- }GatewayFilterFactory. There is an abstract class called AbstractGatewayFilterFactory which you can extend.---
-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
-}---
-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(() -> {
- ServerHttpReponse response = exchange.getResponse();
- //Manipulate the response in some way
- }));
- };
-}public static class Config {
- //Put the configuration properties for your filter here
-}
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(() -> { + ServerHttpReponse response = exchange.getResponse(); + //Manipulate the response in some way + })); + }; + } + + public static class Config { + //Put the configuration properties for your filter here + } + +}
+