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; @@ -20,9 +20,11 @@ package org.springframework.cloud.gateway.config;
import java.util.List;
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.ConditionalOnClass;
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.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.gateway.actuate.GatewayEndpoint;
@ -65,7 +67,7 @@ import org.springframework.cloud.gateway.handler.predicate.QueryRequestPredicate @@ -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.RequestPredicateFactory;
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.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -81,6 +83,7 @@ import rx.RxReactiveStreams; @@ -81,6 +83,7 @@ import rx.RxReactiveStreams;
@Configuration
@ConditionalOnBean(GatewayConfiguration.Marker.class)
@EnableConfigurationProperties
@AutoConfigureBefore(HttpHandlerAutoConfiguration.class)
public class GatewayAutoConfiguration {
@Configuration
@ -113,13 +116,12 @@ public class GatewayAutoConfiguration { @@ -113,13 +116,12 @@ public class GatewayAutoConfiguration {
}
@Bean
@ConditionalOnMissingBean
public RouteLocator defaultRouteLocator(GatewayProperties properties, List<GlobalFilter> globalFilters,
public RouteLocator routeDefinitionRouteLocator(GatewayProperties properties, List<GlobalFilter> globalFilters,
List<WebFilterFactory> webFilterFactories,
List<RequestPredicateFactory> predicates,
RouteDefinitionLocator routeDefinitionLocator) {
return new CachingRouteLocator(new DefaultRouteLocator(properties, routeDefinitionLocator,
predicates, globalFilters, webFilterFactories));
return new CachingRouteLocator(new RouteDefinitionRouteLocator(routeDefinitionLocator, predicates, globalFilters, webFilterFactories, properties
));
}
@Bean
@ -302,6 +304,14 @@ public class GatewayAutoConfiguration { @@ -302,6 +304,14 @@ public class GatewayAutoConfiguration {
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
@ConditionalOnClass(Endpoint.class)
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; @@ -24,7 +24,6 @@ import org.springframework.cloud.gateway.api.RouteLocator;
import org.springframework.cloud.gateway.config.GatewayProperties;
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.handler.predicate.RequestPredicateFactory;
import org.springframework.cloud.gateway.model.FilterDefinition;
import org.springframework.cloud.gateway.model.PredicateDefinition;
@ -52,27 +51,28 @@ import java.util.stream.Collectors; @@ -52,27 +51,28 @@ import java.util.stream.Collectors;
import static java.util.Collections.emptyList;
/**
* {@link RouteLocator} that loads routes from a {@link RouteDefinitionLocator}
* @author Spencer Gibb
*/
public class DefaultRouteLocator implements RouteLocator {
public class RouteDefinitionRouteLocator implements RouteLocator {
protected final Log logger = LogFactory.getLog(getClass());
private final GatewayProperties gatewayProperties;
private final RouteDefinitionLocator routeDefinitionLocator;
private final Map<String, RequestPredicateFactory> requestPredicates = new LinkedHashMap<>();
private final List<GlobalFilter> globalFilters;
private final Map<String, WebFilterFactory> webFilterFactories = new HashMap<>();
private final GatewayProperties gatewayProperties;
public DefaultRouteLocator(GatewayProperties gatewayProperties,
RouteDefinitionLocator routeDefinitionLocator,
List<RequestPredicateFactory> requestPredicates,
List<GlobalFilter> globalFilters,
List<WebFilterFactory> webFilterFactories) {
this.gatewayProperties = gatewayProperties;
public RouteDefinitionRouteLocator(RouteDefinitionLocator routeDefinitionLocator,
List<RequestPredicateFactory> requestPredicates,
List<GlobalFilter> globalFilters,
List<WebFilterFactory> webFilterFactories,
GatewayProperties gatewayProperties) {
this.routeDefinitionLocator = routeDefinitionLocator;
this.globalFilters = initList(globalFilters);
initFactories(requestPredicates);
this.globalFilters = initList(globalFilters);
webFilterFactories.forEach(factory -> this.webFilterFactories.put(factory.name(), factory));
this.gatewayProperties = gatewayProperties;
}
private static <T> List<T> initList(List<T> list) {
Loading…
Cancel
Save