More actuator endpoints
This commit is contained in:
@@ -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<Map<String, Object>> {*/
|
||||
public class GatewayEndpoint {/*extends AbstractEndpoint<Map<String, Object>> {*/
|
||||
|
||||
public GatewayEndpoint(RouteReader routeReader) {
|
||||
private RouteReader routeReader;
|
||||
private List<GlobalFilter> globalFilters;
|
||||
|
||||
public GatewayEndpoint(RouteReader routeReader, List<GlobalFilter> globalFilters) {
|
||||
//super("gateway");
|
||||
this.routeReader = routeReader;
|
||||
this.globalFilters = globalFilters;
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public Map<String, Object> invoke() {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
|
||||
ArrayList<String> filterNames = new ArrayList<>();
|
||||
for (GlobalFilter filter : this.filters) {
|
||||
filterNames.add(filter.getClass().getName());
|
||||
}
|
||||
map.put("filters", filterNames);
|
||||
|
||||
return map;
|
||||
}*/
|
||||
|
||||
@GetMapping("/globalfilters")
|
||||
public Map<String, Object> globalfilters() {
|
||||
HashMap<String, Object> 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<Route> 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
|
||||
}
|
||||
|
||||
@@ -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<GlobalFilter> globalFilters) {
|
||||
return new GatewayEndpoint(routeReader, globalFilters);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user