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;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
*/ */
//TODO: move to new Spring Boot 2.0 actuator when ready
//@ConfigurationProperties(prefix = "endpoints.gateway")
@RestController @RestController
@RequestMapping("/admin/gateway") @RequestMapping("${management.context-path:/application}/gateway")
public class GatewayEndpoint implements ApplicationEventPublisherAware {/*extends AbstractEndpoint<Map<String, Object>> {*/ 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 RouteDefinitionLocator routeDefinitionLocator;
private List<GlobalFilter> globalFilters; private List<GlobalFilter> globalFilters;
@ -65,10 +63,9 @@ public class GatewayEndpoint implements ApplicationEventPublisherAware {/*extend
private RouteLocator routeLocator; private RouteLocator routeLocator;
private ApplicationEventPublisher publisher; private ApplicationEventPublisher publisher;
public GatewayEndpoint(RouteDefinitionLocator routeDefinitionLocator, List<GlobalFilter> globalFilters, public GatewayWebfluxEndpoint(RouteDefinitionLocator routeDefinitionLocator, List<GlobalFilter> globalFilters,
List<WebFilterFactory> webFilterFactories, RouteDefinitionWriter routeDefinitionWriter, List<WebFilterFactory> webFilterFactories, RouteDefinitionWriter routeDefinitionWriter,
RouteLocator routeLocator) { RouteLocator routeLocator) {
//super("gateway");
this.routeDefinitionLocator = routeDefinitionLocator; this.routeDefinitionLocator = routeDefinitionLocator;
this.globalFilters = globalFilters; this.globalFilters = globalFilters;
this.webFilterFactories = webFilterFactories; this.webFilterFactories = webFilterFactories;
@ -81,10 +78,6 @@ public class GatewayEndpoint implements ApplicationEventPublisherAware {/*extend
this.publisher = publisher; this.publisher = publisher;
} }
/*@Override
public Map<String, Object> invoke() {
}*/
// TODO: Add uncommited or new but not active routes endpoint // TODO: Add uncommited or new but not active routes endpoint
//TODO: this should really be a listener that responds to a RefreshEvent //TODO: this should really be a listener that responds to a RefreshEvent
@ -119,6 +112,7 @@ public class GatewayEndpoint implements ApplicationEventPublisherAware {/*extend
return filters; return filters;
} }
// TODO: Add support for RouteLocator
@GetMapping("/routes") @GetMapping("/routes")
public Mono<List<RouteDefinition>> routes() { public Mono<List<RouteDefinition>> routes() {
return this.routeDefinitionLocator.getRouteDefinitions().collectList(); 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;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.springframework.beans.factory.annotation.Qualifier; 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.actuate.health.Health;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
@ -30,7 +31,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration; import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties; 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.ForwardRoutingFilter;
import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.cloud.gateway.filter.NettyRoutingFilter; import org.springframework.cloud.gateway.filter.NettyRoutingFilter;
@ -370,15 +371,16 @@ public class GatewayAutoConfiguration {
} }
@Configuration @ManagementContextConfiguration
@ConditionalOnProperty(value = "management.gateway.enabled", matchIfMissing = true)
@ConditionalOnClass(Health.class) @ConditionalOnClass(Health.class)
protected static class GatewayActuatorConfiguration { protected static class GatewayActuatorConfiguration {
@Bean @Bean
public GatewayEndpoint gatewayEndpoint(RouteDefinitionLocator routeDefinitionLocator, List<GlobalFilter> globalFilters, public GatewayWebfluxEndpoint gatewayWebfluxEndpoint(RouteDefinitionLocator routeDefinitionLocator, List<GlobalFilter> globalFilters,
List<WebFilterFactory> webFilterFactories, RouteDefinitionWriter routeDefinitionWriter, List<WebFilterFactory> webFilterFactories, RouteDefinitionWriter routeDefinitionWriter,
RouteLocator routeLocator) { RouteLocator routeLocator) {
return new GatewayEndpoint(routeDefinitionLocator, globalFilters, webFilterFactories, routeDefinitionWriter, routeLocator); return new GatewayWebfluxEndpoint(routeDefinitionLocator, globalFilters, webFilterFactories, routeDefinitionWriter, routeLocator);
} }
} }

Loading…
Cancel
Save