Set routeId on configurations from route definitions.
fixes gh-1160
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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<String> 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<String> response = retry(key, count);
|
||||
if (!expectedbody.equals(body)) {
|
||||
AtomicInteger num = getCount(key);
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user