Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 45 additions & 81 deletions .settings.xml
Original file line number Diff line number Diff line change
@@ -1,83 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2013-2017 the original author or authors.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert all changes to this file

~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">

<settings>
<servers>
<server>
<id>repo.spring.io</id>
<username>${env.CI_DEPLOY_USERNAME}</username>
<password>${env.CI_DEPLOY_PASSWORD}</password>
</server>
</servers>
<profiles>
<profile>
<!--
N.B. this profile is only here to support users and IDEs that do not use Maven 3.3.
It isn't needed on the command line if you use the wrapper script (mvnw) or if you use
a native Maven with the right version. Eclipse users should points their Maven tooling to
this settings file, or copy the profile into their ~/.m2/settings.xml.
-->
<id>spring</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
<profiles>
<profile>
<id>spring-community</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<activeProfiles>
<activeProfile>spring-community</activeProfile>
</activeProfiles>
</settings>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.cloud.gateway.route;

import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -179,6 +180,42 @@ List<GatewayFilter> loadGatewayFilters(String id, List<FilterDefinition> filterD
}

private List<GatewayFilter> getFilters(RouteDefinition routeDefinition) {

// --- GH-3293: URI Path Syntactic Sugar ---
URI uri = routeDefinition.getUri();
if (uri != null && org.springframework.util.StringUtils.hasText(uri.getPath()) && !"/".equals(uri.getPath())) {

String path = uri.getPath();

// check if SetPath already exists to avoid duplication
boolean hasSetPath = routeDefinition.getFilters()
.stream()
.anyMatch(f -> "SetPath".equalsIgnoreCase(f.getName()));

if (!hasSetPath) {
// 1. Create the FilterDefinition programmatically
FilterDefinition sugar = new FilterDefinition();
sugar.setName("SetPath");
// SetPath expects a parameter named 'template'
sugar.addArg("template", path);

// Add it at the beginning of the filter chain
routeDefinition.getFilters().add(0, sugar);

// 2. Strip the path from the URI to prevent double-pathing
// (e.g., http://example.com/foo -> http://example.com)
URI strippedUri = org.springframework.web.util.UriComponentsBuilder.fromUri(uri)
.replacePath(null)
.build()
.toUri();
routeDefinition.setUri(strippedUri);
}
}
// --- END GH-3293 ---

// ... existing code follows (List<GatewayFilter> filters = new ArrayList<>();
// etc.)

List<GatewayFilter> filters = new ArrayList<>();
Objects.requireNonNull(routeDefinition.getId(), "Route id must be set");
// TODO: support option to apply defaults after route specific filters?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,41 @@ public void contextLoadsAndApplyRouteIdToRetryFilter() {
}).expectComplete().verify();
}

@Test
public void uriWithMappingShouldAddSetPathFilter() {
// 1. Setup
List<RoutePredicateFactory> predicates = Arrays.asList(new HostRoutePredicateFactory());
List<GatewayFilterFactory> gatewayFilterFactories = Arrays
.asList(new org.springframework.cloud.gateway.filter.factory.SetPathGatewayFilterFactory());

GatewayProperties gatewayProperties = new GatewayProperties();

// Standard way to create the definition
RouteDefinition definition = new RouteDefinition();
definition.setId("sugar_test");
definition.setUri(URI.create("https://example.com/foo/bar"));
definition.setPredicates(Arrays.asList(new PredicateDefinition("Host=*.example.com")));

gatewayProperties.setRoutes(Arrays.asList(definition));

PropertiesRouteDefinitionLocator routeDefinitionLocator = new PropertiesRouteDefinitionLocator(
gatewayProperties);

// 2. Initialize the Locator
RouteDefinitionRouteLocator routeDefinitionRouteLocator = new RouteDefinitionRouteLocator(
new CompositeRouteDefinitionLocator(Flux.just(routeDefinitionLocator)), predicates,
gatewayFilterFactories, gatewayProperties, new ConfigurationService(null, () -> null, () -> null));

// 3. Verify
StepVerifier.create(routeDefinitionRouteLocator.getRoutes()).assertNext(route -> {
assertThat(route.getUri().toString()).isEqualTo("https://example.com:443");

List<GatewayFilter> filters = route.getFilters();
assertThat(filters).hasSize(1);
assertThat(getFilterClassName(filters.get(0))).contains("SetPath");
}).expectComplete().verify();
}

private List<RouteDefinition> containsInvalidRoutes() {
RouteDefinition foo = new RouteDefinition();
foo.setId("foo");
Expand Down