Browse Source

Rename some Zuul config keys

zuul.route -> zuul.routes
zuul.mapping -> zuul.prefix
pull/6/head
Dave Syer 10 years ago
parent
commit
7e91b9ea21
  1. 4
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/RouteLocator.java
  2. 4
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulHandlerMapping.java
  3. 6
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulProperties.java
  4. 4
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java
  5. 19
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/RouteLocatorTests.java
  6. 6
      spring-cloud-netflix-core/src/test/resources/application.yml

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

@ -44,7 +44,7 @@ public class RouteLocator implements ApplicationListener<EnvironmentChangeEvent> @@ -44,7 +44,7 @@ public class RouteLocator implements ApplicationListener<EnvironmentChangeEvent>
@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<EnvironmentChangeEvent> @@ -90,7 +90,7 @@ public class RouteLocator implements ApplicationListener<EnvironmentChangeEvent>
}
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()) {
String serviceId = entry.getKey();
String route = entry.getValue() ;

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

@ -58,8 +58,8 @@ public class ZuulHandlerMapping extends AbstractUrlHandlerMapping implements @@ -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;
}

6
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; @@ -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<String,String> route = new HashMap<String, String>();
private String prefix = "";
private boolean stripPrefix = false;
private Map<String,String> routes = new HashMap<String, String>();
private boolean addProxyHeaders = true;
private List<String> ignoredServices = Collections.emptyList();
}

4
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 { @@ -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());

19
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/RouteLocatorTests.java

@ -41,7 +41,22 @@ public class RouteLocatorTests { @@ -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<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();
@ -54,7 +69,7 @@ public class RouteLocatorTests { @@ -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<String, String> routesMap = routeLocator.getRoutes();

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

@ -17,8 +17,8 @@ endpoints: @@ -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/**

Loading…
Cancel
Save