Renames UrlRoutePredicate to PathRoutePredicate

fixes gh-30
This commit is contained in:
Spencer Gibb
2017-03-02 10:58:02 -07:00
parent b479cacfcb
commit 24e5aa3401
10 changed files with 31 additions and 33 deletions

View File

@@ -123,7 +123,7 @@ public class GatewayEndpoint implements ApplicationEventPublisherAware {/*extend
}
/*
http POST :8080/admin/gateway/routes/apiaddreqhead uri=http://httpbin.org:80 predicates:='["Host=**.apiaddrequestheader.org", "Url=/headers"]' filters:='["AddRequestHeader=X-Request-ApiFoo, ApiBar"]'
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) {

View File

@@ -59,10 +59,10 @@ 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.PathRoutePredicate;
import org.springframework.cloud.gateway.handler.predicate.QueryRoutePredicate;
import org.springframework.cloud.gateway.handler.predicate.RemoteAddrRoutePredicate;
import org.springframework.cloud.gateway.handler.predicate.RoutePredicate;
import org.springframework.cloud.gateway.handler.predicate.UrlRoutePredicate;
import org.springframework.cloud.gateway.support.CachingRouteLocator;
import org.springframework.cloud.gateway.support.InMemoryRouteRepository;
import org.springframework.context.annotation.Bean;
@@ -195,6 +195,11 @@ public class GatewayAutoConfiguration {
return new MethodRoutePredicate();
}
@Bean(name = "PathRoutePredicate")
public PathRoutePredicate pathRoutePredicate() {
return new PathRoutePredicate();
}
@Bean(name = "QueryRoutePredicate")
public QueryRoutePredicate queryRoutePredicate() {
return new QueryRoutePredicate();
@@ -205,12 +210,6 @@ public class GatewayAutoConfiguration {
return new RemoteAddrRoutePredicate();
}
@Bean(name = "UrlRoutePredicate")
public UrlRoutePredicate urlRoutePredicate() {
return new UrlRoutePredicate();
}
// Filter Factory beans
@Bean(name = "AddRequestHeaderRouteFilter")

View File

@@ -25,7 +25,7 @@ import org.springframework.cloud.gateway.api.PredicateDefinition;
import org.springframework.cloud.gateway.api.Route;
import org.springframework.cloud.gateway.api.RouteLocator;
import org.springframework.cloud.gateway.filter.route.RewritePathRouteFilter;
import org.springframework.cloud.gateway.handler.predicate.UrlRoutePredicate;
import org.springframework.cloud.gateway.handler.predicate.PathRoutePredicate;
import static org.springframework.cloud.gateway.support.NameUtils.normalizeFilterName;
import static org.springframework.cloud.gateway.support.NameUtils.normalizePredicateName;
@@ -56,7 +56,7 @@ public class DiscoveryClientRouteLocator implements RouteLocator {
// add a predicate that matches the url at /serviceId/**
PredicateDefinition predicate = new PredicateDefinition();
predicate.setName(normalizePredicateName(UrlRoutePredicate.class));
predicate.setName(normalizePredicateName(PathRoutePredicate.class));
predicate.setArgs("/" + serviceId + "/**");
route.getPredicates().add(predicate);

View File

@@ -25,7 +25,7 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.util.UriTemplate;
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.getAttribute;
import static org.springframework.cloud.gateway.handler.predicate.UrlRoutePredicate.URL_PREDICATE_VARS_ATTR;
import static org.springframework.cloud.gateway.handler.predicate.PathRoutePredicate.URL_PREDICATE_VARS_ATTR;
/**
* @author Spencer Gibb

View File

@@ -20,19 +20,19 @@ package org.springframework.cloud.gateway.handler.predicate;
import java.util.Map;
import java.util.function.Predicate;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.support.HttpRequestPathHelper;
import org.springframework.web.util.ParsingPathMatcher;
/**
* @author Spencer Gibb
*/
public class UrlRoutePredicate implements RoutePredicate {
public class PathRoutePredicate implements RoutePredicate {
public static final String URL_PREDICATE_VARS_ATTR = "urlPredicateVars";
private PathMatcher pathMatcher = new AntPathMatcher();
private PathMatcher pathMatcher = new ParsingPathMatcher();
private HttpRequestPathHelper pathHelper = new HttpRequestPathHelper();
public PathMatcher getPathMatcher() {

View File

@@ -22,7 +22,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.UrlRoutePredicate;
import org.springframework.cloud.gateway.handler.predicate.PathRoutePredicate;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.http.server.reactive.MockServerHttpResponse;
import org.springframework.web.server.ServerWebExchange;
@@ -61,7 +61,7 @@ public class SetPathRouteFilterTests {
.build();
DefaultServerWebExchange exchange = new DefaultServerWebExchange(request, new MockServerHttpResponse());
exchange.getAttributes().put(UrlRoutePredicate.URL_PREDICATE_VARS_ATTR, variables);
exchange.getAttributes().put(PathRoutePredicate.URL_PREDICATE_VARS_ATTR, variables);
WebFilterChain filterChain = mock(WebFilterChain.class);

View File

@@ -41,10 +41,10 @@ import reactor.test.StepVerifier;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = RANDOM_PORT)
@DirtiesContext
public class UrlRoutePredicateIntegrationTests extends BaseWebClientTests {
public class PathRoutePredicateIntegrationTests extends BaseWebClientTests {
@Test
public void urlRouteWorks() {
public void pathRouteWorks() {
Mono<ClientResponse> result = webClient.get()
.uri("/get")
.exchange();

View File

@@ -10,7 +10,7 @@ spring:
uri: http://httpbin.org:80
predicates:
- Host=**.removerequestheader.org
- Url=/headers
- Path=/headers
filters:
- RemoveRequestHeader=X-Request-Foo

View File

@@ -19,7 +19,7 @@ spring:
uri: ${test.uri}
predicates:
- Host=**.foo.org
- Url=/headers
- Path=/headers
- Method=GET
- Header=X-Request-Id, \d+
- Query=foo, ba.
@@ -34,7 +34,7 @@ spring:
uri: ${test.uri}
predicates:
- Host=**.addrequestheader.org
- Url=/headers
- Path=/headers
filters:
- AddRequestHeader=X-Request-Foo, Bar
@@ -43,7 +43,7 @@ spring:
uri: ${test.uri}
predicates:
- Host=**.addrequestparameter.org
- Url=/get
- Path=/get
filters:
- AddRequestParameter=foo, bar
@@ -52,7 +52,7 @@ spring:
uri: ${test.uri}
predicates:
- Host=**.addresponseheader.org
- Url=/headers
- Path=/headers
filters:
- AddResponseHeader=X-Request-Foo, Bar
@@ -91,7 +91,7 @@ spring:
uri: ${test.uri}
predicates:
- Host=**.removerequestheader.org
- Url=/headers
- Path=/headers
filters:
- RemoveRequestHeader=X-Request-Foo
@@ -100,7 +100,7 @@ spring:
uri: ${test.uri}
predicates:
- Host=**.removereresponseheader.org
- Url=/headers
- Path=/headers
filters:
- AddResponseHeader=X-Request-Foo, Bar
- RemoveResponseHeader=X-Request-Foo
@@ -110,7 +110,7 @@ spring:
uri: ${test.uri}
predicates:
- Host=**.secureheaders.org
- Url=/headers
- Path=/headers
filters:
- SecureHeaders
@@ -119,7 +119,7 @@ spring:
uri: ${test.uri}
predicates:
- Host=**.setpath.org
- Url=/foo/{segment}
- Path=/foo/{segment}
filters:
- SetPath=/{segment}
@@ -128,7 +128,7 @@ spring:
uri: ${test.uri}
predicates:
- Host=**.setreresponseheader.org
- Url=/headers
- Path=/headers
filters:
- AddResponseHeader=X-Request-Foo, Bar1
- AddResponseHeader=X-Request-Foo, Bar2
@@ -139,7 +139,7 @@ spring:
uri: ${test.uri}
predicates:
- Host=**.setstatusint.org
- Url=/headers
- Path=/headers
filters:
- name: SetStatus
args: 401
@@ -149,7 +149,7 @@ spring:
uri: ${test.uri}
predicates:
- Host=**.setstatusstring.org
- Url=/headers
- Path=/headers
filters:
- SetStatus=BAD_REQUEST
@@ -169,7 +169,7 @@ spring:
- id: default_path_to_httpbin
uri: ${test.uri}
predicates:
- name: Url
- name: Path
args: /**
myservice:

View File

@@ -14,8 +14,7 @@ spring:
- id: default_path_to_httpbin
uri: ${test.uri}
predicates:
- name: Url
args: /**
- Path=/**
logging:
level: