Browse Source

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.
pull/6/head
Dave Syer 9 years ago
parent
commit
98e1ac7375
  1. 2
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/RoutesEndpoint.java
  2. 17
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/Route.java
  3. 5
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java
  4. 2
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/web/ZuulHandlerMapping.java
  5. 2
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyAppTestsWithHttpClient.java
  6. 2
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java
  7. 6
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/discovery/DiscoveryClientRouteLocatorTests.java

2
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/RoutesEndpoint.java

@ -70,7 +70,7 @@ public class RoutesEndpoint implements MvcEndpoint, ApplicationEventPublisherAwa @@ -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;
}

17
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/Route.java

@ -16,15 +16,28 @@ @@ -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;

5
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 { @@ -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;
}

2
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/web/ZuulHandlerMapping.java

@ -95,7 +95,7 @@ public class ZuulHandlerMapping extends AbstractUrlHandlerMapping { @@ -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);
}
}
}

2
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyAppTestsWithHttpClient.java

@ -84,7 +84,7 @@ public class SampleZuulProxyAppTestsWithHttpClient { @@ -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();
}
}

2
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java

@ -90,7 +90,7 @@ public class SampleZuulProxyApplicationTests { @@ -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();
}
}

6
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; @@ -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 { @@ -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;
}

Loading…
Cancel
Save