only update route location if location is empty. Fixes bug introduced in 18b346def1

This commit is contained in:
Spencer Gibb
2015-02-09 21:08:21 -07:00
parent 18b346def1
commit 24a06ca630
3 changed files with 24 additions and 6 deletions

View File

@@ -156,9 +156,12 @@ public class ProxyRouteLocator implements RouteLocator {
if (staticServices.containsKey(serviceId)
&& staticServices.get(serviceId).getUrl() == null) {
// Explicitly configured with no URL, cannot be ignored
// all static routes are already in routesMap, just update
// all static routes are already in routesMap
// Update location using serviceId if location is null
ZuulRoute staticRoute = staticServices.get(serviceId);
staticRoute.updateRoute(key, serviceId);
if (!StringUtils.hasText(staticRoute.getLocation())) {
staticRoute.setLocation(serviceId);
}
}
if (!PatternMatchUtils.simpleMatch(ignored, serviceId)
&& !routesMap.containsKey(key)) {

View File

@@ -102,10 +102,6 @@ public class ZuulProperties {
}
public ZuulRoute(String path, String location) {
updateRoute(path, location);
}
public void updateRoute(String path, String location) {
this.id = extractId(path);
this.path = path;
setLocation(location);

View File

@@ -276,6 +276,25 @@ public class ProxyRouteLocatorTests {
assertEquals("retryable is wrong", Boolean.TRUE, actual.getRetryable());
}
@Test
public void testIgnoredRouteNonServiceIdPathRemains() {
//This is how you setup a route defined like zuul.proxy.route.foo=/**
ZuulRoute route = new ZuulRoute("/**", "foo");
route.setId("foo");
this.properties.getRoutes().put("foo", route);
ProxyRouteLocator routeLocator = new ProxyRouteLocator("/", this.discovery,
this.properties);
this.properties.setIgnoredServices(Collections.singletonList("*"));
given(this.discovery.getServices()).willReturn(Collections.singletonList("foo"));
LinkedHashMap<String, ZuulRoute> routes = routeLocator.locateRoutes();
ZuulRoute actual = routes.get("/**");
assertNotNull("routes ignored foo", actual);
assertEquals("id is wrong", "foo", actual.getId());
assertEquals("location is wrong", "foo", actual.getServiceId());
assertEquals("path is wrong", "/**", actual.getPath());
}
@Test
public void testIgnoredRouteIncludedIfConfiguredAndNotDiscovered() {
this.properties.getRoutes()