|
|
|
@ -20,12 +20,18 @@ import java.net.URI;
@@ -20,12 +20,18 @@ import java.net.URI;
|
|
|
|
|
import java.net.URISyntaxException; |
|
|
|
|
import java.net.URL; |
|
|
|
|
import java.util.Collection; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
import java.util.function.Consumer; |
|
|
|
|
import java.util.function.Function; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
|
import reactor.retry.Repeat; |
|
|
|
|
import reactor.retry.Retry; |
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
|
|
|
|
import org.springframework.cloud.gateway.filter.GatewayFilter; |
|
|
|
|
import org.springframework.cloud.gateway.filter.OrderedGatewayFilter; |
|
|
|
@ -59,9 +65,6 @@ import org.springframework.core.Ordered;
@@ -59,9 +65,6 @@ import org.springframework.core.Ordered;
|
|
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
|
import org.springframework.web.server.ServerWebExchange; |
|
|
|
|
|
|
|
|
|
import reactor.retry.Repeat; |
|
|
|
|
import reactor.retry.Retry; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Applies specific filters to routes. |
|
|
|
|
*/ |
|
|
|
@ -109,17 +112,30 @@ public class GatewayFilterSpec extends UriSpec {
@@ -109,17 +112,30 @@ public class GatewayFilterSpec extends UriSpec {
|
|
|
|
|
* @return a {@link GatewayFilterSpec} that can be used to apply additional filters |
|
|
|
|
*/ |
|
|
|
|
public GatewayFilterSpec filters(GatewayFilter... gatewayFilters) { |
|
|
|
|
this.routeBuilder.filters(gatewayFilters); |
|
|
|
|
List<GatewayFilter> filters = transformToOrderedFilters(Stream.of(gatewayFilters)); |
|
|
|
|
this.routeBuilder.filters(filters); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public List<GatewayFilter> transformToOrderedFilters(Stream<GatewayFilter> stream) { |
|
|
|
|
return stream |
|
|
|
|
.map(filter -> { |
|
|
|
|
if (filter instanceof Ordered) { |
|
|
|
|
return filter; |
|
|
|
|
} else { |
|
|
|
|
return new OrderedGatewayFilter(filter, 0); |
|
|
|
|
} |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Applies the list of filters to the route. |
|
|
|
|
* @param gatewayFilters the filters to apply |
|
|
|
|
* @return a {@link GatewayFilterSpec} that can be used to apply additional filters |
|
|
|
|
*/ |
|
|
|
|
public GatewayFilterSpec filters(Collection<GatewayFilter> gatewayFilters) { |
|
|
|
|
this.routeBuilder.filters(gatewayFilters); |
|
|
|
|
List<GatewayFilter> filters = transformToOrderedFilters(gatewayFilters.stream()); |
|
|
|
|
this.routeBuilder.filters(filters); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|