Use RouteLocator interface.

fixes gh-1030
parent c3f12106
......@@ -76,7 +76,7 @@ public class ZuulConfiguration {
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnMissingBean(RouteLocator.class)
public RouteLocator routeLocator() {
return new SimpleRouteLocator(this.server.getServletPrefix(),
this.zuulProperties);
......
......@@ -135,7 +135,7 @@ public class ZuulProxyConfiguration extends ZuulConfiguration {
protected static class RoutesEndpointConfiguration {
@Bean
public RoutesEndpoint zuulEndpoint(DiscoveryClientRouteLocator routeLocator) {
public RoutesEndpoint zuulEndpoint(RouteLocator routeLocator) {
return new RoutesEndpoint(routeLocator);
}
......
......@@ -24,15 +24,20 @@ import javax.servlet.http.HttpServletRequest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.netflix.ribbon.StaticServerList;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.route.RestClientRibbonCommand;
import org.springframework.cloud.netflix.zuul.filters.route.RestClientRibbonCommandFactory;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext;
......@@ -82,6 +87,9 @@ import lombok.SneakyThrows;
@DirtiesContext
public class SampleZuulProxyApplicationTests extends ZuulProxyTestBase {
@Autowired
RouteLocator routeLocator;
@Test
public void simpleHostRouteWithTrailingSlash() {
this.routes.addRoute("/self/**", "http://localhost:" + this.port + "/");
......@@ -191,6 +199,12 @@ public class SampleZuulProxyApplicationTests extends ZuulProxyTestBase {
this.ribbonCommandFactory instanceof SampleZuulProxyApplication.MyRibbonCommandFactory);
}
@Test
public void routeLocatorOverridden() {
assertTrue("routeLocator not a MyRouteLocator",
this.routeLocator instanceof SampleZuulProxyApplication.MyRouteLocator);
}
}
// Don't use @SpringBootApplication because we don't want to component scan
......@@ -238,6 +252,11 @@ class SampleZuulProxyApplication extends ZuulProxyTestBase.AbstractZuulProxyAppl
return new MyRibbonCommandFactory(clientFactory);
}
@Bean
public RouteLocator routeLocator(DiscoveryClient discoveryClient, ZuulProperties zuulProperties) {
return new MyRouteLocator("/", discoveryClient, zuulProperties);
}
public static void main(String[] args) {
SpringApplication.run(SampleZuulProxyApplication.class, args);
}
......@@ -299,4 +318,11 @@ class SampleZuulProxyApplication extends ZuulProxyTestBase.AbstractZuulProxyAppl
}
}
static class MyRouteLocator extends DiscoveryClientRouteLocator {
public MyRouteLocator(String servletPath, DiscoveryClient discovery, ZuulProperties properties) {
super(servletPath, discovery, properties);
}
}
}
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