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 { ...@@ -153,16 +153,17 @@ public class ProxyRouteLocator implements RouteLocator {
// Ignore specifically ignored services and those that were manually // Ignore specifically ignored services and those that were manually
// configured // configured
String key = "/" + serviceId + "/**"; String key = "/" + serviceId + "/**";
ZuulRoute route = new ZuulRoute(key, serviceId);
if (staticServices.containsKey(serviceId) if (staticServices.containsKey(serviceId)
&& staticServices.get(serviceId).getUrl() == null) { && staticServices.get(serviceId).getUrl() == null) {
// Explicitly configured with no URL, cannot be ignored // 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) if (!PatternMatchUtils.simpleMatch(ignored, serviceId)
&& !routesMap.containsKey(key)) { && !routesMap.containsKey(key)) {
// Not ignored // Not ignored
routesMap.put(key, route); routesMap.put(key, new ZuulRoute(key, serviceId));
} }
} }
} }
......
...@@ -102,6 +102,10 @@ public class ZuulProperties { ...@@ -102,6 +102,10 @@ public class ZuulProperties {
} }
public ZuulRoute(String path, String location) { public ZuulRoute(String path, String location) {
updateRoute(path, location);
}
public void updateRoute(String path, String location) {
this.id = extractId(path); this.id = extractId(path);
this.path = path; this.path = path;
setLocation(location); setLocation(location);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package org.springframework.cloud.netflix.zuul.filters; package org.springframework.cloud.netflix.zuul.filters;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.junit.Before; import org.junit.Before;
...@@ -31,6 +32,7 @@ import static org.junit.Assert.assertEquals; ...@@ -31,6 +32,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.MockitoAnnotations.initMocks; import static org.mockito.MockitoAnnotations.initMocks;
...@@ -258,6 +260,23 @@ public class ProxyRouteLocatorTests { ...@@ -258,6 +260,23 @@ public class ProxyRouteLocatorTests {
} }
@Test @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() { public void testIgnoredRouteIncludedIfConfiguredAndNotDiscovered() {
this.properties.getRoutes() this.properties.getRoutes()
.put("foo", new ZuulRoute("/foo/**", "http://foo.com")); .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