Rename Route to RouteDefinition
This commit is contained in:
@@ -25,12 +25,12 @@ import java.util.Optional;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.cloud.gateway.model.Route;
|
||||
import org.springframework.cloud.gateway.api.RouteLocator;
|
||||
import org.springframework.cloud.gateway.api.RouteWriter;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.cloud.gateway.filter.factory.WebFilterFactory;
|
||||
import org.springframework.cloud.gateway.handler.FilteringWebHandler;
|
||||
import org.springframework.cloud.gateway.model.RouteDefinition;
|
||||
import org.springframework.cloud.gateway.support.NotFoundException;
|
||||
import org.springframework.cloud.gateway.support.RefreshRoutesEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
@@ -118,7 +118,7 @@ public class GatewayEndpoint implements ApplicationEventPublisherAware {/*extend
|
||||
}
|
||||
|
||||
@GetMapping("/routes")
|
||||
public Mono<List<Route>> routes() {
|
||||
public Mono<List<RouteDefinition>> routes() {
|
||||
return this.routeLocator.getRoutes().collectList();
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class GatewayEndpoint implements ApplicationEventPublisherAware {/*extend
|
||||
http POST :8080/admin/gateway/routes/apiaddreqhead uri=http://httpbin.org:80 predicates:='["Host=**.apiaddrequestheader.org", "Path=/headers"]' filters:='["AddRequestHeader=X-Request-ApiFoo, ApiBar"]'
|
||||
*/
|
||||
@PostMapping("/routes/{id}")
|
||||
public Mono<ResponseEntity<Void>> save(@PathVariable String id, @RequestBody Mono<Route> route) {
|
||||
public Mono<ResponseEntity<Void>> save(@PathVariable String id, @RequestBody Mono<RouteDefinition> route) {
|
||||
return this.routeWriter.save(route.map(r -> {
|
||||
r.setId(id);
|
||||
log.debug("Saving route: " + route);
|
||||
@@ -144,7 +144,7 @@ http POST :8080/admin/gateway/routes/apiaddreqhead uri=http://httpbin.org:80 pre
|
||||
}
|
||||
|
||||
@GetMapping("/routes/{id}")
|
||||
public Mono<ResponseEntity<Route>> route(@PathVariable String id) {
|
||||
public Mono<ResponseEntity<RouteDefinition>> route(@PathVariable String id) {
|
||||
return this.routeLocator.getRoutes()
|
||||
.filter(route -> route.getId().equals(id))
|
||||
.singleOrEmpty()
|
||||
@@ -154,10 +154,10 @@ http POST :8080/admin/gateway/routes/apiaddreqhead uri=http://httpbin.org:80 pre
|
||||
|
||||
@GetMapping("/routes/{id}/combinedfilters")
|
||||
public Map<String, Object> combinedfilters(@PathVariable String id) {
|
||||
Mono<Route> route = this.routeLocator.getRoutes()
|
||||
Mono<RouteDefinition> route = this.routeLocator.getRoutes()
|
||||
.filter(r -> r.getId().equals(id))
|
||||
.singleOrEmpty();
|
||||
Optional<Route> optional = Optional.ofNullable(route.block()); //TODO: remove block();
|
||||
Optional<RouteDefinition> optional = Optional.ofNullable(route.block()); //TODO: remove block();
|
||||
return getNamesToOrders(this.filteringWebHandler.combineFiltersForRoute(optional));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package org.springframework.cloud.gateway.api;
|
||||
|
||||
import org.springframework.cloud.gateway.model.Route;
|
||||
import org.springframework.cloud.gateway.model.RouteDefinition;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
/**
|
||||
@@ -25,5 +25,5 @@ import reactor.core.publisher.Flux;
|
||||
*/
|
||||
public interface RouteLocator {
|
||||
|
||||
Flux<Route> getRoutes();
|
||||
Flux<RouteDefinition> getRoutes();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package org.springframework.cloud.gateway.api;
|
||||
|
||||
import org.springframework.cloud.gateway.model.Route;
|
||||
import org.springframework.cloud.gateway.model.RouteDefinition;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
@@ -25,7 +25,7 @@ import reactor.core.publisher.Mono;
|
||||
*/
|
||||
public interface RouteWriter {
|
||||
|
||||
Mono<Void> save(Mono<Route> route);
|
||||
Mono<Void> save(Mono<RouteDefinition> route);
|
||||
|
||||
Mono<Void> delete(Mono<String> routeId);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.gateway.model.FilterDefinition;
|
||||
import org.springframework.cloud.gateway.model.Route;
|
||||
import org.springframework.cloud.gateway.model.RouteDefinition;
|
||||
import org.springframework.cloud.gateway.filter.factory.RemoveNonProxyHeadersWebFilterFactory;
|
||||
|
||||
import static org.springframework.cloud.gateway.support.NameUtils.normalizeFilterName;
|
||||
@@ -41,7 +41,7 @@ public class GatewayProperties {
|
||||
*/
|
||||
@NotNull
|
||||
@Valid
|
||||
private List<Route> routes = new ArrayList<>();
|
||||
private List<RouteDefinition> routes = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* List of filter definitions that are applied to every route.
|
||||
@@ -56,11 +56,11 @@ public class GatewayProperties {
|
||||
return defaults;
|
||||
}
|
||||
|
||||
public List<Route> getRoutes() {
|
||||
public List<RouteDefinition> getRoutes() {
|
||||
return routes;
|
||||
}
|
||||
|
||||
public void setRoutes(List<Route> routes) {
|
||||
public void setRoutes(List<RouteDefinition> routes) {
|
||||
this.routes = routes;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package org.springframework.cloud.gateway.config;
|
||||
|
||||
import org.springframework.cloud.gateway.model.Route;
|
||||
import org.springframework.cloud.gateway.model.RouteDefinition;
|
||||
import org.springframework.cloud.gateway.api.RouteLocator;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -34,7 +34,7 @@ public class PropertiesRouteLocator implements RouteLocator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Route> getRoutes() {
|
||||
public Flux<RouteDefinition> getRoutes() {
|
||||
return Flux.fromIterable(this.properties.getRoutes());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.cloud.gateway.filter.factory.RewritePathWebFilterFact
|
||||
import org.springframework.cloud.gateway.handler.predicate.PathRequestPredicateFactory;
|
||||
import org.springframework.cloud.gateway.model.FilterDefinition;
|
||||
import org.springframework.cloud.gateway.model.PredicateDefinition;
|
||||
import org.springframework.cloud.gateway.model.Route;
|
||||
import org.springframework.cloud.gateway.model.RouteDefinition;
|
||||
|
||||
import static org.springframework.cloud.gateway.filter.factory.RewritePathWebFilterFactory.REGEXP_KEY;
|
||||
import static org.springframework.cloud.gateway.filter.factory.RewritePathWebFilterFactory.REPLACEMENT_KEY;
|
||||
@@ -50,18 +50,18 @@ public class DiscoveryClientRouteLocator implements RouteLocator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Route> getRoutes() {
|
||||
public Flux<RouteDefinition> getRoutes() {
|
||||
return Flux.fromIterable(discoveryClient.getServices())
|
||||
.map(serviceId -> {
|
||||
Route route = new Route();
|
||||
route.setId(this.routeIdPrefix + serviceId);
|
||||
route.setUri(URI.create("lb://" + serviceId));
|
||||
RouteDefinition routeDefinition = new RouteDefinition();
|
||||
routeDefinition.setId(this.routeIdPrefix + serviceId);
|
||||
routeDefinition.setUri(URI.create("lb://" + serviceId));
|
||||
|
||||
// add a predicate that matches the url at /serviceId/**
|
||||
PredicateDefinition predicate = new PredicateDefinition();
|
||||
predicate.setName(normalizePredicateName(PathRequestPredicateFactory.class));
|
||||
predicate.addArg(PATTERN_KEY, "/" + serviceId + "/**");
|
||||
route.getPredicates().add(predicate);
|
||||
routeDefinition.getPredicates().add(predicate);
|
||||
|
||||
//TODO: support for other default predicates
|
||||
|
||||
@@ -72,11 +72,11 @@ public class DiscoveryClientRouteLocator implements RouteLocator {
|
||||
String replacement = "/${remaining}";
|
||||
filter.addArg(REGEXP_KEY, regex);
|
||||
filter.addArg(REPLACEMENT_KEY, replacement);
|
||||
route.getFilters().add(filter);
|
||||
routeDefinition.getFilters().add(filter);
|
||||
|
||||
//TODO: support for default filters
|
||||
|
||||
return route;
|
||||
return routeDefinition;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.net.URI;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.cloud.gateway.model.Route;
|
||||
import org.springframework.cloud.gateway.model.RouteDefinition;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebFilterChain;
|
||||
@@ -48,13 +48,13 @@ public class RouteToRequestUrlFilter implements GlobalFilter, Ordered {
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
Route route = getAttribute(exchange, GATEWAY_ROUTE_ATTR, Route.class);
|
||||
if (route == null) {
|
||||
RouteDefinition routeDefinition = getAttribute(exchange, GATEWAY_ROUTE_ATTR, RouteDefinition.class);
|
||||
if (routeDefinition == null) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
log.info("RouteToRequestUrlFilter start");
|
||||
URI requestUrl = UriComponentsBuilder.fromHttpRequest(exchange.getRequest())
|
||||
.uri(route.getUri())
|
||||
.uri(routeDefinition.getUri())
|
||||
.build(true)
|
||||
.toUri();
|
||||
exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, requestUrl);
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.cloud.gateway.filter.factory.WebFilterFactory;
|
||||
import org.springframework.cloud.gateway.model.FilterDefinition;
|
||||
import org.springframework.cloud.gateway.model.Route;
|
||||
import org.springframework.cloud.gateway.model.RouteDefinition;
|
||||
import org.springframework.cloud.gateway.config.GatewayProperties;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.cloud.gateway.support.NameUtils;
|
||||
@@ -102,7 +102,7 @@ public class FilteringWebHandler extends WebHandlerDecorator {
|
||||
|
||||
@Override
|
||||
public Mono<Void> handle(ServerWebExchange exchange) {
|
||||
Optional<Route> route = exchange.getAttribute(GATEWAY_ROUTE_ATTR);
|
||||
Optional<RouteDefinition> route = exchange.getAttribute(GATEWAY_ROUTE_ATTR);
|
||||
List<WebFilter> webFilters = combineFiltersForRoute(route);
|
||||
|
||||
logger.debug("Sorted webFilterFactories: "+ webFilters);
|
||||
@@ -110,7 +110,7 @@ public class FilteringWebHandler extends WebHandlerDecorator {
|
||||
return new DefaultWebFilterChain(webFilters, getDelegate()).filter(exchange);
|
||||
}
|
||||
|
||||
public List<WebFilter> combineFiltersForRoute(Optional<Route> route) {
|
||||
public List<WebFilter> combineFiltersForRoute(Optional<RouteDefinition> route) {
|
||||
if (!route.isPresent()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -157,7 +157,7 @@ public class FilteringWebHandler extends WebHandlerDecorator {
|
||||
}
|
||||
Map<String, String> args = definition.getArgs();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Route " + id + " applying filter " + args + " to " + definition.getName());
|
||||
logger.debug("RouteDefinition " + id + " applying filter " + args + " to " + definition.getName());
|
||||
}
|
||||
|
||||
//TODO: move Tuple building to common class, see RequestPredicateFactory.lookup
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.util.function.Function;
|
||||
import org.springframework.cloud.gateway.api.RouteLocator;
|
||||
import org.springframework.cloud.gateway.handler.predicate.RequestPredicateFactory;
|
||||
import org.springframework.cloud.gateway.model.PredicateDefinition;
|
||||
import org.springframework.cloud.gateway.model.Route;
|
||||
import org.springframework.cloud.gateway.model.RouteDefinition;
|
||||
import org.springframework.cloud.gateway.support.NameUtils;
|
||||
import org.springframework.tuple.Tuple;
|
||||
import org.springframework.tuple.TupleBuilder;
|
||||
@@ -79,7 +79,7 @@ public class RequestPredicateHandlerMapping extends AbstractHandlerMapping {
|
||||
|
||||
return lookupRoute(exchange)
|
||||
.log("TRACE")
|
||||
.then((Function<Route, Mono<?>>) r -> {
|
||||
.then((Function<RouteDefinition, Mono<?>>) r -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Mapping [" + getExchangeDesc(exchange) + "] to " + r);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class RequestPredicateHandlerMapping extends AbstractHandlerMapping {
|
||||
return Mono.just(webHandler);
|
||||
}).otherwiseIfEmpty(Mono.empty().then(() -> {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("No Route found for [" + getExchangeDesc(exchange) + "]");
|
||||
logger.trace("No RouteDefinition found for [" + getExchangeDesc(exchange) + "]");
|
||||
}
|
||||
return Mono.empty();
|
||||
}));
|
||||
@@ -105,7 +105,7 @@ public class RequestPredicateHandlerMapping extends AbstractHandlerMapping {
|
||||
}
|
||||
|
||||
|
||||
protected Mono<Route> lookupRoute(ServerWebExchange exchange) {
|
||||
protected Mono<RouteDefinition> lookupRoute(ServerWebExchange exchange) {
|
||||
return this.routeLocator.getRoutes()
|
||||
.map(this::getRouteCombinedPredicates)
|
||||
.filter(rcp -> rcp.combinedPredicate.test(new ExchangeServerRequest(exchange)))
|
||||
@@ -113,41 +113,41 @@ public class RequestPredicateHandlerMapping extends AbstractHandlerMapping {
|
||||
//TODO: error handling
|
||||
.map(rcp -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Route matched: " + rcp.route.getId());
|
||||
logger.debug("RouteDefinition matched: " + rcp.routeDefinition.getId());
|
||||
}
|
||||
validateRoute(rcp.route, exchange);
|
||||
return rcp.route;
|
||||
validateRoute(rcp.routeDefinition, exchange);
|
||||
return rcp.routeDefinition;
|
||||
});
|
||||
|
||||
/* TODO: trace logging
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Route did not match: " + route.getId());
|
||||
logger.trace("RouteDefinition did not match: " + routeDefinition.getId());
|
||||
}*/
|
||||
}
|
||||
|
||||
private RouteCombinedPredicates getRouteCombinedPredicates(Route route) {
|
||||
private RouteCombinedPredicates getRouteCombinedPredicates(RouteDefinition routeDefinition) {
|
||||
RequestPredicate predicate = this.combinedPredicates
|
||||
.computeIfAbsent(route.getId(), k -> combinePredicates(route));
|
||||
.computeIfAbsent(routeDefinition.getId(), k -> combinePredicates(routeDefinition));
|
||||
|
||||
return new RouteCombinedPredicates(route, predicate);
|
||||
return new RouteCombinedPredicates(routeDefinition, predicate);
|
||||
}
|
||||
|
||||
private class RouteCombinedPredicates {
|
||||
private Route route;
|
||||
private RouteDefinition routeDefinition;
|
||||
private RequestPredicate combinedPredicate;
|
||||
|
||||
public RouteCombinedPredicates(Route route, RequestPredicate combinedPredicate) {
|
||||
this.route = route;
|
||||
public RouteCombinedPredicates(RouteDefinition routeDefinition, RequestPredicate combinedPredicate) {
|
||||
this.routeDefinition = routeDefinition;
|
||||
this.combinedPredicate = combinedPredicate;
|
||||
}
|
||||
}
|
||||
|
||||
private RequestPredicate combinePredicates(Route route) {
|
||||
List<PredicateDefinition> predicates = route.getPredicates();
|
||||
RequestPredicate predicate = lookup(route, predicates.get(0));
|
||||
private RequestPredicate combinePredicates(RouteDefinition routeDefinition) {
|
||||
List<PredicateDefinition> predicates = routeDefinition.getPredicates();
|
||||
RequestPredicate predicate = lookup(routeDefinition, predicates.get(0));
|
||||
|
||||
for (PredicateDefinition andPredicate : predicates.subList(1, predicates.size())) {
|
||||
RequestPredicate found = lookup(route, andPredicate);
|
||||
RequestPredicate found = lookup(routeDefinition, andPredicate);
|
||||
predicate = predicate.and(found);
|
||||
}
|
||||
|
||||
@@ -155,14 +155,14 @@ public class RequestPredicateHandlerMapping extends AbstractHandlerMapping {
|
||||
}
|
||||
|
||||
//TODO: decouple from HandlerMapping?
|
||||
private RequestPredicate lookup(Route route, PredicateDefinition predicate) {
|
||||
private RequestPredicate lookup(RouteDefinition routeDefinition, PredicateDefinition predicate) {
|
||||
RequestPredicateFactory found = this.requestPredicates.get(predicate.getName());
|
||||
if (found == null) {
|
||||
throw new IllegalArgumentException("Unable to find RequestPredicateFactory with name " + predicate.getName());
|
||||
}
|
||||
Map<String, String> args = predicate.getArgs();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Route " + route.getId() + " applying "
|
||||
logger.debug("RouteDefinition " + routeDefinition.getId() + " applying "
|
||||
+ args + " to " + predicate.getName());
|
||||
}
|
||||
|
||||
@@ -211,12 +211,12 @@ public class RequestPredicateHandlerMapping extends AbstractHandlerMapping {
|
||||
* Validate the given handler against the current request.
|
||||
* <p>The default implementation is empty. Can be overridden in subclasses,
|
||||
* for example to enforce specific preconditions expressed in URL mappings.
|
||||
* @param route the Route object to validate
|
||||
* @param routeDefinition the RouteDefinition object to validate
|
||||
* @param exchange current exchange
|
||||
* @throws Exception if validation failed
|
||||
*/
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
protected void validateRoute(Route route, ServerWebExchange exchange) {
|
||||
protected void validateRoute(RouteDefinition routeDefinition, ServerWebExchange exchange) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import static org.springframework.util.StringUtils.tokenizeToStringArray;
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class Route {
|
||||
public class RouteDefinition {
|
||||
@NotEmpty
|
||||
private String id = UUID.randomUUID().toString();
|
||||
|
||||
@@ -47,12 +47,12 @@ public class Route {
|
||||
@NotNull
|
||||
private URI uri;
|
||||
|
||||
public Route() {}
|
||||
public RouteDefinition() {}
|
||||
|
||||
public Route(String text) {
|
||||
public RouteDefinition(String text) {
|
||||
int eqIdx = text.indexOf("=");
|
||||
if (eqIdx <= 0) {
|
||||
throw new ValidationException("Unable to parse Route text '" + text + "'" +
|
||||
throw new ValidationException("Unable to parse RouteDefinition text '" + text + "'" +
|
||||
", must be of the form name=value");
|
||||
}
|
||||
|
||||
@@ -103,10 +103,10 @@ public class Route {
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Route route = (Route) o;
|
||||
return Objects.equals(id, route.id) &&
|
||||
Objects.equals(predicates, route.predicates) &&
|
||||
Objects.equals(uri, route.uri);
|
||||
RouteDefinition routeDefinition = (RouteDefinition) o;
|
||||
return Objects.equals(id, routeDefinition.id) &&
|
||||
Objects.equals(predicates, routeDefinition.predicates) &&
|
||||
Objects.equals(uri, routeDefinition.uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,7 +116,7 @@ public class Route {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Route{" +
|
||||
return "RouteDefinition{" +
|
||||
"id='" + id + '\'' +
|
||||
", predicates=" + predicates +
|
||||
", filters=" + filters +
|
||||
@@ -20,7 +20,7 @@ package org.springframework.cloud.gateway.support;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.springframework.cloud.gateway.model.Route;
|
||||
import org.springframework.cloud.gateway.model.RouteDefinition;
|
||||
import org.springframework.cloud.gateway.api.RouteLocator;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -31,7 +31,7 @@ import reactor.core.publisher.Flux;
|
||||
public class CachingRouteLocator implements RouteLocator {
|
||||
|
||||
private final RouteLocator delegate;
|
||||
private final AtomicReference<List<Route>> cachedRoutes = new AtomicReference<>();
|
||||
private final AtomicReference<List<RouteDefinition>> cachedRoutes = new AtomicReference<>();
|
||||
|
||||
public CachingRouteLocator(RouteLocator delegate) {
|
||||
this.delegate = delegate;
|
||||
@@ -39,7 +39,7 @@ public class CachingRouteLocator implements RouteLocator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Route> getRoutes() {
|
||||
public Flux<RouteDefinition> getRoutes() {
|
||||
return Flux.fromIterable(this.cachedRoutes.get());
|
||||
}
|
||||
|
||||
@@ -47,12 +47,12 @@ public class CachingRouteLocator implements RouteLocator {
|
||||
* Sets the new routes
|
||||
* @return old routes
|
||||
*/
|
||||
public Flux<Route> refresh() {
|
||||
public Flux<RouteDefinition> refresh() {
|
||||
return Flux.fromIterable(this.cachedRoutes.getAndUpdate(
|
||||
routes -> CachingRouteLocator.this.collectRoutes()));
|
||||
}
|
||||
|
||||
private List<Route> collectRoutes() {
|
||||
private List<RouteDefinition> collectRoutes() {
|
||||
return this.delegate.getRoutes().collectList().block();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package org.springframework.cloud.gateway.support;
|
||||
|
||||
import org.springframework.cloud.gateway.model.Route;
|
||||
import org.springframework.cloud.gateway.model.RouteDefinition;
|
||||
import org.springframework.cloud.gateway.api.RouteLocator;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class CompositeRouteLocator implements RouteLocator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Route> getRoutes() {
|
||||
public Flux<RouteDefinition> getRoutes() {
|
||||
return this.delegates.flatMap(RouteLocator::getRoutes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ package org.springframework.cloud.gateway.support;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.cloud.gateway.model.Route;
|
||||
import org.springframework.cloud.gateway.model.RouteDefinition;
|
||||
import org.springframework.cloud.gateway.api.RouteLocator;
|
||||
import org.springframework.cloud.gateway.api.RouteWriter;
|
||||
|
||||
@@ -34,10 +34,10 @@ import reactor.core.publisher.Mono;
|
||||
*/
|
||||
public class InMemoryRouteRepository implements RouteLocator, RouteWriter {
|
||||
|
||||
private final Map<String, Route> routes = synchronizedMap(new LinkedHashMap<String, Route>());
|
||||
private final Map<String, RouteDefinition> routes = synchronizedMap(new LinkedHashMap<String, RouteDefinition>());
|
||||
|
||||
@Override
|
||||
public Mono<Void> save(Mono<Route> route) {
|
||||
public Mono<Void> save(Mono<RouteDefinition> route) {
|
||||
return route.then( r -> {
|
||||
routes.put(r.getId(), r);
|
||||
return Mono.empty();
|
||||
@@ -51,12 +51,12 @@ public class InMemoryRouteRepository implements RouteLocator, RouteWriter {
|
||||
routes.remove(id);
|
||||
return Mono.empty();
|
||||
}
|
||||
return Mono.error(new NotFoundException("Route not found: "+routeId));
|
||||
return Mono.error(new NotFoundException("RouteDefinition not found: "+routeId));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Route> getRoutes() {
|
||||
public Flux<RouteDefinition> getRoutes() {
|
||||
return Flux.fromIterable(routes.values());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.junit.Before;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.cloud.gateway.EnableGateway;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.cloud.gateway.model.Route;
|
||||
import org.springframework.cloud.gateway.model.RouteDefinition;
|
||||
import org.springframework.cloud.netflix.ribbon.RibbonClient;
|
||||
import org.springframework.cloud.netflix.ribbon.RibbonClients;
|
||||
import org.springframework.cloud.netflix.ribbon.StaticServerList;
|
||||
@@ -58,7 +58,7 @@ import reactor.core.publisher.Mono;
|
||||
public class BaseWebClientTests {
|
||||
|
||||
protected static final String HANDLER_MAPPER_HEADER = "X-Gateway-Handler-Mapper-Class";
|
||||
protected static final String ROUTE_ID_HEADER = "X-Gateway-Route-Id";
|
||||
protected static final String ROUTE_ID_HEADER = "X-Gateway-RouteDefinition-Id";
|
||||
protected static final Duration DURATION = Duration.ofSeconds(5);
|
||||
|
||||
@LocalServerPort
|
||||
@@ -163,9 +163,9 @@ public class BaseWebClientTests {
|
||||
log.info("modifyResponseFilter start");
|
||||
String value = (String) exchange.getAttribute(GATEWAY_HANDLER_MAPPER_ATTR).orElse("N/A");
|
||||
exchange.getResponse().getHeaders().add(HANDLER_MAPPER_HEADER, value);
|
||||
Route route = (Route) exchange.getAttribute(GATEWAY_ROUTE_ATTR).orElse(null);
|
||||
if (route != null) {
|
||||
exchange.getResponse().getHeaders().add(ROUTE_ID_HEADER, route.getId());
|
||||
RouteDefinition routeDefinition = (RouteDefinition) exchange.getAttribute(GATEWAY_ROUTE_ATTR).orElse(null);
|
||||
if (routeDefinition != null) {
|
||||
exchange.getResponse().getHeaders().add(ROUTE_ID_HEADER, routeDefinition.getId());
|
||||
}
|
||||
return chain.filter(exchange);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user