Browse Source

Align gateway endpoint closer to spring boot 2.0

pull/96/head
Spencer Gibb 7 years ago
parent
commit
5f9bd816b4
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 20
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/actuate/GatewayWebfluxEndpoint.java
  2. 14
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java

20
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/actuate/GatewayEndpoint.java → spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/actuate/GatewayWebfluxEndpoint.java

@ -50,13 +50,11 @@ import reactor.core.publisher.Mono; @@ -50,13 +50,11 @@ import reactor.core.publisher.Mono;
/**
* @author Spencer Gibb
*/
//TODO: move to new Spring Boot 2.0 actuator when ready
//@ConfigurationProperties(prefix = "endpoints.gateway")
@RestController
@RequestMapping("/admin/gateway")
public class GatewayEndpoint implements ApplicationEventPublisherAware {/*extends AbstractEndpoint<Map<String, Object>> {*/
@RequestMapping("${management.context-path:/application}/gateway")
public class GatewayWebfluxEndpoint implements ApplicationEventPublisherAware {
private static final Log log = LogFactory.getLog(GatewayEndpoint.class);
private static final Log log = LogFactory.getLog(GatewayWebfluxEndpoint.class);
private RouteDefinitionLocator routeDefinitionLocator;
private List<GlobalFilter> globalFilters;
@ -65,10 +63,9 @@ public class GatewayEndpoint implements ApplicationEventPublisherAware {/*extend @@ -65,10 +63,9 @@ public class GatewayEndpoint implements ApplicationEventPublisherAware {/*extend
private RouteLocator routeLocator;
private ApplicationEventPublisher publisher;
public GatewayEndpoint(RouteDefinitionLocator routeDefinitionLocator, List<GlobalFilter> globalFilters,
List<WebFilterFactory> webFilterFactories, RouteDefinitionWriter routeDefinitionWriter,
RouteLocator routeLocator) {
//super("gateway");
public GatewayWebfluxEndpoint(RouteDefinitionLocator routeDefinitionLocator, List<GlobalFilter> globalFilters,
List<WebFilterFactory> webFilterFactories, RouteDefinitionWriter routeDefinitionWriter,
RouteLocator routeLocator) {
this.routeDefinitionLocator = routeDefinitionLocator;
this.globalFilters = globalFilters;
this.webFilterFactories = webFilterFactories;
@ -81,10 +78,6 @@ public class GatewayEndpoint implements ApplicationEventPublisherAware {/*extend @@ -81,10 +78,6 @@ public class GatewayEndpoint implements ApplicationEventPublisherAware {/*extend
this.publisher = publisher;
}
/*@Override
public Map<String, Object> invoke() {
}*/
// TODO: Add uncommited or new but not active routes endpoint
//TODO: this should really be a listener that responds to a RefreshEvent
@ -119,6 +112,7 @@ public class GatewayEndpoint implements ApplicationEventPublisherAware {/*extend @@ -119,6 +112,7 @@ public class GatewayEndpoint implements ApplicationEventPublisherAware {/*extend
return filters;
}
// TODO: Add support for RouteLocator
@GetMapping("/routes")
public Mono<List<RouteDefinition>> routes() {
return this.routeDefinitionLocator.getRouteDefinitions().collectList();

14
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java

@ -21,6 +21,7 @@ import java.util.List; @@ -21,6 +21,7 @@ import java.util.List;
import java.util.function.Consumer;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
@ -30,7 +31,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean @@ -30,7 +31,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.gateway.actuate.GatewayEndpoint;
import org.springframework.cloud.gateway.actuate.GatewayWebfluxEndpoint;
import org.springframework.cloud.gateway.filter.ForwardRoutingFilter;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.cloud.gateway.filter.NettyRoutingFilter;
@ -370,15 +371,16 @@ public class GatewayAutoConfiguration { @@ -370,15 +371,16 @@ public class GatewayAutoConfiguration {
}
@Configuration
@ManagementContextConfiguration
@ConditionalOnProperty(value = "management.gateway.enabled", matchIfMissing = true)
@ConditionalOnClass(Health.class)
protected static class GatewayActuatorConfiguration {
@Bean
public GatewayEndpoint gatewayEndpoint(RouteDefinitionLocator routeDefinitionLocator, List<GlobalFilter> globalFilters,
List<WebFilterFactory> webFilterFactories, RouteDefinitionWriter routeDefinitionWriter,
RouteLocator routeLocator) {
return new GatewayEndpoint(routeDefinitionLocator, globalFilters, webFilterFactories, routeDefinitionWriter, routeLocator);
public GatewayWebfluxEndpoint gatewayWebfluxEndpoint(RouteDefinitionLocator routeDefinitionLocator, List<GlobalFilter> globalFilters,
List<WebFilterFactory> webFilterFactories, RouteDefinitionWriter routeDefinitionWriter,
RouteLocator routeLocator) {
return new GatewayWebfluxEndpoint(routeDefinitionLocator, globalFilters, webFilterFactories, routeDefinitionWriter, routeLocator);
}
}

Loading…
Cancel
Save