Commit 18b346de by Spencer Gibb

update the serviceId and location for statically configured routes that are also…

update the serviceId and location for statically configured routes that are also part of serviceDiscovery. fixes gh-199
parent 96335e1d
......@@ -153,16 +153,17 @@ public class ProxyRouteLocator implements RouteLocator {
// Ignore specifically ignored services and those that were manually
// configured
String key = "/" + serviceId + "/**";
ZuulRoute route = new ZuulRoute(key, serviceId);
if (staticServices.containsKey(serviceId)
&& staticServices.get(serviceId).getUrl() == null) {
// Explicitly configured with no URL, cannot be ignored
routesMap.put(key, route);
// all static routes are already in routesMap, just update
ZuulRoute staticRoute = staticServices.get(serviceId);
staticRoute.updateRoute(key, serviceId);
}
if (!PatternMatchUtils.simpleMatch(ignored, serviceId)
&& !routesMap.containsKey(key)) {
// Not ignored
routesMap.put(key, route);
routesMap.put(key, new ZuulRoute(key, serviceId));
}
}
}
......
......@@ -102,6 +102,10 @@ 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);
......
......@@ -17,6 +17,7 @@
package org.springframework.cloud.netflix.zuul.filters;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Before;
......@@ -31,6 +32,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.MockitoAnnotations.initMocks;
......@@ -258,6 +260,23 @@ public class ProxyRouteLocatorTests {
}
@Test
public void testIgnoredRoutePropertiesRemain() {
ZuulRoute route = new ZuulRoute("/foo/**");
route.setStripPrefix(true);
route.setRetryable(Boolean.TRUE);
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(getMapping("foo"));
assertNotNull("routes ignored foo", actual);
assertTrue("stripPrefix is wrong", actual.isStripPrefix());
assertEquals("retryable is wrong", Boolean.TRUE, actual.getRetryable());
}
@Test
public void testIgnoredRouteIncludedIfConfiguredAndNotDiscovered() {
this.properties.getRoutes()
.put("foo", new ZuulRoute("/foo/**", "http://foo.com"));
......
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