From 0037ef60f99045d61e6fe7dc6b72d7a7a40ceac5 Mon Sep 17 00:00:00 2001 From: spencergibb Date: Wed, 6 Oct 2021 23:20:12 -0400 Subject: [PATCH] Updates mappings to pass tests --- .../gateway/filter/headers/XForwardedHeadersFilter.java | 3 +++ .../factory/RetryGatewayFilterFactoryIntegrationTests.java | 6 ++++-- ...gCloudCircuitBreakerResilience4JFilterFactoryTests.java | 2 +- .../factory/SpringCloudCircuitBreakerTestConfig.java | 7 ++++--- .../cloud/gateway/test/HttpBinCompatibleController.java | 6 +++--- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/headers/XForwardedHeadersFilter.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/headers/XForwardedHeadersFilter.java index f80ab45f..1623349e 100644 --- a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/headers/XForwardedHeadersFilter.java +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/headers/XForwardedHeadersFilter.java @@ -284,6 +284,9 @@ public class XForwardedHeadersFilter implements HttpHeadersFilter, Ordered { } private void write(HttpHeaders headers, String name, String value, boolean append) { + if (value == null) { + return; + } if (append) { headers.add(name, value); // these headers should be treated as a single comma separated header diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java index 46e76748..d2ac12e4 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java @@ -54,7 +54,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -211,7 +213,7 @@ public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTest @Value("${test.uri}") private String uri; - @GetMapping("/httpbin/sleep") + @RequestMapping("/httpbin/sleep") public Mono> sleep(@RequestParam("key") String key, @RequestParam("millis") long millisToSleep) { AtomicInteger num = getCount(key); @@ -231,7 +233,7 @@ public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTest .body("permanently broken"); } - @GetMapping("/httpbin/retrypost") + @PostMapping("/httpbin/retrypost") public ResponseEntity retrypost(@RequestParam("key") String key, @RequestParam(name = "count", defaultValue = "3") int count, @RequestParam("expectedbody") String expectedbody, @RequestBody String body) { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerResilience4JFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerResilience4JFilterFactoryTests.java index bdda74aa..fbfd6cba 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerResilience4JFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerResilience4JFilterFactoryTests.java @@ -44,7 +44,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen * @author Ryan Baxter */ @SpringBootTest(webEnvironment = RANDOM_PORT, - properties = { "debug=true", "spring.cloud.circuitbreaker.hystrix.enabled=false" }) + properties = { "logging.level.org.springframework.cloud.gateway=TRACE", "debug=true", "spring.cloud.circuitbreaker.hystrix.enabled=false" }) @ContextConfiguration(classes = SpringCloudCircuitBreakerResilience4JFilterFactoryTests.Config.class) @DirtiesContext public class SpringCloudCircuitBreakerResilience4JFilterFactoryTests diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerTestConfig.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerTestConfig.java index 80712f5e..a6676b6b 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerTestConfig.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerTestConfig.java @@ -38,6 +38,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.reactive.function.server.RouterFunction; @@ -82,7 +83,7 @@ public class SpringCloudCircuitBreakerTestConfig { return Collections.singletonMap("from", "statusCodeFallbackController"); } - @GetMapping("/resetExchangeFallbackController") + @RequestMapping("/resetExchangeFallbackController") public ResponseEntity> resetExchangeFallbackController(ServerWebExchange exchange) { return ResponseEntity.status(HttpStatus.OK) .headers((HttpHeaders) exchange.getRequest().getHeaders().entrySet().stream() @@ -98,10 +99,10 @@ public class SpringCloudCircuitBreakerTestConfig { @Bean public RouteLocator circuitBreakerRouteLocator(RouteLocatorBuilder builder) { return builder.routes() - .route("circuitbreaker_fallback_forward", r -> r.host("**.circuitbreakerforward.org") - .filters(f -> f.circuitBreaker(config -> config.setFallbackUri("forward:/fallback"))).uri(uri)) .route("fallback_controller_3", r -> r.path("/fallback").filters(f -> f.setPath("/circuitbreakerFallbackController3")).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", r -> r.host("**.circuitbreakerjava.org") .filters(f -> f.prefixPath("/httpbin").circuitBreaker( diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/HttpBinCompatibleController.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/HttpBinCompatibleController.java index 5b9a990c..12fb3f68 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/HttpBinCompatibleController.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/HttpBinCompatibleController.java @@ -96,7 +96,7 @@ public class HttpBinCompatibleController { } @GetMapping(path = "/delay/{sec}", produces = MediaType.APPLICATION_JSON_VALUE) - public Mono> get(ServerWebExchange exchange, @PathVariable int sec) + public Mono> delay(ServerWebExchange exchange, @PathVariable int sec) throws InterruptedException { int delay = Math.min(sec, 10); return Mono.just(get(exchange)).delayElement(Duration.ofSeconds(delay)); @@ -122,7 +122,7 @@ public class HttpBinCompatibleController { return result; } - @GetMapping(value = "/post", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, + @PostMapping(value = "/post", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public Mono> postFormData(@RequestBody Mono> parts) { // StringDecoder decoder = StringDecoder.allMimeTypes(true); @@ -136,7 +136,7 @@ public class HttpBinCompatibleController { }).map(files -> Collections.singletonMap("files", files)); } - @GetMapping(path = "/post", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, + @PostMapping(path = "/post", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public Mono> postUrlEncoded(ServerWebExchange exchange) throws IOException { return post(exchange, null);