Skip to content

Add syntactic sugar for URI paths (gh-3293)#4135

Open
Arnav05-cyber wants to merge 2 commits intospring-cloud:mainfrom
Arnav05-cyber:feature/gh-3293-uri-path-sugar
Open

Add syntactic sugar for URI paths (gh-3293)#4135
Arnav05-cyber wants to merge 2 commits intospring-cloud:mainfrom
Arnav05-cyber:feature/gh-3293-uri-path-sugar

Conversation

@Arnav05-cyber
Copy link
Copy Markdown

Description

This Pull Request addresses issue #3293 by adding "syntactic sugar" for RouteDefinition URIs that contain a path component.

Currently, if a user specifies a path in the URI (e.g., uri: https://example.com/foo/bar), the Gateway does not automatically handle the path mapping, often requiring an explicit SetPath filter to avoid routing errors or double-pathing.

Changes introduced in this PR:

  1. Automatic Path Detection: The RouteDefinitionRouteLocator now checks if the provided URI has a non-root path.
  2. Filter Injection: If a path is detected and no SetPath filter is manually defined, a SetPath filter is automatically added to the beginning of the filter chain.
  3. URI Normalization: The path component is stripped from the base URI after the filter is added to prevent "double-routing" (sending the path twice to the downstream service).

Testing

Added a new unit test uriWithMappingShouldAddSetPathFilter in RouteDefinitionRouteLocatorTests.java to verify:

  • The SetPath filter is correctly injected with the URI's path.
  • The Route URI is correctly stripped of its path component.
  • The logic respects existing SetPath filters and does not duplicate them.

Signed-off-by: Arnav arnav.vyas06@gmail.com

Signed-off-by: Arnav <arnav.vyas06@gmail.com>
Copy link
Copy Markdown
Member

@spencergibb spencergibb left a comment

Choose a reason for hiding this comment

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

I'll have to think about this, since RouteDefinitionRouteLocator is only one implementation of RouteLocator. Ideally this would work with any implementation.

@@ -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

Signed-off-by: Arnav <arnav.vyas06@gmail.com>
@Arnav05-cyber Arnav05-cyber force-pushed the feature/gh-3293-uri-path-sugar branch from ccc0bbc to bb9e5f1 Compare April 3, 2026 15:02
@Arnav05-cyber
Copy link
Copy Markdown
Author

Thanks for the feedback, @spencergibb

I have reverted the changes to .settings.xml and fixed the DCO sign-off on that commit.

Regarding the implementation: I see your point. By putting this in RouteDefinitionRouteLocator, it only benefits users defining routes via properties/YAML.

Proposed Plan: I’m planning to move the path-detection and 'sugar' logic into the Route.Builder (specifically within the uri(URI uri) method). This would ensure that whether a route is created via the Java DSL, Discovery Client, or RouteDefinition, the path is correctly identified and a SetPath filter is added if missing.

Please advise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants