From 7e91b9ea21c0c5c0cd339ddffe4c083fe58cd3c2 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 2 Dec 2014 13:09:06 +0000 Subject: [PATCH] Rename some Zuul config keys zuul.route -> zuul.routes zuul.mapping -> zuul.prefix --- .../cloud/netflix/zuul/RouteLocator.java | 4 ++-- .../netflix/zuul/ZuulHandlerMapping.java | 4 ++-- .../cloud/netflix/zuul/ZuulProperties.java | 6 +++--- .../zuul/filters/pre/PreDecorationFilter.java | 4 ++-- .../cloud/netflix/zuul/RouteLocatorTests.java | 19 +++++++++++++++++-- .../src/test/resources/application.yml | 6 +++--- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/RouteLocator.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/RouteLocator.java index 9443f22f..9ec31213 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/RouteLocator.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/RouteLocator.java @@ -44,7 +44,7 @@ public class RouteLocator implements ApplicationListener @Override public void onApplicationEvent(EnvironmentChangeEvent event) { for (String key : event.getKeys()) { - if (key.startsWith(properties.getMapping())) { + if (key.startsWith("zuul.route")) { resetRoutes(); return; } @@ -90,7 +90,7 @@ public class RouteLocator implements ApplicationListener } protected void addConfiguredRoutes(Map routes) { - Map routeEntries = properties.getRoute(); + Map routeEntries = properties.getRoutes(); for (Map.Entry entry : routeEntries.entrySet()) { String serviceId = entry.getKey(); String route = entry.getValue() ; diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulHandlerMapping.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulHandlerMapping.java index 6bb8c506..33995340 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulHandlerMapping.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulHandlerMapping.java @@ -58,8 +58,8 @@ public class ZuulHandlerMapping extends AbstractUrlHandlerMapping implements url = "/" + url; } - if (StringUtils.hasText(properties.getMapping())) { - url = properties.getMapping() + url; + if (StringUtils.hasText(properties.getPrefix())) { + url = properties.getPrefix() + url; if (!url.startsWith("/")) { url = "/" + url; } diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulProperties.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulProperties.java index 86e2acde..ad2d6a48 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulProperties.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulProperties.java @@ -15,9 +15,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @Data @ConfigurationProperties("zuul") public class ZuulProperties { - private String mapping = ""; - private boolean stripMapping = false; - private Map route = new HashMap(); + private String prefix = ""; + private boolean stripPrefix = false; + private Map routes = new HashMap(); private boolean addProxyHeaders = true; private List ignoredServices = Collections.emptyList(); } diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java index dba24d39..5f6d3d0b 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java @@ -57,10 +57,10 @@ public class PreDecorationFilter extends ZuulFilter { String requestURI = ctx.getRequest().getRequestURI(); - String proxyMapping = properties.getMapping(); + String proxyMapping = properties.getPrefix(); final String uriPart; - if (StringUtils.hasText(proxyMapping) && properties.isStripMapping() + if (StringUtils.hasText(proxyMapping) && properties.isStripPrefix() && requestURI.startsWith(proxyMapping)) { // TODO: better strategy? uriPart = requestURI.substring(proxyMapping.length()); diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/RouteLocatorTests.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/RouteLocatorTests.java index 196755ba..1e4d8add 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/RouteLocatorTests.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/RouteLocatorTests.java @@ -41,7 +41,22 @@ public class RouteLocatorTests { public void testGetRoutes() { ZuulProperties properties = new ZuulProperties(); RouteLocator routeLocator = new RouteLocator(this.discovery, properties); - properties.getRoute().put(ASERVICE, "/"+ASERVICE + "/**"); + properties.getRoutes().put(ASERVICE, "/"+ASERVICE + "/**"); + + Map routesMap = routeLocator.getRoutes(); + + assertNotNull("routesMap was null", routesMap); + assertFalse("routesMap was empty", routesMap.isEmpty()); + assertMapping(routesMap, ASERVICE); + } + + @Test + public void testGetRoutesWithMapping() { + ZuulProperties properties = new ZuulProperties(); + RouteLocator routeLocator = new RouteLocator(this.discovery, properties); + properties.getRoutes().put(ASERVICE, "/"+ASERVICE + "/**"); + // Prefix doesn't have any impact on the routes (it's used in the filter) + properties.setPrefix("/foo"); Map routesMap = routeLocator.getRoutes(); @@ -54,7 +69,7 @@ public class RouteLocatorTests { public void testGetPhysicalRoutes() { ZuulProperties properties = new ZuulProperties(); RouteLocator routeLocator = new RouteLocator(this.discovery, properties); - properties.getRoute().put("http://" + ASERVICE, "/"+ASERVICE + "/**"); + properties.getRoutes().put("http://" + ASERVICE, "/"+ASERVICE + "/**"); Map routesMap = routeLocator.getRoutes(); diff --git a/spring-cloud-netflix-core/src/test/resources/application.yml b/spring-cloud-netflix-core/src/test/resources/application.yml index f8f7260f..ec5e90c4 100644 --- a/spring-cloud-netflix-core/src/test/resources/application.yml +++ b/spring-cloud-netflix-core/src/test/resources/application.yml @@ -17,8 +17,8 @@ endpoints: health: sensitive: false zuul: - #mapping: /api - #strip-mapping: true - route: + #prefix: /api + #strip-prefix: true + routes: testclient: /testing123/** http://localhost:8081: /stores/**