diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/RoutesEndpoint.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/RoutesEndpoint.java index ef33b9b7..920cb114 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/RoutesEndpoint.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/RoutesEndpoint.java @@ -70,7 +70,7 @@ public class RoutesEndpoint implements MvcEndpoint, ApplicationEventPublisherAwa public Map getRoutes() { Map map = new LinkedHashMap<>(); for (Route route : this.routes.getRoutes()) { - map.put(route.getPath(), route.getLocation()); + map.put(route.getFullPath(), route.getLocation()); } return map; } diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/Route.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/Route.java index 488fe280..71ead62f 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/Route.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/Route.java @@ -16,15 +16,28 @@ package org.springframework.cloud.netflix.zuul.filters; -import lombok.AllArgsConstructor; +import org.springframework.util.StringUtils; + import lombok.Data; @Data -@AllArgsConstructor public class Route { + public Route(String id, String path, String location, String prefix, + Boolean retryable) { + this.id = id; + this.prefix = StringUtils.hasText(prefix) ? prefix : ""; + this.path = path; + this.fullPath = prefix + path; + this.location = location; + this.retryable = retryable; + + } + private String id; + private String fullPath; + private String path; private String location; diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java index d5ce6fef..8296f076 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java @@ -81,8 +81,9 @@ public class PreDecorationFilter extends ZuulFilter { ctx.addOriginResponseHeader("X-Zuul-Service", location); } else if (location.startsWith("forward:")) { - ctx.set("forward.to", StringUtils.cleanPath( - location.substring("forward:".length()) + route.getPath())); + ctx.set("forward.to", + StringUtils.cleanPath(location.substring("forward:".length()) + + route.getPath())); ctx.setRouteHost(null); return null; } diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/web/ZuulHandlerMapping.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/web/ZuulHandlerMapping.java index 6835a01f..af81c9ae 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/web/ZuulHandlerMapping.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/web/ZuulHandlerMapping.java @@ -95,7 +95,7 @@ public class ZuulHandlerMapping extends AbstractUrlHandlerMapping { } else { for (Route route : routes) { - registerHandler(route.getPrefix() + route.getPath(), this.zuul); + registerHandler(route.getFullPath(), this.zuul); } } } diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyAppTestsWithHttpClient.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyAppTestsWithHttpClient.java index 369c8f4b..83409485 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyAppTestsWithHttpClient.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyAppTestsWithHttpClient.java @@ -84,7 +84,7 @@ public class SampleZuulProxyAppTestsWithHttpClient { private String getRoute(String path) { for (Route route : this.routes.getRoutes()) { - if (path.equals(route.getPrefix() + route.getPath())) { + if (path.equals(route.getFullPath())) { return route.getLocation(); } } diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java index bf2d4b5a..3a08e3ac 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java @@ -90,7 +90,7 @@ public class SampleZuulProxyApplicationTests { private String getRoute(String path) { for (Route route : this.routes.getRoutes()) { - if (path.equals(route.getPrefix() + route.getPath())) { + if (path.equals(route.getFullPath())) { return route.getLocation(); } } diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/discovery/DiscoveryClientRouteLocatorTests.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/discovery/DiscoveryClientRouteLocatorTests.java index 991d770d..39641acc 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/discovery/DiscoveryClientRouteLocatorTests.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/discovery/DiscoveryClientRouteLocatorTests.java @@ -29,7 +29,6 @@ import org.springframework.cloud.netflix.zuul.filters.Route; import org.springframework.cloud.netflix.zuul.filters.ZuulProperties; import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute; import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.util.StringUtils; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -590,10 +589,7 @@ public class DiscoveryClientRouteLocatorTests { private Route getRoute(List routes, String path) { for (Route route : routes) { - String pattern = route.getPath(); - if (StringUtils.hasText(route.getPrefix())) { - pattern = route.getPrefix() + route.getPath(); - } + String pattern = route.getFullPath(); if (path.equals(pattern)) { return route; }