Adds support for migrating default-filters.

Also adds migration tests for streaming-media-types. Removes unused migration key in server webmvc that is faulty anyway.

Fixes gh-3817
This commit is contained in:
spencergibb
2025-05-30 11:52:09 -04:00
parent 3017275785
commit 4b6fb4c0fb
6 changed files with 33 additions and 4 deletions

View File

@@ -56,8 +56,6 @@ class GatewayServerWebMvcPropertiesMigrationListener implements ApplicationListe
private static final String DEPRECATED_ROUTES_MAP_KEY = DEPRECATED_ROOT + ".routes-map";
private static final String DEPRECATED_ROUTESMAP_KEY = DEPRECATED_ROOT + ".routesMap";
private static final String GATEWAY_PROPERTY_SOURCE_PREFIX = "migrategatewaymvc";
private static final String NEW_ROUTES_LIST_KEY = GatewayMvcProperties.PREFIX + ".routes";
@@ -89,8 +87,6 @@ class GatewayServerWebMvcPropertiesMigrationListener implements ApplicationListe
DEPRECATED_ROUTES_LIST_KEY, NEW_ROUTES_LIST_KEY));
routesMigrations.addAll(migrate(env, propertySource, GATEWAY_PROPERTY_SOURCE_PREFIX + "routes-map-",
DEPRECATED_ROUTES_MAP_KEY, NEW_ROUTES_MAP_KEY));
routesMigrations.addAll(migrate(env, propertySource, GATEWAY_PROPERTY_SOURCE_PREFIX + "routesMap-",
DEPRECATED_ROUTES_MAP_KEY, NEW_ROUTES_MAP_KEY));
});
}

View File

@@ -34,6 +34,7 @@ import org.springframework.cloud.gateway.server.mvc.filter.TransferEncodingNorma
import org.springframework.cloud.gateway.server.mvc.filter.WeightCalculatorFilter;
import org.springframework.cloud.gateway.server.mvc.filter.XForwardedRequestHeadersFilter;
import org.springframework.context.ApplicationContext;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import static org.assertj.core.api.Assertions.assertThat;
@@ -69,6 +70,12 @@ public class GatewayMvcPropertiesMigrationTests {
assertThat(properties.getRoutesMap()).hasSize(2);
}
@Test
public void deprecatedStreamingMediaTypesWork() {
assertThat(properties.getStreamingMediaTypes()).hasSize(1)
.containsOnly(new MediaType("application", "activemessage"));
}
private void assertBeanDoesNotExist(Class<?> type) {
assertThat(context.getBeanNamesForType(type)).isEmpty();
}

View File

@@ -42,6 +42,8 @@ spring.cloud.gateway.mvc:
uri: https://example2.com
predicates:
- Path=/anything/example2
streaming-media-types: application/activemessage
logging:
level:
org.springframework.cloud.gateway.server.mvc: TRACE

View File

@@ -54,10 +54,14 @@ class GatewayServerWebfluxPropertiesMigrationListener implements ApplicationList
private static final String DEPRECATED_ROUTES_LIST_KEY = DEPRECATED_ROOT + ".routes";
private static final String DEPRECATED_DEFAULT_FILTERS_KEY = DEPRECATED_ROOT + ".default-filters";
private static final String GATEWAY_PROPERTY_SOURCE_PREFIX = "migrategatewayflux";
private static final String NEW_ROUTES_LIST_KEY = GatewayProperties.PREFIX + ".routes";
private static final String NEW_DEFAULT_FILTERS_KEY = GatewayProperties.PREFIX + ".default-filters";
private final List<Migration> routesMigrations = new ArrayList<>();
@Override
@@ -81,6 +85,8 @@ class GatewayServerWebfluxPropertiesMigrationListener implements ApplicationList
ConfigurationPropertySources.get(env).forEach(propertySource -> {
routesMigrations.addAll(migrate(env, propertySource, GATEWAY_PROPERTY_SOURCE_PREFIX + "routes-",
DEPRECATED_ROUTES_LIST_KEY, NEW_ROUTES_LIST_KEY));
routesMigrations.addAll(migrate(env, propertySource, GATEWAY_PROPERTY_SOURCE_PREFIX + "default-filters-",
DEPRECATED_DEFAULT_FILTERS_KEY, NEW_DEFAULT_FILTERS_KEY));
});
}

View File

@@ -29,6 +29,7 @@ import org.springframework.cloud.gateway.filter.headers.XForwardedHeadersFilter;
import org.springframework.cloud.gateway.handler.predicate.AfterRoutePredicateFactory;
import org.springframework.cloud.gateway.route.RouteRefreshListener;
import org.springframework.context.ApplicationContext;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import static org.assertj.core.api.Assertions.assertThat;
@@ -58,6 +59,19 @@ public class GatewayPropertiesMigrationTests {
assertThat(properties.getRoutes()).hasSize(2);
}
@Test
public void deprecatedDefaultFiltersPropertiesWork() {
assertThat(properties.getDefaultFilters()).hasSize(2);
assertThat(properties.getDefaultFilters().get(0).getName()).isEqualTo("AddRequestHeader");
assertThat(properties.getDefaultFilters().get(1).getName()).isEqualTo("AddRequestHeader");
}
@Test
public void deprecatedStreamingMediaTypesWork() {
assertThat(properties.getStreamingMediaTypes()).hasSize(1)
.containsOnly(new MediaType("application", "activemessage"));
}
private void assertBeanDoesNotExist(Class<?> type) {
assertThat(context.getBeanNamesForType(type)).isEmpty();
}

View File

@@ -27,6 +27,10 @@ spring.cloud.gateway:
pattern: /anything/listRoute2
filters:
- AddRequestHeader=X-Test,listRoute2
defaultFilters:
- AddRequestHeader=X-Default1
- AddRequestHeader=X-Default2
streaming-media-types: application/activemessage
logging:
level:
org.springframework.cloud.gateway: TRACE