spring-cloud / spring-cloud/spring-cloud-gateway
Composite / Stereotype Filters
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.9k
- Forks
- 3.5k
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 8
Description
Let's say I have a different types of routes in my application, routes of Type A and Type B.
And my application has filters: Filter1, Filter2 ... Filter10
For Type A routes I want to always apply Filters 1,2,3,4,5 and for Type B routes I always want to apply Filters 6,7,8.
Filter9 and Filter10 may by applied to either type of route.
Rather than having to copy/paste and specify each of the individual filters on every single route in my application, I'd love some mechanism to create Composite sets of filters that should be applied.
So for a route of Type A instead of:
- filters:
- Filter1
- Filter2
- Filter3
- Filter4
- Filter5
- Filter10
...
I could write something like:
-filters:
- TypeA
- Filter10
...
I attempted to do this via creating an TypeAGatewayFilterFactory that simply invokes 1,2,3,4,5 in turn, but this is not ideal as it doesn't respect the global ordering of the OrderedFilters the filters will always be applied immediately after the ordering of the TypeA OrderedFilter in the specific sequence they're applied.
I also attempted to use a yaml anchor reference e.g.
type-a-filters: &type-a-filters
- Filter1
- Filter2
- Filter3
...
- filters
- Filter10
- *common-filters
But i got a errors like:
Binding to target [Bindable@1e8add86 type = java.util.List<org.springframework.cloud.gateway.filter.FilterDefinition>, value = 'provided', annotations = array<Annotation>[@jakarta.validation.Valid()], bindMethod = [null]] failed:
Property: spring.cloud.gateway.routes[0].filters[1][0]
Value: "Filter1"
Origin: "spring.cloud.gateway.routes[0].filters[1][0]" from property source "bootstrapProperties-devConfigTest/gateway-app/"
Reason: The elements [spring.cloud.gateway.routes[0].filters[1][0],spring.cloud.gateway.routes[0].filters[1][1],spring.cloud.gateway.routes[0].filters[1][2]] were left unbound.
Property: spring.cloud.gateway.routes[0].filters[1][1]
Value: "Filter2"
Origin: "spring.cloud.gateway.routes[0].filters[1][1]" from property source "bootstrapProperties-devConfigTest/gateway-app/"
Reason: The elements [spring.cloud.gateway.routes[0].filters[1][0],spring.cloud.gateway.routes[0].filters[1][1],spring.cloud.gateway.routes[0].filters[1][2]] were left unbound.
Property: spring.cloud.gateway.routes[0].filters[1][2]
Value: "Filter3"
Origin: "spring.cloud.gateway.routes[0].filters[1][2]" from property source "bootstrapProperties-devConfigTest/gateway-app/"
Reason: The elements [spring.cloud.gateway.routes[0].filters[1][0],spring.cloud.gateway.routes[0].filters[1][1],spring.cloud.gateway.routes[0].filters[1][2]] were left unbound.
Is there any alternate mechanism I should be considering to enable these types of Composite Filters?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the Spring Cloud Gateway route filter configuration described in the issue, including FilterDefinition, gateway filter factories, and OrderedFilter behavior. Determine whether composite filters can preserve global ordering and define what configuration and ordering behavior would demonstrate completion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, spring-boot
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100