use of org.springframework.cloud.gateway.filter.OrderedGatewayFilter in project spring-cloud-gateway by spring-cloud.
the class RouteDefinitionRouteLocator method loadGatewayFilters.
@SuppressWarnings("unchecked")
private List<GatewayFilter> loadGatewayFilters(String id, List<FilterDefinition> filterDefinitions) {
List<GatewayFilter> filters = filterDefinitions.stream().map(definition -> {
GatewayFilterFactory factory = this.gatewayFilterFactories.get(definition.getName());
if (factory == null) {
throw new IllegalArgumentException("Unable to find GatewayFilterFactory with name " + definition.getName());
}
Map<String, String> args = definition.getArgs();
if (logger.isDebugEnabled()) {
logger.debug("RouteDefinition " + id + " applying filter " + args + " to " + definition.getName());
}
if (factory.isConfigurable()) {
Map<String, Object> properties = factory.shortcutType().normalize(args, factory, this.parser, this.beanFactory);
Object configuration = factory.newConfig();
ConfigurationUtils.bind(configuration, properties, factory.shortcutFieldPrefix(), definition.getName(), validator);
GatewayFilter gatewayFilter = factory.apply(configuration);
if (this.publisher != null) {
this.publisher.publishEvent(new FilterArgsEvent(this, id, properties));
}
return gatewayFilter;
} else {
Tuple tuple = getTuple(factory, args, this.parser, this.beanFactory);
return factory.apply(tuple);
}
}).collect(Collectors.toList());
ArrayList<GatewayFilter> ordered = new ArrayList<>(filters.size());
for (int i = 0; i < filters.size(); i++) {
ordered.add(new OrderedGatewayFilter(filters.get(i), i + 1));
}
return ordered;
}
use of org.springframework.cloud.gateway.filter.OrderedGatewayFilter in project spring-cloud-gateway by spring-cloud.
the class GatewayFilterSpec method filter.
public GatewayFilterSpec filter(GatewayFilter gatewayFilter, int order) {
if (gatewayFilter instanceof Ordered) {
this.routeBuilder.filter(gatewayFilter);
log.warn("GatewayFilter already implements ordered " + gatewayFilter.getClass() + "ignoring order parameter: " + order);
return this;
}
this.routeBuilder.filter(new OrderedGatewayFilter(gatewayFilter, order));
return this;
}
Aggregations