Spring-cloude-gateway fluent java api has different manner of defining predicates
up vote
0
down vote
favorite
In our code we use Spring Cloud Gateway to dynamically configure routes to services using the fluent java routes API. Lets assume we want to filter on the path of an incoming request. We can implement this in two manners and my question is about the difference between the two:
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder, ThrottleGatewayFilterFactory throttle) {
return builder.routes()
.route(r ->
r.host("**.abc.org")
.and()
.path("/image/png")
.uri("http://httpbin.org:80")
)
.route(r ->
r.host("**.abc.org")
.uri("http://httpbin.org:80")
.and(ServerWebExchangeUtils.toAsyncPredicate(
new PathRoutePredicateFactory().apply(config -> config.setPattern("/images/jpeg")))
)
.build();
}
In the first route, we configure the path predicate by calling the
PredicateSpec.path().In the second example we configure the path using
Route.AsyncBuilder.and()(Route.AsyncBuilderis the type returned by.uri()method).
Obviously, the first manner is more readable and easy. But I guess there is a use case for defining predicates after the uri() method? What the difference between defining predicates before or after the call to uri()?
spring-cloud-gateway
New contributor
Guidoos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
In our code we use Spring Cloud Gateway to dynamically configure routes to services using the fluent java routes API. Lets assume we want to filter on the path of an incoming request. We can implement this in two manners and my question is about the difference between the two:
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder, ThrottleGatewayFilterFactory throttle) {
return builder.routes()
.route(r ->
r.host("**.abc.org")
.and()
.path("/image/png")
.uri("http://httpbin.org:80")
)
.route(r ->
r.host("**.abc.org")
.uri("http://httpbin.org:80")
.and(ServerWebExchangeUtils.toAsyncPredicate(
new PathRoutePredicateFactory().apply(config -> config.setPattern("/images/jpeg")))
)
.build();
}
In the first route, we configure the path predicate by calling the
PredicateSpec.path().In the second example we configure the path using
Route.AsyncBuilder.and()(Route.AsyncBuilderis the type returned by.uri()method).
Obviously, the first manner is more readable and easy. But I guess there is a use case for defining predicates after the uri() method? What the difference between defining predicates before or after the call to uri()?
spring-cloud-gateway
New contributor
Guidoos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
In our code we use Spring Cloud Gateway to dynamically configure routes to services using the fluent java routes API. Lets assume we want to filter on the path of an incoming request. We can implement this in two manners and my question is about the difference between the two:
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder, ThrottleGatewayFilterFactory throttle) {
return builder.routes()
.route(r ->
r.host("**.abc.org")
.and()
.path("/image/png")
.uri("http://httpbin.org:80")
)
.route(r ->
r.host("**.abc.org")
.uri("http://httpbin.org:80")
.and(ServerWebExchangeUtils.toAsyncPredicate(
new PathRoutePredicateFactory().apply(config -> config.setPattern("/images/jpeg")))
)
.build();
}
In the first route, we configure the path predicate by calling the
PredicateSpec.path().In the second example we configure the path using
Route.AsyncBuilder.and()(Route.AsyncBuilderis the type returned by.uri()method).
Obviously, the first manner is more readable and easy. But I guess there is a use case for defining predicates after the uri() method? What the difference between defining predicates before or after the call to uri()?
spring-cloud-gateway
New contributor
Guidoos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
In our code we use Spring Cloud Gateway to dynamically configure routes to services using the fluent java routes API. Lets assume we want to filter on the path of an incoming request. We can implement this in two manners and my question is about the difference between the two:
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder, ThrottleGatewayFilterFactory throttle) {
return builder.routes()
.route(r ->
r.host("**.abc.org")
.and()
.path("/image/png")
.uri("http://httpbin.org:80")
)
.route(r ->
r.host("**.abc.org")
.uri("http://httpbin.org:80")
.and(ServerWebExchangeUtils.toAsyncPredicate(
new PathRoutePredicateFactory().apply(config -> config.setPattern("/images/jpeg")))
)
.build();
}
In the first route, we configure the path predicate by calling the
PredicateSpec.path().In the second example we configure the path using
Route.AsyncBuilder.and()(Route.AsyncBuilderis the type returned by.uri()method).
Obviously, the first manner is more readable and easy. But I guess there is a use case for defining predicates after the uri() method? What the difference between defining predicates before or after the call to uri()?
spring-cloud-gateway
spring-cloud-gateway
New contributor
Guidoos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Guidoos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Guidoos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked yesterday
Guidoos
11
11
New contributor
Guidoos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Guidoos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Guidoos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Guidoos is a new contributor. Be nice, and check out our Code of Conduct.
Guidoos is a new contributor. Be nice, and check out our Code of Conduct.
Guidoos is a new contributor. Be nice, and check out our Code of Conduct.
Guidoos is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265869%2fspring-cloude-gateway-fluent-java-api-has-different-manner-of-defining-predicate%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password