Skip to content
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

Unable to set default filters via configuration properties #48

Closed
fitzoh opened this issue Jul 9, 2017 · 3 comments
Closed

Unable to set default filters via configuration properties #48

fitzoh opened this issue Jul 9, 2017 · 3 comments
Labels

Comments

@fitzoh
Copy link
Contributor

fitzoh commented Jul 9, 2017

In M1 it does not appear to be possible to add a default filter via configuration properties.
Given the following configuration:

spring:
  cloud:
    gateway:
      default-filters:
       - name: filter1
       - name: filter2

with a breakpoint on GatewayProperties::getDefaultFilters I always end up with a single RemoveNonProxyHeadersWebFilterFactory filter which is added via GatewayProperties::loadDefaults.

I can verify that filter1 and filter2 are being created by setting breakpoints in the constructor.

@spencergibb
Copy link
Member

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

@fitzoh
Copy link
Contributor Author

fitzoh commented Jul 13, 2017

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

@spencergibb
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants