-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global filters for MVC Gateway #3239
Comments
Hello @NiiazKhan, thank you for your answer. |
@Andross96 I am monitoring these issues: |
I'm not sure mvc gateway requires a separate implementation of filters besides what mvc.fn provides or just a servlet filter |
We actually have no "proper" way to create filter on matched gateway routes configured inside application.yml, respecting the configured predicates. Let's take a simple example: spring:
cloud:
gateway:
mvc:
routes:
- id: backend
uri: http://localhost:8080
predicates:
- Path=/api/**
# possibily multiple/variable predicates per route Using the actual mvc.fn or servlet filter, we have to recreate the entire RouterFunction based on the configuration file, so we have to get the properties of the routes (to set the backend url), and the harsh part is to "translate" all predicates entered (like GatewayMvcPropertiesBeanDefinitionRegistrar#getRouterFunction) because we need the predicates to be validated first before executing our filter. Are we missing something ? |
So you want filters that only run for gateway matched routes. What about #3177 default filters for mvc gateway? |
Yes exactly, but there is a main difference which make the default filter still not as suitable as global filters unfortunately : with default filter, you have to write manually the filters in your application properties (sometimes multiple,complexes..), while global filters are executed by default for every matched routes, without worrying about additional application properties configuration. It's a bit sad that migrating from reactive gateway to MVC isn't feasible while preserving identical behaviors. Both versions should ideally offer comparable features, ensuring consistency and compatibility across applications stack. |
This is never going to be possible to have identical behavior, similar yes, identical never. So, to create a global filter you have to create a bean, why can't default filters be added with a bean? |
That could do the trick ! But I do not see how to add default filter with a bean ? |
gateway mvc doesn't support default filters at all yet, so both config and bean configuration would be supported. That documentation if for the reactive gateway. |
Closing in favor of #3177 |
Question
Using the reactive (webflux) Spring Cloud Gateway, we had a GlobalFilter which allowed to filter on matching configured route only.
What is the equivalent in MVC ?
According to the documentation and another related issues (#3143), we have now to use Spring WebMvc.fn.
But we can not find a way using WebMvc.fn to simply filter on an already existing configured route only: we have to recreate an entire RouterFunction, translate predicates from application properties, etc.
For a better code comprehension, we are simply trying to translate our previous webflux GlobalFilter to make it work on MVC gateway:
The text was updated successfully, but these errors were encountered: