Code Monkey home page Code Monkey logo

Comments (6)

spencergibb avatar spencergibb commented on June 2, 2024

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.

gatewaynovice avatar gatewaynovice commented on June 2, 2024

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.

spencergibb avatar spencergibb commented on June 2, 2024

I'm not positive. @poutsma could say with certainty.

from spring-cloud-gateway.

spencergibb avatar spencergibb commented on June 2, 2024

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.

gatewaynovice avatar gatewaynovice commented on June 2, 2024

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.

poutsma avatar poutsma commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.