Change from using WebFliter to custom GatewayFilter.
This avoids any confusion with how WebFilters are using in WebFlux.
This commit is contained in:
@@ -29,7 +29,7 @@ import org.springframework.web.reactive.function.server.RouterFunction;
|
||||
import org.springframework.web.reactive.function.server.RouterFunctions;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
|
||||
import static org.springframework.cloud.gateway.filter.factory.WebFilterFactories.addResponseHeader;
|
||||
import static org.springframework.cloud.gateway.filter.factory.GatewayFilters.addResponseHeader;
|
||||
import static org.springframework.cloud.gateway.handler.predicate.RoutePredicates.host;
|
||||
import static org.springframework.cloud.gateway.handler.predicate.RoutePredicates.path;
|
||||
import static org.springframework.tuple.TupleBuilder.tuple;
|
||||
@@ -42,7 +42,7 @@ import static org.springframework.tuple.TupleBuilder.tuple;
|
||||
public class GatewaySampleApplication {
|
||||
|
||||
@Bean
|
||||
public RouteLocator customRouteLocator(ThrottleWebFilterFactory throttle) {
|
||||
public RouteLocator customRouteLocator(ThrottleGatewayFilterFactory throttle) {
|
||||
return Routes.locator()
|
||||
.route("test")
|
||||
.uri("http://httpbin.org:80")
|
||||
@@ -67,8 +67,8 @@ public class GatewaySampleApplication {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ThrottleWebFilterFactory throttleWebFilterFactory() {
|
||||
return new ThrottleWebFilterFactory();
|
||||
public ThrottleGatewayFilterFactory throttleWebFilterFactory() {
|
||||
return new ThrottleGatewayFilterFactory();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -21,10 +21,10 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.isomorphism.util.TokenBucket;
|
||||
import org.isomorphism.util.TokenBuckets;
|
||||
import org.springframework.cloud.gateway.filter.factory.WebFilterFactory;
|
||||
import org.springframework.cloud.gateway.filter.factory.GatewayFilterFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.tuple.Tuple;
|
||||
import org.springframework.web.server.WebFilter;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -32,11 +32,11 @@ import java.util.concurrent.TimeUnit;
|
||||
* Sample throttling filter.
|
||||
* See https://github.com/bbeck/token-bucket
|
||||
*/
|
||||
public class ThrottleWebFilterFactory implements WebFilterFactory {
|
||||
public class ThrottleGatewayFilterFactory implements GatewayFilterFactory {
|
||||
private Log log = LogFactory.getLog(getClass());
|
||||
|
||||
@Override
|
||||
public WebFilter apply(Tuple args) {
|
||||
public GatewayFilter apply(Tuple args) {
|
||||
int capacity = args.getInt("capacity");
|
||||
int refillTokens = args.getInt("refillTokens");
|
||||
int refillPeriod = args.getInt("refillPeriod");
|
||||
Reference in New Issue
Block a user