diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionRouteLocator.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionRouteLocator.java index 54463142..72b9ed44 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionRouteLocator.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/RouteDefinitionRouteLocator.java @@ -41,6 +41,7 @@ import org.springframework.cloud.gateway.handler.AsyncPredicate; import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition; import org.springframework.cloud.gateway.handler.predicate.RoutePredicateFactory; import org.springframework.cloud.gateway.support.ConfigurationUtils; +import org.springframework.cloud.gateway.support.HasRouteId; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.core.Ordered; @@ -173,6 +174,13 @@ public class RouteDefinitionRouteLocator ConfigurationUtils.bind(configuration, properties, factory.shortcutFieldPrefix(), definition.getName(), validator); + // some filters require routeId + // TODO: is there a better place to apply this? + if (configuration instanceof HasRouteId) { + HasRouteId hasRouteId = (HasRouteId) configuration; + hasRouteId.setRouteId(id); + } + GatewayFilter gatewayFilter = factory.apply(configuration); if (this.publisher != null) { this.publisher.publishEvent(new FilterArgsEvent(this, id, properties)); diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java index f5511e03..4267b218 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java @@ -84,6 +84,14 @@ public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTest @Test public void retryFilterPost() { + testClient.post().uri("/retrypost?key=postconfig&expectedbody=HelloConfig") + .header(HttpHeaders.HOST, "www.retrypostconfig.org") + .syncBody("HelloConfig").exchange().expectStatus().isOk() + .expectBody(String.class).isEqualTo("3"); + } + + @Test + public void retryFilterPostJavaDsl() { testClient.post().uri("/retrypost?key=post&expectedbody=Hello") .header(HttpHeaders.HOST, "www.retryjava.org").syncBody("Hello") .exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("3"); @@ -131,7 +139,8 @@ public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTest @RequestMapping("/httpbin/retrypost") public ResponseEntity retry(@RequestParam("key") String key, @RequestParam(name = "count", defaultValue = "3") int count, - @RequestParam("expectedbody") String expectedbody, @RequestBody String body) { + @RequestParam("expectedbody") String expectedbody, + @RequestBody String body) { ResponseEntity response = retry(key, count); if (!expectedbody.equals(body)) { AtomicInteger num = getCount(key); diff --git a/spring-cloud-gateway-core/src/test/resources/application.yml b/spring-cloud-gateway-core/src/test/resources/application.yml index 29f27f06..06ccc646 100644 --- a/spring-cloud-gateway-core/src/test/resources/application.yml +++ b/spring-cloud-gateway-core/src/test/resources/application.yml @@ -251,6 +251,16 @@ spring: filters: - Retry + # ===================================== + - id: retry_post_test + uri: ${test.uri} + predicates: + - Host=**.retrypostconfig.org + filters: + - name: Retry + args: + methods: GET,POST + # ===================================== - id: secure_headers_test uri: ${test.uri}