Commit 7e91b9ea by Dave Syer

Rename some Zuul config keys

zuul.route -> zuul.routes zuul.mapping -> zuul.prefix
parent e272f8d6
...@@ -44,7 +44,7 @@ public class RouteLocator implements ApplicationListener<EnvironmentChangeEvent> ...@@ -44,7 +44,7 @@ public class RouteLocator implements ApplicationListener<EnvironmentChangeEvent>
@Override @Override
public void onApplicationEvent(EnvironmentChangeEvent event) { public void onApplicationEvent(EnvironmentChangeEvent event) {
for (String key : event.getKeys()) { for (String key : event.getKeys()) {
if (key.startsWith(properties.getMapping())) { if (key.startsWith("zuul.route")) {
resetRoutes(); resetRoutes();
return; return;
} }
...@@ -90,7 +90,7 @@ public class RouteLocator implements ApplicationListener<EnvironmentChangeEvent> ...@@ -90,7 +90,7 @@ public class RouteLocator implements ApplicationListener<EnvironmentChangeEvent>
} }
protected void addConfiguredRoutes(Map<String, String> routes) { protected void addConfiguredRoutes(Map<String, String> routes) {
Map<String, String> routeEntries = properties.getRoute(); Map<String, String> routeEntries = properties.getRoutes();
for (Map.Entry<String, String> entry : routeEntries.entrySet()) { for (Map.Entry<String, String> entry : routeEntries.entrySet()) {
String serviceId = entry.getKey(); String serviceId = entry.getKey();
String route = entry.getValue() ; String route = entry.getValue() ;
......
...@@ -58,8 +58,8 @@ public class ZuulHandlerMapping extends AbstractUrlHandlerMapping implements ...@@ -58,8 +58,8 @@ public class ZuulHandlerMapping extends AbstractUrlHandlerMapping implements
url = "/" + url; url = "/" + url;
} }
if (StringUtils.hasText(properties.getMapping())) { if (StringUtils.hasText(properties.getPrefix())) {
url = properties.getMapping() + url; url = properties.getPrefix() + url;
if (!url.startsWith("/")) { if (!url.startsWith("/")) {
url = "/" + url; url = "/" + url;
} }
......
...@@ -15,9 +15,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -15,9 +15,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@Data @Data
@ConfigurationProperties("zuul") @ConfigurationProperties("zuul")
public class ZuulProperties { public class ZuulProperties {
private String mapping = ""; private String prefix = "";
private boolean stripMapping = false; private boolean stripPrefix = false;
private Map<String,String> route = new HashMap<String, String>(); private Map<String,String> routes = new HashMap<String, String>();
private boolean addProxyHeaders = true; private boolean addProxyHeaders = true;
private List<String> ignoredServices = Collections.emptyList(); private List<String> ignoredServices = Collections.emptyList();
} }
...@@ -57,10 +57,10 @@ public class PreDecorationFilter extends ZuulFilter { ...@@ -57,10 +57,10 @@ public class PreDecorationFilter extends ZuulFilter {
String requestURI = ctx.getRequest().getRequestURI(); String requestURI = ctx.getRequest().getRequestURI();
String proxyMapping = properties.getMapping(); String proxyMapping = properties.getPrefix();
final String uriPart; final String uriPart;
if (StringUtils.hasText(proxyMapping) && properties.isStripMapping() if (StringUtils.hasText(proxyMapping) && properties.isStripPrefix()
&& requestURI.startsWith(proxyMapping)) { && requestURI.startsWith(proxyMapping)) {
// TODO: better strategy? // TODO: better strategy?
uriPart = requestURI.substring(proxyMapping.length()); uriPart = requestURI.substring(proxyMapping.length());
......
...@@ -41,7 +41,22 @@ public class RouteLocatorTests { ...@@ -41,7 +41,22 @@ public class RouteLocatorTests {
public void testGetRoutes() { public void testGetRoutes() {
ZuulProperties properties = new ZuulProperties(); ZuulProperties properties = new ZuulProperties();
RouteLocator routeLocator = new RouteLocator(this.discovery, properties); RouteLocator routeLocator = new RouteLocator(this.discovery, properties);
properties.getRoute().put(ASERVICE, "/"+ASERVICE + "/**"); properties.getRoutes().put(ASERVICE, "/"+ASERVICE + "/**");
Map<String, String> 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<String, String> routesMap = routeLocator.getRoutes(); Map<String, String> routesMap = routeLocator.getRoutes();
...@@ -54,7 +69,7 @@ public class RouteLocatorTests { ...@@ -54,7 +69,7 @@ public class RouteLocatorTests {
public void testGetPhysicalRoutes() { public void testGetPhysicalRoutes() {
ZuulProperties properties = new ZuulProperties(); ZuulProperties properties = new ZuulProperties();
RouteLocator routeLocator = new RouteLocator(this.discovery, properties); RouteLocator routeLocator = new RouteLocator(this.discovery, properties);
properties.getRoute().put("http://" + ASERVICE, "/"+ASERVICE + "/**"); properties.getRoutes().put("http://" + ASERVICE, "/"+ASERVICE + "/**");
Map<String, String> routesMap = routeLocator.getRoutes(); Map<String, String> routesMap = routeLocator.getRoutes();
......
...@@ -17,8 +17,8 @@ endpoints: ...@@ -17,8 +17,8 @@ endpoints:
health: health:
sensitive: false sensitive: false
zuul: zuul:
#mapping: /api #prefix: /api
#strip-mapping: true #strip-prefix: true
route: routes:
testclient: /testing123/** testclient: /testing123/**
http://localhost:8081: /stores/** http://localhost:8081: /stores/**
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment