Rename PredicateFactory -> RoutePredicate

This commit is contained in:
Spencer Gibb
2017-01-14 11:24:43 -07:00
parent efe4855e62
commit a431b7ed9a
11 changed files with 44 additions and 44 deletions

View File

@@ -23,13 +23,13 @@ import org.springframework.cloud.gateway.filter.route.SetStatusRouteFilter;
import org.springframework.cloud.gateway.handler.GatewayFilteringWebHandler;
import org.springframework.cloud.gateway.handler.GatewayPredicateHandlerMapping;
import org.springframework.cloud.gateway.handler.GatewayWebHandler;
import org.springframework.cloud.gateway.handler.predicate.CookiePredicateFactory;
import org.springframework.cloud.gateway.handler.predicate.HeaderPredicateFactory;
import org.springframework.cloud.gateway.handler.predicate.HostPredicateFactory;
import org.springframework.cloud.gateway.handler.predicate.MethodPredicateFactory;
import org.springframework.cloud.gateway.handler.predicate.PredicateFactory;
import org.springframework.cloud.gateway.handler.predicate.QueryPredicateFactory;
import org.springframework.cloud.gateway.handler.predicate.UrlPredicateFactory;
import org.springframework.cloud.gateway.handler.predicate.CookieRoutePredicate;
import org.springframework.cloud.gateway.handler.predicate.HeaderRoutePredicate;
import org.springframework.cloud.gateway.handler.predicate.HostRoutePredicate;
import org.springframework.cloud.gateway.handler.predicate.MethodRoutePredicate;
import org.springframework.cloud.gateway.handler.predicate.RoutePredicate;
import org.springframework.cloud.gateway.handler.predicate.QueryRoutePredicate;
import org.springframework.cloud.gateway.handler.predicate.UrlRoutePredicate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
@@ -80,39 +80,39 @@ public class GatewayAutoConfiguration {
@Bean
public GatewayPredicateHandlerMapping gatewayPredicateHandlerMapping(GatewayFilteringWebHandler webHandler,
Map<String, PredicateFactory> predicates,
Map<String, RoutePredicate> predicates,
RouteReader routeReader) {
return new GatewayPredicateHandlerMapping(webHandler, predicates, routeReader);
}
@Bean(name = "CookiePredicateFactory")
public CookiePredicateFactory cookiePredicateFactory() {
return new CookiePredicateFactory();
@Bean(name = "CookieRoutePredicate")
public CookieRoutePredicate cookieRoutePredicate() {
return new CookieRoutePredicate();
}
@Bean(name = "HeaderPredicateFactory")
public HeaderPredicateFactory headerPredicateFactory() {
return new HeaderPredicateFactory();
@Bean(name = "HeaderRoutePredicate")
public HeaderRoutePredicate headerRoutePredicate() {
return new HeaderRoutePredicate();
}
@Bean(name = "HostPredicateFactory")
public HostPredicateFactory hostPredicateFactory() {
return new HostPredicateFactory();
@Bean(name = "HostRoutePredicate")
public HostRoutePredicate hostRoutePredicate() {
return new HostRoutePredicate();
}
@Bean(name = "MethodPredicateFactory")
public MethodPredicateFactory methodPredicateFactory() {
return new MethodPredicateFactory();
@Bean(name = "MethodRoutePredicate")
public MethodRoutePredicate methodRoutePredicate() {
return new MethodRoutePredicate();
}
@Bean(name = "QueryPredicateFactory")
public QueryPredicateFactory queryPredicateFactory() {
return new QueryPredicateFactory();
@Bean(name = "QueryRoutePredicate")
public QueryRoutePredicate queryRoutePredicate() {
return new QueryRoutePredicate();
}
@Bean(name = "UrlPredicateFactory")
public UrlPredicateFactory urlPredicateFactory() {
return new UrlPredicateFactory();
@Bean(name = "UrlRoutePredicate")
public UrlRoutePredicate urlRoutePredicate() {
return new UrlRoutePredicate();
}
// Filter Factory beans

View File

@@ -8,7 +8,7 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.util.UriTemplate;
import static org.springframework.cloud.gateway.filter.GatewayFilter.getAttribute;
import static org.springframework.cloud.gateway.handler.predicate.UrlPredicateFactory.URL_PREDICATE_VARS_ATTR;
import static org.springframework.cloud.gateway.handler.predicate.UrlRoutePredicate.URL_PREDICATE_VARS_ATTR;
/**
* @author Spencer Gibb

View File

@@ -11,7 +11,7 @@ import org.springframework.beans.BeansException;
import org.springframework.cloud.gateway.api.RouteReader;
import org.springframework.cloud.gateway.config.Route;
import org.springframework.cloud.gateway.config.PredicateDefinition;
import org.springframework.cloud.gateway.handler.predicate.PredicateFactory;
import org.springframework.cloud.gateway.handler.predicate.RoutePredicate;
import org.springframework.web.reactive.handler.AbstractHandlerMapping;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebHandler;
@@ -26,13 +26,13 @@ import static org.springframework.cloud.gateway.filter.GatewayFilter.GATEWAY_ROU
*/
public class GatewayPredicateHandlerMapping extends AbstractHandlerMapping {
private Map<String, PredicateFactory> predicates = new LinkedHashMap<>();
private Map<String, RoutePredicate> predicates = new LinkedHashMap<>();
private RouteReader routeReader;
private WebHandler webHandler;
private List<Route> routes;
public GatewayPredicateHandlerMapping(WebHandler webHandler, Map<String, PredicateFactory> predicates,
public GatewayPredicateHandlerMapping(WebHandler webHandler, Map<String, RoutePredicate> predicates,
RouteReader routeReader) {
this.webHandler = webHandler;
this.routeReader = routeReader;
@@ -40,13 +40,13 @@ public class GatewayPredicateHandlerMapping extends AbstractHandlerMapping {
predicates.forEach((name, factory) -> {
String key = normalizeName(name);
if (this.predicates.containsKey(key)) {
this.logger.warn("A PredicateFactory named "+ key
this.logger.warn("A RoutePredicate named "+ key
+ " already exists, class: " + this.predicates.get(key)
+ ". It will be overwritten.");
}
this.predicates.put(key, factory);
if (logger.isInfoEnabled()) {
logger.info("Loaded PredicateFactory [" + key + "]");
logger.info("Loaded RoutePredicate [" + key + "]");
}
});
@@ -54,7 +54,7 @@ public class GatewayPredicateHandlerMapping extends AbstractHandlerMapping {
}
private String normalizeName(String name) {
return name.replace(PredicateFactory.class.getSimpleName(), "");
return name.replace(RoutePredicate.class.getSimpleName(), "");
}
@Override
@@ -140,9 +140,9 @@ public class GatewayPredicateHandlerMapping extends AbstractHandlerMapping {
}
private Predicate<ServerWebExchange> lookup(Route route, PredicateDefinition predicate) {
PredicateFactory found = this.predicates.get(predicate.getName());
RoutePredicate found = this.predicates.get(predicate.getName());
if (found == null) {
throw new IllegalArgumentException("Unable to find PredicateFactory with name " + predicate.getName());
throw new IllegalArgumentException("Unable to find RoutePredicate with name " + predicate.getName());
}
if (logger.isDebugEnabled()) {
List<String> args;

View File

@@ -10,7 +10,7 @@ import org.springframework.web.server.ServerWebExchange;
/**
* @author Spencer Gibb
*/
public class CookiePredicateFactory implements PredicateFactory {
public class CookieRoutePredicate implements RoutePredicate {
@Override
public Predicate<ServerWebExchange> apply(String name, String[] args) {

View File

@@ -9,7 +9,7 @@ import org.springframework.web.server.ServerWebExchange;
/**
* @author Spencer Gibb
*/
public class HeaderPredicateFactory implements PredicateFactory {
public class HeaderRoutePredicate implements RoutePredicate {
@Override
public Predicate<ServerWebExchange> apply(String header, String[] args) {

View File

@@ -9,7 +9,7 @@ import org.springframework.web.server.ServerWebExchange;
/**
* @author Spencer Gibb
*/
public class HostPredicateFactory implements PredicateFactory {
public class HostRoutePredicate implements RoutePredicate {
private PathMatcher pathMatcher = new AntPathMatcher(".");

View File

@@ -8,7 +8,7 @@ import org.springframework.web.server.ServerWebExchange;
/**
* @author Spencer Gibb
*/
public class MethodPredicateFactory implements PredicateFactory {
public class MethodRoutePredicate implements RoutePredicate {
@Override
public Predicate<ServerWebExchange> apply(String method, String[] args) {

View File

@@ -8,7 +8,7 @@ import org.springframework.web.server.ServerWebExchange;
/**
* @author Spencer Gibb
*/
public class QueryPredicateFactory implements PredicateFactory {
public class QueryRoutePredicate implements RoutePredicate {
@Override
public Predicate<ServerWebExchange> apply(String param, String[] args) {

View File

@@ -7,7 +7,7 @@ import org.springframework.web.server.ServerWebExchange;
/**
* @author Spencer Gibb
*/
public interface PredicateFactory {
public interface RoutePredicate {
Predicate<ServerWebExchange> apply(String value, String[] args);
}

View File

@@ -11,7 +11,7 @@ import org.springframework.web.server.support.HttpRequestPathHelper;
/**
* @author Spencer Gibb
*/
public class UrlPredicateFactory implements PredicateFactory {
public class UrlRoutePredicate implements RoutePredicate {
public static final String URL_PREDICATE_VARS_ATTR = "urlPredicateVars";

View File

@@ -5,7 +5,7 @@ import java.util.HashMap;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.cloud.gateway.handler.predicate.UrlPredicateFactory;
import org.springframework.cloud.gateway.handler.predicate.UrlRoutePredicate;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.http.server.reactive.MockServerHttpResponse;
import org.springframework.web.server.ServerWebExchange;
@@ -44,7 +44,7 @@ public class SetPathRouteFilterTests {
.build();
DefaultServerWebExchange exchange = new DefaultServerWebExchange(request, new MockServerHttpResponse());
exchange.getAttributes().put(UrlPredicateFactory.URL_PREDICATE_VARS_ATTR, variables);
exchange.getAttributes().put(UrlRoutePredicate.URL_PREDICATE_VARS_ATTR, variables);
WebFilterChain filterChain = mock(WebFilterChain.class);