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)
- ForwardRoutingFilter does not set GATEWAY_ORIGINAL_REQUEST_URL_ATTR attr
- Invalid IPv6 forwarded for header when ForwardedHeadersFilter uses unresolved address HOT 1
- How to Validate a Specific Value in the Request Body of a POST Request in Spring Cloud Gateway MVC?
- Response body is not coming in SCG
- Bug Report: 500 Internal Server Error with Spring Cloud Gateway
- Not able to access service URL HOT 2
- Provide a way to customize via Spring framework a TTL for Netty's DNS cache HOT 2
- Provide some documentation for how to implement a user specific rate limiter, with Spring Session (Redis)
- Spring cloud gateway ServerHttpResponseDecorator writeWith not called on receiving response
- GatewayRouterFunctions throwing for path variable with space throwing 400 bad request error HOT 3
- JKS with null password for mTLS 'silently' fails
- Content-Type 'application/x-www-form-urlencoded;charset=UTF-8' is not supported
- Better docs about naming convention in PredicateDefinition: Path receives pattern key and it works?
- RFE: Use ObjectMapper to convert name/args to Config object
- Http client Type of JDK gives "empty headers are not allowed"
- [Spring Cloud Gateway MVC] Multipart data missing
- [Spring Cloud Gateway MVC] route vs controller precedence
- Spring cloud gateway error SSL/TLS when enable http2 + ssl together
- [Spring Cloud Gateway MVC] Filters are not run when doing internal forwarding
- Routes unable redirect HOT 1
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.