Merge pull request #3211 from ryanjbaxter/path-fallback-uri

Support segments with Java config. Fixes #3204
This commit is contained in:
Ryan Baxter
2024-01-24 16:28:46 -05:00
committed by GitHub
3 changed files with 21 additions and 2 deletions

View File

@@ -17,6 +17,8 @@
package org.springframework.cloud.gateway.filter.factory;
import java.net.URI;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -135,8 +137,10 @@ public abstract class SpringCloudCircuitBreakerFilterFactory
@Override
public String toString() {
String fallbackUriString = config.fallbackUri != null
? URLDecoder.decode(config.fallbackUri.toString(), StandardCharsets.UTF_8) : null;
return filterToStringCreator(SpringCloudCircuitBreakerFilterFactory.this)
.append("name", config.getName()).append("fallback", config.fallbackUri).toString();
.append("name", config.getName()).append("fallback", fallbackUriString).toString();
}
};
}
@@ -184,7 +188,7 @@ public abstract class SpringCloudCircuitBreakerFilterFactory
}
public Config setFallbackUri(String fallbackUri) {
return setFallbackUri(URI.create(fallbackUri));
return setFallbackUri(UriComponentsBuilder.fromUriString(fallbackUri).build().toUri());
}
public String getName() {

View File

@@ -91,6 +91,12 @@ public abstract class SpringCloudCircuitBreakerFilterFactoryTests extends BaseWe
.is5xxServerError();
}
@Test
public void testJavaConfigSegments() {
testClient.get().uri("/fallback/seg").exchange().expectStatus().isOk().expectBody()
.json("{\"from\":\"circuitbreakerfallbackcontrollerseg\"}");
}
@Test
public void filterErrorPage() {
testClient.get().uri("/delay/3").header("Host", "www.circuitbreakerconnectfail.org").accept(APPLICATION_JSON)

View File

@@ -83,6 +83,11 @@ public class SpringCloudCircuitBreakerTestConfig {
return Collections.singletonMap("from", "circuitbreakerfallbackcontroller3");
}
@GetMapping("/circuitbreakerFallbackController/seg")
public Map<String, String> fallbackcontrollerSeg() {
return Collections.singletonMap("from", "circuitbreakerfallbackcontrollerseg");
}
@GetMapping("/statusCodeFallbackController")
public Map<String, String> statusCodeFallbackController(ServerWebExchange exchange) {
return Collections.singletonMap("from", "statusCodeFallbackController");
@@ -106,6 +111,10 @@ public class SpringCloudCircuitBreakerTestConfig {
return builder.routes()
.route("fallback_controller_3",
r -> r.path("/fallback").filters(f -> f.setPath("/circuitbreakerFallbackController3")).uri(uri))
.route("fallback_with_segments", r -> r.path("/fallback/{*segments}")
.filters(f -> f.circuitBreaker(c -> c.setName("test")
.setFallbackUri("forward:/circuitbreakerFallbackController/{segments}")))
.uri(uri))
.route("circuitbreaker_fallback_forward", r -> r.host("**.circuitbreakerforward.org")
.filters(f -> f.circuitBreaker(config -> config.setFallbackUri("forward:/fallback"))).uri(uri))
.route("circuitbreaker_java",