Code Monkey home page Code Monkey logo

Comments (3)

spencergibb avatar spencergibb commented on May 18, 2024

This worked for me. Maybe a project that recreates the problem?

spring:
  cloud:
    gateway:
      default-filters:
      - name: AddResponseHeader
        args:
          name: X-Response-Default-Foo
          value: Default-Bar

from spring-cloud-gateway.

fitzoh avatar fitzoh commented on May 18, 2024

Yeah, did a little more testing and it looks like you're correct.
I had a breakpoint set on the getter, and the getter was only getting called before the new values had been added to the bean. So the initial issue isn't valid, but I do still have a question if you don't mind....

What got me started down this thread was being unable to figure out why default filters weren't being applied to things from a RouteLocator bean.

Given:

@EnableGateway
@SpringBootApplication
public class SampleApplication {

    public static void main(String[] args) {
        SpringApplication.run(SampleApplication.class, args);
    }

    @Bean
    public RouteLocator routes() {
        return Routes.locator()
                .route("the-service")
                .uri("http://httpbin.org:80")
                .predicate(x -> true)
                .and()
                .build();
    }

}
public class ShutdownWebFilterFactory implements WebFilterFactory {

    @Override
    public WebFilter apply(Tuple args) {
        return (exchange, chain) -> {
            System.out.println("in filter, shutting down");
            System.exit(1);
            throw new RuntimeException();
        };

    }
}
spring:
  cloud:
    gateway:
      defaultFilters:
       - name: Shutdown

Why is the filter not being applied on every request?
Am I misunderstanding the purpose of defaultFilters?

sample project here
https://github.com/Fitzoh/spring-gateway-question

from spring-cloud-gateway.

spencergibb avatar spencergibb commented on May 18, 2024

That is the purpose. ShutdownWebFilterFactory needs to be a bean.

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.