Move to predicate package. Create Method Predicate.

This commit is contained in:
Spencer Gibb
2016-12-01 12:26:43 -07:00
parent 209d3c4905
commit 283604ac15
8 changed files with 42 additions and 11 deletions

View File

@@ -8,11 +8,12 @@ import org.springframework.cloud.gateway.actuate.GatewayEndpoint;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter;
import org.springframework.cloud.gateway.handler.GatewayFilteringWebHandler;
import org.springframework.cloud.gateway.handler.HostPredicateFactory;
import org.springframework.cloud.gateway.handler.GatewayPredicateFactory;
import org.springframework.cloud.gateway.handler.predicate.HostPredicateFactory;
import org.springframework.cloud.gateway.handler.predicate.GatewayPredicateFactory;
import org.springframework.cloud.gateway.handler.GatewayWebHandler;
import org.springframework.cloud.gateway.handler.ServerWebExchangePredicateHandlerMapping;
import org.springframework.cloud.gateway.handler.UrlPredicateFactory;
import org.springframework.cloud.gateway.handler.predicate.MethodPredicateFactory;
import org.springframework.cloud.gateway.handler.predicate.UrlPredicateFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
@@ -70,6 +71,11 @@ public class GatewayAutoConfiguration {
return new UrlPredicateFactory();
}
@Bean
public MethodPredicateFactory methodPredicateFactory() {
return new MethodPredicateFactory();
}
@Configuration
@ConditionalOnClass(Endpoint.class)
protected static class GatewayActuatorConfiguration {

View File

@@ -8,7 +8,7 @@ import java.util.function.Predicate;
import org.springframework.beans.BeansException;
import org.springframework.cloud.gateway.config.GatewayProperties;
import org.springframework.cloud.gateway.config.GatewayProperties.Route;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.handler.predicate.GatewayPredicateFactory;
import org.springframework.web.reactive.handler.AbstractHandlerMapping;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebHandler;

View File

@@ -1,4 +1,4 @@
package org.springframework.cloud.gateway.handler;
package org.springframework.cloud.gateway.handler.predicate;
import org.springframework.web.server.ServerWebExchange;

View File

@@ -1,4 +1,4 @@
package org.springframework.cloud.gateway.handler;
package org.springframework.cloud.gateway.handler.predicate;
import java.util.function.Predicate;

View File

@@ -0,0 +1,26 @@
package org.springframework.cloud.gateway.handler.predicate;
import java.util.function.Predicate;
import org.springframework.http.HttpMethod;
import org.springframework.web.server.ServerWebExchange;
/**
* @author Spencer Gibb
*/
public class MethodPredicateFactory implements GatewayPredicateFactory {
@Override
public String getName() {
return "Method";
}
@Override
public Predicate<ServerWebExchange> create(String method) {
//TODO: caching can happen here
return exchange -> {
HttpMethod requestMethod = exchange.getRequest().getMethod();
return requestMethod.matches(method);
};
}
}

View File

@@ -1,4 +1,4 @@
package org.springframework.cloud.gateway.handler;
package org.springframework.cloud.gateway.handler.predicate;
import java.util.function.Predicate;

View File

@@ -8,12 +8,9 @@ import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.gateway.config.GatewayProperties;
import org.springframework.cloud.gateway.config.GatewayProperties.Route;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.handler.HostPredicateFactory;
import org.springframework.cloud.gateway.handler.ServerWebExchangePredicateHandlerMapping;
import org.springframework.cloud.gateway.handler.UrlPredicateFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpHeaders;

View File

@@ -17,7 +17,9 @@ spring:
- name: Host
value: '**.foo.org'
- name: Url
value: '/headers'
value: /headers
- name: Method
value: GET
# =====================================
- id: default_path_to_httpbin