diff --git a/reference/html/index.html b/reference/html/index.html index 904d1520..72de683b 100644 --- a/reference/html/index.html +++ b/reference/html/index.html @@ -1933,45 +1933,31 @@ This property takes a list of filters

6.1. Combined Global Filter and GatewayFilter Ordering

-

When a request comes in (and matches a Route) the Filtering Web Handler will add all instances of GlobalFilter and all route specific instances of GatewayFilter to a filter chain. This combined filter chain is sorted by the org.springframework.core.Ordered interface, which can be set by implementing the getOrder() method or by using the @Order annotation.

+

When a request comes in (and matches a Route) the Filtering Web Handler will add all instances of GlobalFilter and all route specific instances of GatewayFilter to a filter chain. This combined filter chain is sorted by the org.springframework.core.Ordered interface, which can be set by implementing the getOrder() method.

-

As Spring Cloud Gateway distinguishes between "pre" and "post" phases for filter logic execution (see: How It Works), the filter with the highest precedence will be the first in the "pre"-phase and the last in the "post"-phase.

+

As Spring Cloud Gateway distinguishes between "pre" and "post" phases for filter logic execution (see: How it Works), the filter with the highest precedence will be the first in the "pre"-phase and the last in the "post"-phase.

ExampleConfiguration.java
@Bean
-@Order(-1)
-public GlobalFilter a() {
-    return (exchange, chain) -> {
-        log.info("first pre filter");
-        return chain.filter(exchange).then(Mono.fromRunnable(() -> {
-            log.info("third post filter");
-        }));
-    };
+public GlobalFilter customFilter() {
+    return CustomGlobalFilter();
 }
 
-@Bean
-@Order(0)
-public GlobalFilter b() {
-    return (exchange, chain) -> {
-        log.info("second pre filter");
-        return chain.filter(exchange).then(Mono.fromRunnable(() -> {
-            log.info("second post filter");
-        }));
-    };
-}
+public class CustomGlobalFilter implements GlobalFilter, Ordered {
 
-@Bean
-@Order(1)
-public GlobalFilter c() {
-    return (exchange, chain) -> {
-        log.info("third pre filter");
-        return chain.filter(exchange).then(Mono.fromRunnable(() -> {
-            log.info("first post filter");
-        }));
-    };
+    @Override
+    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
+        log.info("custom global filter");
+        return chain.filter(exchange);
+    }
+
+    @Override
+    public int getOrder() {
+        return -1;
+    }
 }
diff --git a/reference/html/spring-cloud-gateway.html b/reference/html/spring-cloud-gateway.html index 904d1520..72de683b 100644 --- a/reference/html/spring-cloud-gateway.html +++ b/reference/html/spring-cloud-gateway.html @@ -1933,45 +1933,31 @@ This property takes a list of filters

6.1. Combined Global Filter and GatewayFilter Ordering

-

When a request comes in (and matches a Route) the Filtering Web Handler will add all instances of GlobalFilter and all route specific instances of GatewayFilter to a filter chain. This combined filter chain is sorted by the org.springframework.core.Ordered interface, which can be set by implementing the getOrder() method or by using the @Order annotation.

+

When a request comes in (and matches a Route) the Filtering Web Handler will add all instances of GlobalFilter and all route specific instances of GatewayFilter to a filter chain. This combined filter chain is sorted by the org.springframework.core.Ordered interface, which can be set by implementing the getOrder() method.

-

As Spring Cloud Gateway distinguishes between "pre" and "post" phases for filter logic execution (see: How It Works), the filter with the highest precedence will be the first in the "pre"-phase and the last in the "post"-phase.

+

As Spring Cloud Gateway distinguishes between "pre" and "post" phases for filter logic execution (see: How it Works), the filter with the highest precedence will be the first in the "pre"-phase and the last in the "post"-phase.

ExampleConfiguration.java
@Bean
-@Order(-1)
-public GlobalFilter a() {
-    return (exchange, chain) -> {
-        log.info("first pre filter");
-        return chain.filter(exchange).then(Mono.fromRunnable(() -> {
-            log.info("third post filter");
-        }));
-    };
+public GlobalFilter customFilter() {
+    return CustomGlobalFilter();
 }
 
-@Bean
-@Order(0)
-public GlobalFilter b() {
-    return (exchange, chain) -> {
-        log.info("second pre filter");
-        return chain.filter(exchange).then(Mono.fromRunnable(() -> {
-            log.info("second post filter");
-        }));
-    };
-}
+public class CustomGlobalFilter implements GlobalFilter, Ordered {
 
-@Bean
-@Order(1)
-public GlobalFilter c() {
-    return (exchange, chain) -> {
-        log.info("third pre filter");
-        return chain.filter(exchange).then(Mono.fromRunnable(() -> {
-            log.info("first post filter");
-        }));
-    };
+    @Override
+    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
+        log.info("custom global filter");
+        return chain.filter(exchange);
+    }
+
+    @Override
+    public int getOrder() {
+        return -1;
+    }
 }