Skip to content

Composite / Stereotype Filters #3589

Open
@benmadore-glassdoor

Description

@benmadore-glassdoor

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions