Browse Source

add pkg protected resetRoutes so new mappings can be created via post to /routes

pull/6/head
Spencer Gibb 10 years ago
parent
commit
c0903c5a22
  1. 13
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/RouteLocator.java
  2. 2
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulHandlerMapping.java
  3. 6
      spring-cloud-netflix-sidecar/src/test/resources/application.yml

13
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/RouteLocator.java

@ -45,7 +45,7 @@ public class RouteLocator implements ApplicationListener<EnvironmentChangeEvent> @@ -45,7 +45,7 @@ public class RouteLocator implements ApplicationListener<EnvironmentChangeEvent>
public void onApplicationEvent(EnvironmentChangeEvent event) {
for (String key : event.getKeys()) {
if (key.startsWith(properties.getMapping())) {
routes.set(locateRoutes());
resetRoutes();
return;
}
}
@ -53,13 +53,20 @@ public class RouteLocator implements ApplicationListener<EnvironmentChangeEvent> @@ -53,13 +53,20 @@ public class RouteLocator implements ApplicationListener<EnvironmentChangeEvent>
public Map<String, String> getRoutes() {
if (routes.get() == null) {
routes.set(locateRoutes());
return resetRoutes();
}
return routes.get();
}
protected LinkedHashMap<String, String> locateRoutes() {
//access so ZuulHandlerMapping actuator can reset it's mappings
/*package*/ Map<String, String> resetRoutes() {
LinkedHashMap<String, String> newValue = locateRoutes();
routes.set(newValue);
return newValue;
}
protected LinkedHashMap<String, String> locateRoutes() {
LinkedHashMap<String, String> routesMap = new LinkedHashMap<>();
// Add routes for discovery services by default

2
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulHandlerMapping.java

@ -74,7 +74,7 @@ public class ZuulHandlerMapping extends AbstractUrlHandlerMapping implements @@ -74,7 +74,7 @@ public class ZuulHandlerMapping extends AbstractUrlHandlerMapping implements
@ResponseBody
@ManagedOperation
public Map<String, String> reset() {
Map<String, String> routes = routeLocator.getRoutes();
Map<String, String> routes = routeLocator.resetRoutes();
registerHandlers(routes);
return routes;
}

6
spring-cloud-netflix-sidecar/src/test/resources/application.yml

@ -20,9 +20,3 @@ endpoints: @@ -20,9 +20,3 @@ endpoints:
health:
sensitive: false
zuul:
proxy:
route:
stores: /stores
customers: /customers

Loading…
Cancel
Save