From e07801b0984daad9191109f93335573893b7d425 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Fri, 20 Jan 2017 20:56:36 -0700 Subject: [PATCH] More actuator endpoints --- .../gateway/actuate/GatewayEndpoint.java | 46 ++++++++++++++----- .../config/GatewayAutoConfiguration.java | 4 +- 2 files changed, 37 insertions(+), 13 deletions(-) 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 d140ce8d..bea55e93 100644 --- a/src/main/java/org/springframework/cloud/gateway/actuate/GatewayEndpoint.java +++ b/src/main/java/org/springframework/cloud/gateway/actuate/GatewayEndpoint.java @@ -1,10 +1,15 @@ package org.springframework.cloud.gateway.actuate; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.springframework.cloud.gateway.api.RouteReader; import org.springframework.cloud.gateway.config.Route; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.core.Ordered; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -15,29 +20,48 @@ import org.springframework.web.bind.annotation.RestController; //@ConfigurationProperties(prefix = "endpoints.gateway") @RestController @RequestMapping("/admin/gateway") -public class GatewayEndpoint { - private RouteReader routeReader;/*extends AbstractEndpoint> {*/ +public class GatewayEndpoint {/*extends AbstractEndpoint> {*/ - public GatewayEndpoint(RouteReader routeReader) { + private RouteReader routeReader; + private List globalFilters; + + public GatewayEndpoint(RouteReader routeReader, List globalFilters) { //super("gateway"); this.routeReader = routeReader; + this.globalFilters = globalFilters; } /*@Override public Map invoke() { - HashMap map = new HashMap<>(); - ArrayList filterNames = new ArrayList<>(); - for (GlobalFilter filter : this.filters) { - filterNames.add(filter.getClass().getName()); - } - map.put("filters", filterNames); - - return map; }*/ + @GetMapping("/globalfilters") + public Map globalfilters() { + HashMap filters = new HashMap<>(); + + for (GlobalFilter filter : this.globalFilters) { + Integer order = null; + if (filter instanceof Ordered) { + order = ((Ordered)filter).getOrder(); + } + filters.put(filter.getClass().getName(), order); + } + + return filters; + } + @GetMapping("/routes") public List routes() { return this.routeReader.getRoutes(); } + + @GetMapping("/routes/{id}") + public Route routes(@PathVariable String id) { + return this.routeReader.getRoutes().stream() + .filter(route -> route.getId().equals(id)) + .findFirst().get(); + } + + //TODO: add combined routes for a filter } 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 d14c4334..f660fbb3 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,8 @@ public class GatewayAutoConfiguration { protected static class GatewayActuatorConfiguration { @Bean - public GatewayEndpoint gatewayEndpoint(RouteReader routeReader) { - return new GatewayEndpoint(routeReader); + public GatewayEndpoint gatewayEndpoint(RouteReader routeReader, List globalFilters) { + return new GatewayEndpoint(routeReader, globalFilters); } }