Commit 3ecd9cb0 by Dave Syer

Move discovery related route locator stuff into a new package

parent 9161c54c
......@@ -2,6 +2,7 @@
:github-repo: spring-cloud/spring-cloud-netflix
:github-raw: http://raw.github.com/{github-repo}/{github-tag}
:github-code: http://github.com/{github-repo}/tree/{github-tag}
:all: {asterisk}{asterisk}
= Spring Cloud Netflix
include::intro.adoc[]
......@@ -1055,7 +1056,7 @@ and the serviceId independently:
This means that http calls to "/myusers" get forwarded to the
"users_service" service. The route has to have a "path" which can be
specified as an ant-style pattern, so "/myusers/\*" only matches one
level, but "/myusers/**" matches hierarchically.
level, but "/myusers/{all}" matches hierarchically.
The location of the backend can be specified as either a "serviceId"
(for a Eureka service) or a "url" (for a physical location), e.g.
......@@ -1093,25 +1094,28 @@ users:
listOfServers: example.com,google.com
----
You can provide convention between serviceId and routes using regexmapper.
It uses regular expression named group to extract variables from serviceId and inject them
into a route pattern.
You can provide convention between serviceId and routes using
regexmapper. It uses regular expression named group to extract
variables from serviceId and inject them into a route pattern.
.application.yml
[source,yaml]
.ApplicationConfiguration.java
[source,java]
----
zuul:
regexMapper:
enabled: true
servicePattern: "(?<name>^.+)-(?<version>v.+$)"
routePattern: "${version}/${name}"
@Bean
public PatternServiceRouteMapper serviceRouteMapper() {
retuen new PatternServiceRouteMapper(
"(?<name>^.+)-(?<version>v.+$)",
"${version}/${name}");
}
----
This means that a serviceId "myusers-v1" will be mapped to route "/v1/myusers/**".
Any regular expression is accepted but all named group must be present in both servicePattern and routePattern.
If servicePattern do not match a serviceId, the default behavior is used. In exemple above,
a serviceId "myusers" will be mapped to route "/myusers/**" (no version detected)
These feature is disable by default and is only applied to discovered services.
This means that a serviceId "myusers-v1" will be mapped to route
"/v1/myusers/{all}". Any regular expression is accepted but all named
group must be present in both servicePattern and routePattern. If
servicePattern do not match a serviceId, the default behavior is
used. In exemple above, a serviceId "myusers" will be mapped to route
"/myusers/{all}" (no version detected) These feature is disable by
default and is only applied to discovered services.
To add a prefix to all mappings, set `zuul.prefix` to a value, such as
`/api`. The proxy prefix is stripped from the request before the
......@@ -1145,7 +1149,7 @@ above).
An application with the `@EnableZuulProxy` could act as a standalone
server if you set a default route ("/"), for example `zuul.route.home:
/` would route all traffic (i.e. "/**") to the "home" service.
/` would route all traffic (i.e. "/{all}") to the "home" service.
If more fine-grained ignoring is needed, you can specify specific patterns to ignore.
These patterns are being evaluated at the start of the route location process, which
......@@ -1195,10 +1199,10 @@ Example configuration:
In this example we are strangling the "legacy" app which is mapped to
all requests that do not match one of the other patterns. Paths in
`/first/**` have been extracted into a new service with an external
URL. And paths in `/second/**` are forwared so they can be handled
`/first/{all}` have been extracted into a new service with an external
URL. And paths in `/second/{all}` are forwared so they can be handled
locally, e.g. with a normal Spring `@RequestMapping`. Paths in
`/third/**` are also forwarded, but with a different prefix
`/third/{all}` are also forwarded, but with a different prefix
(i.e. `/third/foo` is forwarded to `/3rd/foo`).
NOTE: The ignored pattterns aren't completely ignored, they just
......@@ -1211,8 +1215,8 @@ If you `@EnableZuulProxy` you can use the proxy paths to
upload files and it should just work as long as the files
are small. For large files there is an alternative path
which bypasses the Spring `DispatcherServlet` (to
avoid multipart processing) in "/zuul/*". I.e. if
`zuul.routes.customers=/customers/**` then you can
avoid multipart processing) in "/zuul/{asterisk}". I.e. if
`zuul.routes.customers=/customers/{all}` then you can
POST large files to "/zuul/customers/*". The servlet
path is externalized via `zuul.servletPath`. Extremely
large files will also require elevated timeout settings
......@@ -1243,9 +1247,10 @@ use `@EnableZuulServer` (instead of `@EnableZuulProxy`). Any beans that you add
will be installed automatically, as they are with `@EnableZuulProxy`, but without any of the proxy filters being added
automatically.
In this case the routes into the Zuul server are
still specified by configuring "zuul.routes.*", but there is no service discovery and no proxying, so the
"serviceId" and "url" settings are ignored. For example:
In this case the routes into the Zuul server are still specified by
configuring "zuul.routes.{asterisk}", but there is no service
discovery and no proxying, so the "serviceId" and "url" settings are
ignored. For example:
.application.yml
[source,yaml]
......@@ -1255,7 +1260,7 @@ still specified by configuring "zuul.routes.*", but there is no service discover
api: /api/**
----
maps all paths in "/api/**" to the Zuul filter chain.
maps all paths in "/api/{all}" to the Zuul filter chain.
=== Disable Zuul Filters
......
......@@ -21,7 +21,6 @@ import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.actuate.trace.TraceRepository;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.cloud.client.actuator.HasFeatures;
import org.springframework.cloud.client.discovery.DiscoveryClient;
......@@ -31,13 +30,12 @@ import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent;
import org.springframework.cloud.client.discovery.event.ParentHeartbeatEvent;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper;
import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ServiceRouteMapper;
import org.springframework.cloud.netflix.zuul.filters.SimpleServiceRouteMapper;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.discovery.ServiceRouteMapper;
import org.springframework.cloud.netflix.zuul.filters.discovery.SimpleServiceRouteMapper;
import org.springframework.cloud.netflix.zuul.filters.pre.PreDecorationFilter;
import org.springframework.cloud.netflix.zuul.filters.regex.RegExServiceRouteMapper;
import org.springframework.cloud.netflix.zuul.filters.route.RestClientRibbonCommandFactory;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter;
......@@ -81,9 +79,9 @@ public class ZuulProxyConfiguration extends ZuulConfiguration {
@Bean
@Override
@ConditionalOnMissingBean(RouteLocator.class)
public ProxyRouteLocator routeLocator() {
return new ProxyRouteLocator(this.server.getServletPrefix(), this.discovery,
this.zuulProperties, this.serviceRouteMapper);
public DiscoveryClientRouteLocator routeLocator() {
return new DiscoveryClientRouteLocator(this.server.getServletPrefix(),
this.discovery, this.zuulProperties, this.serviceRouteMapper);
}
@Bean
......@@ -126,24 +124,10 @@ public class ZuulProxyConfiguration extends ZuulConfiguration {
return new ZuulDiscoveryRefreshListener();
}
@Configuration
@ConditionalOnProperty(name = "zuul.regexMapper.enabled", matchIfMissing = false)
protected static class RegexServiceRouteMapperConfiguration {
@Bean
public ServiceRouteMapper serviceRouteMapper(ZuulProperties props) {
return new RegExServiceRouteMapper(props.getRegexMapper().getServicePattern(),
props.getRegexMapper().getRoutePattern());
}
}
@Configuration
@Bean
@ConditionalOnMissingBean(ServiceRouteMapper.class)
protected static class SimpleServiceRouteMapperConfiguration {
@Bean
public ServiceRouteMapper serviceRouteMapper() {
return new SimpleServiceRouteMapper();
}
public ServiceRouteMapper serviceRouteMapper() {
return new SimpleServiceRouteMapper();
}
@Configuration
......@@ -151,7 +135,7 @@ public class ZuulProxyConfiguration extends ZuulConfiguration {
protected static class RoutesEndpointConfiguration {
@Bean
public RoutesEndpoint zuulEndpoint(ProxyRouteLocator routeLocator) {
public RoutesEndpoint zuulEndpoint(DiscoveryClientRouteLocator routeLocator) {
return new RoutesEndpoint(routeLocator);
}
......
......@@ -14,9 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.netflix.zuul;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
package org.springframework.cloud.netflix.zuul.filters;
/**
* Interface for a route locator that can be refreshed if routes change.
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.netflix.zuul.filters;
package org.springframework.cloud.netflix.zuul.filters.discovery;
import java.util.Collection;
import java.util.LinkedHashMap;
......@@ -25,7 +25,10 @@ import java.util.concurrent.atomic.AtomicReference;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.zuul.RefreshableRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.RefreshableRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.Route;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
......@@ -35,10 +38,14 @@ import org.springframework.util.StringUtils;
import lombok.extern.apachecommons.CommonsLog;
/**
* A {@link RouteLocator} that combines static, configured routes with those from a
* {@link DiscoveryClient}. The discovery client takes precedence.
*
* @author Spencer Gibb
* @author Dave Syer
*/
@CommonsLog
public class ProxyRouteLocator implements RefreshableRouteLocator {
public class DiscoveryClientRouteLocator implements RefreshableRouteLocator {
public static final String DEFAULT_ROUTE = "/**";
......@@ -56,7 +63,7 @@ public class ProxyRouteLocator implements RefreshableRouteLocator {
private ServiceRouteMapper serviceRouteMapper;
public ProxyRouteLocator(String servletPath, DiscoveryClient discovery,
public DiscoveryClientRouteLocator(String servletPath, DiscoveryClient discovery,
ZuulProperties properties) {
if (StringUtils.hasText(servletPath)) { // a servletPath is passed explicitly
this.servletPath = servletPath;
......@@ -81,7 +88,7 @@ public class ProxyRouteLocator implements RefreshableRouteLocator {
this.properties = properties;
}
public ProxyRouteLocator(String servletPath, DiscoveryClient discovery,
public DiscoveryClientRouteLocator(String servletPath, DiscoveryClient discovery,
ZuulProperties properties, ServiceRouteMapper serviceRouteMapper) {
this(servletPath, discovery, properties);
this.serviceRouteMapper = serviceRouteMapper;
......
package org.springframework.cloud.netflix.zuul.filters.regex;
package org.springframework.cloud.netflix.zuul.filters.discovery;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.cloud.netflix.zuul.filters.ServiceRouteMapper;
import org.springframework.util.StringUtils;
/**
......@@ -12,12 +11,15 @@ import org.springframework.util.StringUtils;
* This service route mapper use Java 7 RegEx named group feature to rewrite a discovered
* service Id into a route.
*
* Ex : If we want to map service Id [rest-service-v1] to /v1/rest-service/** route
* service pattern : "(?<name>.*)-(?<version>v.*$)" route pattern : "${version}/${name}"
* Ex : If we want to map service Id <code>[rest-service-v1]</code> to
* <code>/v1/rest-service/**</code> route service pattern :
* <code>"(?<name>.*)-(?<version>v.*$)"</code> route pattern :
* <code>"${version}/${name}"</code>
*
* /!\ This implementation use Matcher.replaceFirst so only one match will be replace.
* This implementation uses <code>Matcher.replaceFirst</code> so only one match will be
* replaced.
*/
public class RegExServiceRouteMapper implements ServiceRouteMapper {
public class PatternServiceRouteMapper implements ServiceRouteMapper {
/**
* A RegExp Pattern that extract needed information from a service ID. Ex :
......@@ -30,7 +32,7 @@ public class RegExServiceRouteMapper implements ServiceRouteMapper {
*/
private String routePattern;
public RegExServiceRouteMapper(String servicePattern, String routePattern) {
public PatternServiceRouteMapper(String servicePattern, String routePattern) {
this.servicePattern = Pattern.compile(servicePattern);
this.routePattern = routePattern;
}
......@@ -45,8 +47,8 @@ public class RegExServiceRouteMapper implements ServiceRouteMapper {
*/
@Override
public String apply(String serviceId) {
Matcher matcher = servicePattern.matcher(serviceId);
String route = matcher.replaceFirst(routePattern);
Matcher matcher = this.servicePattern.matcher(serviceId);
String route = matcher.replaceFirst(this.routePattern);
route = cleanRoute(route);
return (StringUtils.hasText(route) ? route : serviceId);
}
......
package org.springframework.cloud.netflix.zuul.filters;
package org.springframework.cloud.netflix.zuul.filters.discovery;
/**
* Provide a way to apply convention between routes and discovered services name.
......
......@@ -21,7 +21,7 @@ import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.cloud.netflix.zuul.RefreshableRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.RefreshableRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
import org.springframework.util.PatternMatchUtils;
import org.springframework.web.servlet.handler.AbstractUrlHandlerMapping;
......
......@@ -25,8 +25,8 @@ 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.netflix.zuul.filters.ProxyRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
......@@ -53,7 +53,7 @@ public class ContextPathZuulProxyApplicationTests {
private int port;
@Autowired
private ProxyRouteLocator routes;
private DiscoveryClientRouteLocator routes;
@Autowired
private RoutesEndpoint endpoint;
......
......@@ -13,7 +13,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.StaticServerList;
import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
......@@ -51,7 +51,7 @@ public class RetryableZuulProxyApplicationTests {
private int port;
@Autowired
private ProxyRouteLocator routes;
private DiscoveryClientRouteLocator routes;
@Autowired
private RoutesEndpoint endpoint;
......
......@@ -33,8 +33,8 @@ import org.springframework.boot.test.TestRestTemplate;
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.zuul.filters.ProxyRouteLocator;
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.RibbonCommandFactory;
import org.springframework.cloud.netflix.zuul.filters.route.apache.HttpClientRibbonCommandFactory;
import org.springframework.context.annotation.Bean;
......@@ -73,7 +73,7 @@ public class SampleZuulProxyAppTestsWithHttpClient {
private int port;
@Autowired
private ProxyRouteLocator routes;
private DiscoveryClientRouteLocator routes;
@Autowired
private RoutesEndpoint endpoint;
......
......@@ -35,8 +35,8 @@ 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.ProxyRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.route.RestClientRibbonCommandFactory;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory;
import org.springframework.context.annotation.Bean;
......@@ -77,7 +77,7 @@ public class SampleZuulProxyApplicationTests {
private int port;
@Autowired
private ProxyRouteLocator routes;
private DiscoveryClientRouteLocator routes;
@Autowired
private RoutesEndpoint endpoint;
......
......@@ -25,8 +25,8 @@ 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.netflix.zuul.filters.ProxyRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
......@@ -53,7 +53,7 @@ public class ServletPathZuulProxyApplicationTests {
private int port;
@Autowired
private ProxyRouteLocator routes;
private DiscoveryClientRouteLocator routes;
@Autowired
private RoutesEndpoint endpoint;
......
......@@ -17,6 +17,7 @@ import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.netflix.zuul.RoutesEndpoint;
import org.springframework.cloud.netflix.zuul.ZuulProxyConfiguration;
import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -54,7 +55,7 @@ public class CustomHostRoutingFilterTests {
private int port;
@Autowired
private ProxyRouteLocator routes;
private DiscoveryClientRouteLocator routes;
@Autowired
private RoutesEndpoint endpoint;
......
package org.springframework.cloud.netflix.zuul.filters.regex;
package org.springframework.cloud.netflix.zuul.filters.discovery;
import java.util.ArrayList;
import java.util.List;
......@@ -17,7 +17,6 @@ import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.StaticServerList;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.netflix.zuul.RoutesEndpoint;
import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
......@@ -38,7 +37,7 @@ import com.netflix.loadbalancer.ServerList;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.springframework.cloud.netflix.zuul.filters.regex.RegExServiceRouteMapperIntegrationTests.SERVICE_ID;
import static org.springframework.cloud.netflix.zuul.filters.discovery.PatternServiceRouteMapperIntegrationTests.SERVICE_ID;
/**
* @author Stéphane Leroy
......@@ -47,12 +46,9 @@ import static org.springframework.cloud.netflix.zuul.filters.regex.RegExServiceR
@SpringApplicationConfiguration(classes = SampleCustomZuulProxyApplication.class)
@WebIntegrationTest(value = { "spring.application.name=regex-test-application",
"spring.jmx.enabled=true" }, randomPort = true)
@TestPropertySource(properties = { "eureka.client.enabled=false",
"zuul.regexMapper.enabled=true",
"zuul.regexMapper.servicePattern=(?<domain>^.+)-(?<name>.+)-(?<version>v.+$)",
"zuul.regexMapper.routePattern=${version}/${domain}/${name}" })
@TestPropertySource(properties = "eureka.client.enabled=false")
@DirtiesContext
public class RegExServiceRouteMapperIntegrationTests {
public class PatternServiceRouteMapperIntegrationTests {
protected static final String SERVICE_ID = "domain-service-v1";
......@@ -60,14 +56,14 @@ public class RegExServiceRouteMapperIntegrationTests {
private int port;
@Autowired
private ProxyRouteLocator routes;
private DiscoveryClientRouteLocator routes;
@Autowired
private RoutesEndpoint endpoint;
@Test
public void getRegexMappedService() {
endpoint.reset();
this.endpoint.reset();
ResponseEntity<String> result = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/v1/domain/service/get/1",
HttpMethod.GET, new HttpEntity<>((Void) null), String.class);
......@@ -78,7 +74,7 @@ public class RegExServiceRouteMapperIntegrationTests {
@Test
public void getStaticRoute() {
this.routes.addRoute("/self/**", "http://localhost:" + this.port);
endpoint.reset();
this.endpoint.reset();
ResponseEntity<String> result = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/self/get/1", HttpMethod.GET,
new HttpEntity<>((Void) null), String.class);
......@@ -109,6 +105,13 @@ class SampleCustomZuulProxyApplication {
return "Get " + id;
}
@Bean
public PatternServiceRouteMapper serviceRouteMapper() {
return new PatternServiceRouteMapper(
"(?<domain>^.+)-(?<name>.+)-(?<version>v.+$)",
"${version}/${domain}/${name}");
}
public static void main(String[] args) {
SpringApplication.run(SampleCustomZuulProxyApplication.class, args);
}
......
package org.springframework.cloud.netflix.zuul.filters.regex;
package org.springframework.cloud.netflix.zuul.filters.discovery;
import org.junit.Test;
import org.springframework.cloud.netflix.zuul.filters.discovery.PatternServiceRouteMapper;
import static org.junit.Assert.assertEquals;
/**
* @author Stéphane Leroy
*/
public class RegExServiceRouteMapperTests {
public class PatternServiceRouteMapperTests {
/**
* Service pattern that follow convention {domain}-{name}-{version}. The name is
......@@ -18,7 +19,7 @@ public class RegExServiceRouteMapperTests {
@Test
public void test_return_mapped_route_if_serviceid_matches() {
RegExServiceRouteMapper toTest = new RegExServiceRouteMapper(SERVICE_PATTERN,
PatternServiceRouteMapper toTest = new PatternServiceRouteMapper(SERVICE_PATTERN,
ROUTE_PATTERN);
assertEquals("service version convention", "v1/rest/service",
......@@ -27,7 +28,7 @@ public class RegExServiceRouteMapperTests {
@Test
public void test_return_serviceid_if_no_matches() {
RegExServiceRouteMapper toTest = new RegExServiceRouteMapper(SERVICE_PATTERN,
PatternServiceRouteMapper toTest = new PatternServiceRouteMapper(SERVICE_PATTERN,
ROUTE_PATTERN);
// No version here
......@@ -38,7 +39,7 @@ public class RegExServiceRouteMapperTests {
@Test
public void test_route_should_be_cleaned_before_returned() {
// Messy patterns
RegExServiceRouteMapper toTest = new RegExServiceRouteMapper(SERVICE_PATTERN
PatternServiceRouteMapper toTest = new PatternServiceRouteMapper(SERVICE_PATTERN
+ "(?<nevermatch>.)?", "/${version}/${nevermatch}/${domain}/${name}/");
assertEquals("No matches for this service id", "v1/domain/service",
toTest.apply("domain-service-v1"));
......
......@@ -25,9 +25,9 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator;
import org.springframework.mock.web.MockHttpServletRequest;
import com.netflix.util.Pair;
......@@ -45,14 +45,14 @@ public class PreDecorationFilterTests {
private ZuulProperties properties = new ZuulProperties();
private ProxyRouteLocator routeLocator;
private DiscoveryClientRouteLocator routeLocator;
private MockHttpServletRequest request = new MockHttpServletRequest();
@Before
public void init() {
initMocks(this);
this.routeLocator = new ProxyRouteLocator("/", this.discovery,
this.routeLocator = new DiscoveryClientRouteLocator("/", this.discovery,
this.properties);
this.filter = new PreDecorationFilter(this.routeLocator, true);
RequestContext ctx = RequestContext.getCurrentContext();
......
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