diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactory.java index 9a25cb62..f91f8073 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactory.java @@ -50,10 +50,10 @@ import org.springframework.web.util.UriComponentsBuilder; import static java.util.Collections.singletonList; import static java.util.Optional.ofNullable; import static org.springframework.cloud.gateway.support.GatewayToStringStyler.filterToStringCreator; -import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ALREADY_ROUTED_ATTR; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.HYSTRIX_EXECUTION_EXCEPTION_ATTR; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.containsEncodedParts; +import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.removeAlreadyRouted; /** * Depends on `spring-cloud-starter-netflix-hystrix`, @@ -276,7 +276,7 @@ public class HystrixGatewayFilterFactory // Before we continue on remove the already routed attribute since the // fallback may go back through the route handler if the fallback // is to another route in the Gateway - mutated.getAttributes().remove(GATEWAY_ALREADY_ROUTED_ATTR); + removeAlreadyRouted(mutated); return RxReactiveStreams.toObservable(getDispatcherHandler().handle(mutated)); } diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java index 00d85788..7852ef5e 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java @@ -49,7 +49,7 @@ import org.springframework.web.server.ServerWebExchange; import static org.springframework.cloud.gateway.support.GatewayToStringStyler.filterToStringCreator; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.CLIENT_RESPONSE_HEADER_NAMES; -import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ALREADY_ROUTED_ATTR; +import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.removeAlreadyRouted; public class RetryGatewayFilterFactory extends AbstractGatewayFilterFactory { @@ -207,7 +207,7 @@ public class RetryGatewayFilterFactory CLIENT_RESPONSE_HEADER_NAMES, Collections.emptySet()); addedHeaders .forEach(header -> exchange.getResponse().getHeaders().remove(header)); - exchange.getAttributes().remove(GATEWAY_ALREADY_ROUTED_ATTR); + removeAlreadyRouted(exchange); } @Deprecated diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerFilterFactory.java index 4a756ff9..129a9e88 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerFilterFactory.java @@ -37,9 +37,9 @@ import static java.util.Collections.singletonList; import static java.util.Optional.ofNullable; import static org.springframework.cloud.gateway.support.GatewayToStringStyler.filterToStringCreator; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.CIRCUITBREAKER_EXECUTION_EXCEPTION_ATTR; -import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ALREADY_ROUTED_ATTR; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.containsEncodedParts; +import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.removeAlreadyRouted; /** * @author Ryan Baxter @@ -103,7 +103,7 @@ public abstract class SpringCloudCircuitBreakerFilterFactory extends // Before we continue on remove the already routed attribute since the // fallback may go back through the route handler if the fallback // is to another route in the Gateway - exchange.getAttributes().remove(GATEWAY_ALREADY_ROUTED_ATTR); + removeAlreadyRouted(exchange); ServerHttpRequest request = exchange.getRequest().mutate() .uri(requestUrl).build(); diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/ServerWebExchangeUtils.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/ServerWebExchangeUtils.java index f293ece2..ca90c619 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/ServerWebExchangeUtils.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/ServerWebExchangeUtils.java @@ -172,6 +172,10 @@ public final class ServerWebExchangeUtils { exchange.getAttributes().put(GATEWAY_ALREADY_ROUTED_ATTR, true); } + public static void removeAlreadyRouted(ServerWebExchange exchange) { + exchange.getAttributes().remove(GATEWAY_ALREADY_ROUTED_ATTR); + } + public static boolean isAlreadyRouted(ServerWebExchange exchange) { return exchange.getAttributeOrDefault(GATEWAY_ALREADY_ROUTED_ATTR, false); }