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

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
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;
} }

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

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

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

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

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

@ -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/**

Loading…
Cancel
Save