Browse Source

rename DefaultRouteLocator to RouteDefinitionRouteLocator

pull/41/head
Spencer Gibb 8 years ago
parent
commit
e9e1af8a91
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 20
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java
  2. 20
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/RouteDefinitionRouteLocator.java

20
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java

@ -20,9 +20,11 @@ package org.springframework.cloud.gateway.config;
import java.util.List; import java.util.List;
import org.springframework.boot.actuate.endpoint.Endpoint; import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.gateway.actuate.GatewayEndpoint; import org.springframework.cloud.gateway.actuate.GatewayEndpoint;
@ -65,7 +67,7 @@ import org.springframework.cloud.gateway.handler.predicate.QueryRequestPredicate
import org.springframework.cloud.gateway.handler.predicate.RemoteAddrRequestPredicateFactory; import org.springframework.cloud.gateway.handler.predicate.RemoteAddrRequestPredicateFactory;
import org.springframework.cloud.gateway.handler.predicate.RequestPredicateFactory; import org.springframework.cloud.gateway.handler.predicate.RequestPredicateFactory;
import org.springframework.cloud.gateway.support.CachingRouteLocator; import org.springframework.cloud.gateway.support.CachingRouteLocator;
import org.springframework.cloud.gateway.support.DefaultRouteLocator; import org.springframework.cloud.gateway.support.RouteDefinitionRouteLocator;
import org.springframework.cloud.gateway.support.InMemoryRouteDefinitionRepository; import org.springframework.cloud.gateway.support.InMemoryRouteDefinitionRepository;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -81,6 +83,7 @@ import rx.RxReactiveStreams;
@Configuration @Configuration
@ConditionalOnBean(GatewayConfiguration.Marker.class) @ConditionalOnBean(GatewayConfiguration.Marker.class)
@EnableConfigurationProperties @EnableConfigurationProperties
@AutoConfigureBefore(HttpHandlerAutoConfiguration.class)
public class GatewayAutoConfiguration { public class GatewayAutoConfiguration {
@Configuration @Configuration
@ -113,13 +116,12 @@ public class GatewayAutoConfiguration {
} }
@Bean @Bean
@ConditionalOnMissingBean public RouteLocator routeDefinitionRouteLocator(GatewayProperties properties, List<GlobalFilter> globalFilters,
public RouteLocator defaultRouteLocator(GatewayProperties properties, List<GlobalFilter> globalFilters,
List<WebFilterFactory> webFilterFactories, List<WebFilterFactory> webFilterFactories,
List<RequestPredicateFactory> predicates, List<RequestPredicateFactory> predicates,
RouteDefinitionLocator routeDefinitionLocator) { RouteDefinitionLocator routeDefinitionLocator) {
return new CachingRouteLocator(new DefaultRouteLocator(properties, routeDefinitionLocator, return new CachingRouteLocator(new RouteDefinitionRouteLocator(routeDefinitionLocator, predicates, globalFilters, webFilterFactories, properties
predicates, globalFilters, webFilterFactories)); ));
} }
@Bean @Bean
@ -302,6 +304,14 @@ public class GatewayAutoConfiguration {
return new InMemoryRouteDefinitionRepository(); return new InMemoryRouteDefinitionRepository();
} }
/*@Bean
public RouterFunction<ServerResponse> test() {
RouterFunction<ServerResponse> route = RouterFunctions.route(
RequestPredicates.path("/testfun"),
request -> ServerResponse.ok().body(BodyInserters.fromObject("hello")));
return route;
}*/
@Configuration @Configuration
@ConditionalOnClass(Endpoint.class) @ConditionalOnClass(Endpoint.class)
protected static class GatewayActuatorConfiguration { protected static class GatewayActuatorConfiguration {

20
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/DefaultRouteLocator.java → spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/RouteDefinitionRouteLocator.java

@ -24,7 +24,6 @@ import org.springframework.cloud.gateway.api.RouteLocator;
import org.springframework.cloud.gateway.config.GatewayProperties; import org.springframework.cloud.gateway.config.GatewayProperties;
import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.cloud.gateway.filter.factory.WebFilterFactory; import org.springframework.cloud.gateway.filter.factory.WebFilterFactory;
import org.springframework.cloud.gateway.handler.FilteringWebHandler;
import org.springframework.cloud.gateway.handler.predicate.RequestPredicateFactory; import org.springframework.cloud.gateway.handler.predicate.RequestPredicateFactory;
import org.springframework.cloud.gateway.model.FilterDefinition; import org.springframework.cloud.gateway.model.FilterDefinition;
import org.springframework.cloud.gateway.model.PredicateDefinition; import org.springframework.cloud.gateway.model.PredicateDefinition;
@ -52,27 +51,28 @@ import java.util.stream.Collectors;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
/** /**
* {@link RouteLocator} that loads routes from a {@link RouteDefinitionLocator}
* @author Spencer Gibb * @author Spencer Gibb
*/ */
public class DefaultRouteLocator implements RouteLocator { public class RouteDefinitionRouteLocator implements RouteLocator {
protected final Log logger = LogFactory.getLog(getClass()); protected final Log logger = LogFactory.getLog(getClass());
private final GatewayProperties gatewayProperties;
private final RouteDefinitionLocator routeDefinitionLocator; private final RouteDefinitionLocator routeDefinitionLocator;
private final Map<String, RequestPredicateFactory> requestPredicates = new LinkedHashMap<>(); private final Map<String, RequestPredicateFactory> requestPredicates = new LinkedHashMap<>();
private final List<GlobalFilter> globalFilters; private final List<GlobalFilter> globalFilters;
private final Map<String, WebFilterFactory> webFilterFactories = new HashMap<>(); private final Map<String, WebFilterFactory> webFilterFactories = new HashMap<>();
private final GatewayProperties gatewayProperties;
public DefaultRouteLocator(GatewayProperties gatewayProperties, public RouteDefinitionRouteLocator(RouteDefinitionLocator routeDefinitionLocator,
RouteDefinitionLocator routeDefinitionLocator, List<RequestPredicateFactory> requestPredicates,
List<RequestPredicateFactory> requestPredicates, List<GlobalFilter> globalFilters,
List<GlobalFilter> globalFilters, List<WebFilterFactory> webFilterFactories,
List<WebFilterFactory> webFilterFactories) { GatewayProperties gatewayProperties) {
this.gatewayProperties = gatewayProperties;
this.routeDefinitionLocator = routeDefinitionLocator; this.routeDefinitionLocator = routeDefinitionLocator;
this.globalFilters = initList(globalFilters);
initFactories(requestPredicates); initFactories(requestPredicates);
this.globalFilters = initList(globalFilters);
webFilterFactories.forEach(factory -> this.webFilterFactories.put(factory.name(), factory)); webFilterFactories.forEach(factory -> this.webFilterFactories.put(factory.name(), factory));
this.gatewayProperties = gatewayProperties;
} }
private static <T> List<T> initList(List<T> list) { private static <T> List<T> initList(List<T> list) {
Loading…
Cancel
Save