I have a custom filter defined in my application.yml
. I need to take some more parameters from that filter definition in YAML, so that I can perform a logic inside my custom filter. I have multiple such routes defined wherein the filter parameters differs. The problem I am facing is, not able to read the values specified in YAML file.
application.yml ---
spring:
cloud:
gateway:
routes:
- id: test_route
uri: https://api.rangon.pi
predicates:
- Path=/api/staticdata/rattlefeed*
filters:
- AddRequestHeader=X-Y-Host, rangon
- TestGatewayFilter=admin, XY8382, basic
//Is there any way to get "admin, XY8382, basic" in my custom filter class
My filter class
@Component
public class TestGatewayFilter implements
GatewayFilterFactory<TestGatewayFilter.Config> {
@Override
public GatewayFilter apply(Config config) {
// grab configuration from Config object
return (exchange, chain) -> {
Route r = (Route) exchange.getAttributes().get(ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR);
Route route = exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR);
// ServerWebExchange route =
// exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR);
// List<GatewayFilter> list = r.getFilters();
GatewayFilter gwf = r.getFilters().get(r.getFilters().size() - 1);
Builder builder = exchange.getRequest().mutate();
// use builder to manipulate the request
return chain.filter(exchange.mutate().build());
};
}
public Config newConfig() {
Config c = new Config();
return c;
}
public static class Config {
// Put the configuration properties for your filter here
}
}