Commit 98e1ac73 by Dave Syer

Add fullPath as convenience property on Route

More often than not what Route.path was used it had to be concatenated with the prefix. This change just encapsulates that concern in the Route itself.
parent f9fc8ba8
......@@ -70,7 +70,7 @@ public class RoutesEndpoint implements MvcEndpoint, ApplicationEventPublisherAwa
public Map<String, String> getRoutes() {
Map<String, String> map = new LinkedHashMap<>();
for (Route route : this.routes.getRoutes()) {
map.put(route.getPath(), route.getLocation());
map.put(route.getFullPath(), route.getLocation());
}
return map;
}
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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);
}
}
}
......
......@@ -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();
}
}
......
......@@ -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();
}
}
......
......@@ -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<Route> 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;
}
......
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