From 76d0c018eec80ad5a0a54540e1a7269e574c3379 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 20 Mar 2015 20:19:34 +0200 Subject: [PATCH] Ensure ZuulProperties.servletPath is applied to routes Fixes gh-271, fixes gh-272 --- .../netflix/zuul/filters/ProxyRouteLocator.java | 13 ++++++++++++- .../zuul/FormZuulServletProxyApplicationTests.java | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ProxyRouteLocator.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ProxyRouteLocator.java index 1516e75c..c9115018 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ProxyRouteLocator.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ProxyRouteLocator.java @@ -56,7 +56,13 @@ public class ProxyRouteLocator implements RouteLocator { public ProxyRouteLocator(String servletPath, DiscoveryClient discovery, ZuulProperties properties) { - this.servletPath = servletPath; + if (StringUtils.hasText(servletPath)) { // a servletPath is passed explicitly + this.servletPath = servletPath; + } else { + //set Zuul servlet path + this.servletPath = properties.getServletPath() != null? properties.getServletPath() : ""; + } + this.discovery = discovery; this.properties = properties; } @@ -89,17 +95,22 @@ public class ProxyRouteLocator implements RouteLocator { } public ProxyRouteSpec getMatchingRoute(String path) { + log.info("Finding route for path: " + path); + String location = null; String targetPath = null; String id = null; String prefix = this.properties.getPrefix(); + log.debug("servletPath=" + this.servletPath); if (StringUtils.hasText(this.servletPath) && !this.servletPath.equals("/") && path.startsWith(this.servletPath)) { path = path.substring(this.servletPath.length()); } + log.debug("path=" + path); Boolean retryable = this.properties.getRetryable(); for (Entry entry : this.routes.get().entrySet()) { String pattern = entry.getKey(); + log.debug("Matching pattern:" + pattern); if (this.pathMatcher.match(pattern, path)) { ZuulRoute route = entry.getValue(); id = route.getId(); diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/FormZuulServletProxyApplicationTests.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/FormZuulServletProxyApplicationTests.java index 53855a25..0ddf9175 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/FormZuulServletProxyApplicationTests.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/FormZuulServletProxyApplicationTests.java @@ -65,7 +65,7 @@ import static org.junit.Assert.assertEquals; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = FormZuulServletProxyApplication.class) @WebAppConfiguration -@IntegrationTest({ "server.port:0", "zuul.routes.simple:/zuul/simple/**" }) +@IntegrationTest({ "server.port:0", "zuul.routes.simple:/simple/**" }) @DirtiesContext public class FormZuulServletProxyApplicationTests {