Merge pull request #2918 from ryanjbaxter/use-new-path-attribute-in-cb-filter

Remove gateway predicate path attribute in CB filter.
This commit is contained in:
Ryan Baxter
2023-04-05 11:09:57 -04:00
committed by GitHub
3 changed files with 22 additions and 0 deletions

View File

@@ -43,6 +43,7 @@ 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_PREDICATE_PATH_CONTAINER_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.reset;
@@ -115,6 +116,7 @@ public abstract class SpringCloudCircuitBreakerFilterFactory
URI requestUrl = UriComponentsBuilder.fromUri(uri).host(null).port(null)
.uri(config.getFallbackUri()).scheme(null).build(encoded).toUri();
exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, requestUrl);
exchange.getAttributes().remove(GATEWAY_PREDICATE_PATH_CONTAINER_ATTR);
addExceptionDetails(t, exchange);
// Reset the exchange

View File

@@ -60,6 +60,12 @@ public abstract class SpringCloudCircuitBreakerFilterFactoryTests extends BaseWe
.isOk().expectBody().json("{\"from\":\"circuitbreakerfallbackcontroller\"}");
}
@Test
public void filterFallbackPath() {
testClient.get().uri("/status/200").header("Host", "www.circuitbreakerfallbackpath.org").exchange().expectStatus()
.isOk().expectBody().jsonPath("$.headers").exists();
}
@Test
public void filterWorksJavaDsl() {
testClient.get().uri("/get").header("Host", "www.circuitbreakerjava.org").exchange().expectStatus().isOk()

View File

@@ -104,6 +104,20 @@ spring:
name: fallbackcmd
fallbackUri: forward:/circuitbreakerFallbackController
# =====================================
- id: circuitbreaker_fallback_test_path
uri: ${test.uri}
predicates:
- Path=/status/**
- Host=**.circuitbreakerfallbackpath.org
filters:
- name: CircuitBreaker
args:
name: fallbackcmd
statusCodes:
- 200
fallbackUri: forward:/headers
# =====================================
- id: circuitbreaker_fallback_test_statuscode
uri: ${test.uri}