Comments (6)
Your finding are correct about the order. Let's use this to document that fact. Before and after functions are special cases of HandlerFilterFunction
, which has both before and after. So the more accurate execution is this
beforeFunction1 -> beforeFunction2 -> beforeFunction3 -> afterFunction1 (no op) -> afterFunction2 (no op) -> afterFunction3 (no op) ->
routeHandlerFunction ->
afterFunction3 -> afterFunction2 -> afterFunction1 -> beforeFunction3 (no op) -> beforeFunction2 (no op) -> beforeFunction1 (no op)
All the before parts are executed in the order defined, then all the afters are executed in the reverse order they are defined. The fact that you put the route()
call in between the calls to before()
and `after() has no bearing on the order.
from spring-cloud-gateway.
Thanks that helps. Would the after() functions still run if there is an exception that is handled by the onError() functions?
from spring-cloud-gateway.
I'm not positive. @poutsma could say with certainty.
from spring-cloud-gateway.
Looking at the code, onError()
is just a specialization of a handler filter function. Looking at the code it looks like they might still run. What is your experience? https://github.com/spring-projects/spring-framework/blob/8137cc95669690f3e4055d6ccf484e98a07b6703/spring-webmvc/src/main/java/org/springframework/web/servlet/function/HandlerFilterFunction.java#L106-L129
from spring-cloud-gateway.
I'm not seeing the after() functions run after an exception has been handled in my example above, not sure if that is because I defined the onError() handler outside the nested route. The exception happens to be thrown by one of the before() functions in my testing. I had to define the onError() handler outside the nested route otherwise any exceptions being thrown were not getting handled.
from spring-cloud-gateway.
Thanks that helps. Would the after() functions still run if there is an exception that is handled by the onError() functions?
As you already found out, they don't.
I'm not seeing the after() functions run after an exception has been handled in my example above, not sure if that is because I defined the onError() handler outside the nested route. The exception happens to be thrown by one of the before() functions in my testing. I had to define the onError() handler outside the nested route otherwise any exceptions being thrown were not getting handled.
Filters—such as those registered with before
, after
, and onError
—are scoped, and only apply to the routes in the same nesting.
from spring-cloud-gateway.
Related Issues (20)
- can anyone provide a spring-cloud-gateway-mvc sample? HOT 2
- LEAK: ByteBuf.release() error HOT 6
- The cache works differently if the value of local-response-cache.enabled is default false or explicitly false
- Load balance per route read timeout in spring-cloud-gateway-server-mvc HOT 1
- Ratelimiter not working with aws elasticache redis 7.1 HOT 10
- Gateway MVC ServerRequest body broken when created from another
- Required Gobalfilter type interface in Spring Cloud Gateway MVC, and instead of bean creation properties level routes configuration HOT 2
- direct memory always increases when adding custom filter to get request body size
- Spring Cloud Gateway not allowing Encoded URL paths after Update HOT 1
- Documentation Link on spring.io for 4.1.3 does not work.
- Unable to integrate grpc with spring cloud gateway HOT 4
- Can't have @PostRequest with formdata in spring-cloud-gateway-mvc application
- How can i intergrate central swagger for all microservices from gateway
- problem with URL encoding
- how to use JsonToGrpc GatewayFilter HOT 2
- Noticing leaks in release of byte buffers HOT 7
- Doesn't load p12
- Gateway MVC: space character in POSTed JSON leads to IOException: insufficient data written HOT 1
- Unbale to call writeWith(Publisher<? extends DataBuffer> body) method from a filter which extends AbstractGatewayFilterFactory
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-cloud-gateway.