diff --git a/src/main/java/org/springframework/cloud/gateway/actuate/GatewayEndpoint.java b/src/main/java/org/springframework/cloud/gateway/actuate/GatewayEndpoint.java index bea55e938..5d1295cae 100644 --- a/src/main/java/org/springframework/cloud/gateway/actuate/GatewayEndpoint.java +++ b/src/main/java/org/springframework/cloud/gateway/actuate/GatewayEndpoint.java @@ -3,10 +3,13 @@ package org.springframework.cloud.gateway.actuate; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import org.springframework.cloud.gateway.api.RouteReader; import org.springframework.cloud.gateway.config.Route; import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.cloud.gateway.filter.route.RouteFilter; +import org.springframework.cloud.gateway.handler.FilteringWebHandler; import org.springframework.core.Ordered; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -24,11 +27,16 @@ public class GatewayEndpoint {/*extends AbstractEndpoint> {* private RouteReader routeReader; private List globalFilters; + private List routeFilters; + private FilteringWebHandler filteringWebHandler; - public GatewayEndpoint(RouteReader routeReader, List globalFilters) { + public GatewayEndpoint(RouteReader routeReader, List globalFilters, + List routeFilters, FilteringWebHandler filteringWebHandler) { //super("gateway"); this.routeReader = routeReader; this.globalFilters = globalFilters; + this.routeFilters = routeFilters; + this.filteringWebHandler = filteringWebHandler; } /*@Override @@ -38,14 +46,24 @@ public class GatewayEndpoint {/*extends AbstractEndpoint> {* @GetMapping("/globalfilters") public Map globalfilters() { + return getNamesToOrders(this.globalFilters); + } + + @GetMapping("/routefilters") + public Map routefilers() { + return getNamesToOrders(this.routeFilters); + } + + private Map getNamesToOrders(List list) { HashMap filters = new HashMap<>(); - for (GlobalFilter filter : this.globalFilters) { + for (Object o : list) { Integer order = null; - if (filter instanceof Ordered) { - order = ((Ordered)filter).getOrder(); + if (o instanceof Ordered) { + order = ((Ordered)o).getOrder(); } - filters.put(filter.getClass().getName(), order); + //filters.put(o.getClass().getName(), order); + filters.put(o.toString(), order); } return filters; @@ -57,11 +75,17 @@ public class GatewayEndpoint {/*extends AbstractEndpoint> {* } @GetMapping("/routes/{id}") - public Route routes(@PathVariable String id) { + public Route route(@PathVariable String id) { return this.routeReader.getRoutes().stream() .filter(route -> route.getId().equals(id)) .findFirst().get(); } - //TODO: add combined routes for a filter + @GetMapping("/routes/{id}/combinedfilters") + public Map combinedfilters(@PathVariable String id) { + final Optional route = this.routeReader.getRoutes().stream() + .filter(r -> r.getId().equals(id)) + .findFirst(); + return getNamesToOrders(this.filteringWebHandler.combineFiltersForRoute(route)); + } } diff --git a/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java b/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java index f660fbb3a..d8bbc667f 100644 --- a/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java +++ b/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java @@ -229,8 +229,9 @@ public class GatewayAutoConfiguration { protected static class GatewayActuatorConfiguration { @Bean - public GatewayEndpoint gatewayEndpoint(RouteReader routeReader, List globalFilters) { - return new GatewayEndpoint(routeReader, globalFilters); + public GatewayEndpoint gatewayEndpoint(RouteReader routeReader, List globalFilters, + List routeFilters, FilteringWebHandler filteringWebHandler) { + return new GatewayEndpoint(routeReader, globalFilters, routeFilters, filteringWebHandler); } }