Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
3ecd9cb0
Commit
3ecd9cb0
authored
Jan 14, 2016
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move discovery related route locator stuff into a new package
parent
9161c54c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
103 additions
and
102 deletions
+103
-102
spring-cloud-netflix.adoc
docs/src/main/asciidoc/spring-cloud-netflix.adoc
+31
-26
ZuulProxyConfiguration.java
...gframework/cloud/netflix/zuul/ZuulProxyConfiguration.java
+10
-26
RefreshableRouteLocator.java
...k/cloud/netflix/zuul/filters/RefreshableRouteLocator.java
+1
-3
DiscoveryClientRouteLocator.java
...x/zuul/filters/discovery/DiscoveryClientRouteLocator.java
+12
-5
PatternServiceRouteMapper.java
...lix/zuul/filters/discovery/PatternServiceRouteMapper.java
+11
-9
ServiceRouteMapper.java
...ud/netflix/zuul/filters/discovery/ServiceRouteMapper.java
+1
-1
SimpleServiceRouteMapper.java
...flix/zuul/filters/discovery/SimpleServiceRouteMapper.java
+1
-1
ZuulHandlerMapping.java
...gframework/cloud/netflix/zuul/web/ZuulHandlerMapping.java
+1
-1
ContextPathZuulProxyApplicationTests.java
...ud/netflix/zuul/ContextPathZuulProxyApplicationTests.java
+2
-2
RetryableZuulProxyApplicationTests.java
...loud/netflix/zuul/RetryableZuulProxyApplicationTests.java
+2
-2
SampleZuulProxyAppTestsWithHttpClient.java
...d/netflix/zuul/SampleZuulProxyAppTestsWithHttpClient.java
+2
-2
SampleZuulProxyApplicationTests.java
...k/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java
+2
-2
ServletPathZuulProxyApplicationTests.java
...ud/netflix/zuul/ServletPathZuulProxyApplicationTests.java
+2
-2
CustomHostRoutingFilterTests.java
...ud/netflix/zuul/filters/CustomHostRoutingFilterTests.java
+2
-1
DiscoveryClientRouteLocatorTests.java
...l/filters/discovery/DiscoveryClientRouteLocatorTests.java
+0
-0
PatternServiceRouteMapperIntegrationTests.java
.../discovery/PatternServiceRouteMapperIntegrationTests.java
+14
-11
PatternServiceRouteMapperTests.java
...uul/filters/discovery/PatternServiceRouteMapperTests.java
+6
-5
PreDecorationFilterTests.java
...ud/netflix/zuul/filters/pre/PreDecorationFilterTests.java
+3
-3
No files found.
docs/src/main/asciidoc/spring-cloud-netflix.adoc
View file @
3ecd9cb0
...
...
@@ -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
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulProxyConfiguration.java
View file @
3ecd9cb0
...
...
@@ -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
Proxy
RouteLocator
routeLocator
()
{
return
new
ProxyRouteLocator
(
this
.
server
.
getServletPrefix
(),
this
.
discovery
,
this
.
zuulProperties
,
this
.
serviceRouteMapper
);
public
DiscoveryClient
RouteLocator
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
(
Proxy
RouteLocator
routeLocator
)
{
public
RoutesEndpoint
zuulEndpoint
(
DiscoveryClient
RouteLocator
routeLocator
)
{
return
new
RoutesEndpoint
(
routeLocator
);
}
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/RefreshableRouteLocator.java
→
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/
filters/
RefreshableRouteLocator.java
View file @
3ecd9cb0
...
...
@@ -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.
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/
Proxy
RouteLocator.java
→
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/
discovery/DiscoveryClient
RouteLocator.java
View file @
3ecd9cb0
...
...
@@ -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
Proxy
RouteLocator
implements
RefreshableRouteLocator
{
public
class
DiscoveryClient
RouteLocator
implements
RefreshableRouteLocator
{
public
static
final
String
DEFAULT_ROUTE
=
"/**"
;
...
...
@@ -56,7 +63,7 @@ public class ProxyRouteLocator implements RefreshableRouteLocator {
private
ServiceRouteMapper
serviceRouteMapper
;
public
Proxy
RouteLocator
(
String
servletPath
,
DiscoveryClient
discovery
,
public
DiscoveryClient
RouteLocator
(
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
Proxy
RouteLocator
(
String
servletPath
,
DiscoveryClient
discovery
,
public
DiscoveryClient
RouteLocator
(
String
servletPath
,
DiscoveryClient
discovery
,
ZuulProperties
properties
,
ServiceRouteMapper
serviceRouteMapper
)
{
this
(
servletPath
,
discovery
,
properties
);
this
.
serviceRouteMapper
=
serviceRouteMapper
;
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/
regex/RegEx
ServiceRouteMapper.java
→
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/
discovery/Pattern
ServiceRouteMapper.java
View file @
3ecd9cb0
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
RegEx
ServiceRouteMapper
implements
ServiceRouteMapper
{
public
class
Pattern
ServiceRouteMapper
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
RegEx
ServiceRouteMapper
(
String
servicePattern
,
String
routePattern
)
{
public
Pattern
ServiceRouteMapper
(
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
);
}
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ServiceRouteMapper.java
→
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/
discovery/
ServiceRouteMapper.java
View file @
3ecd9cb0
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.
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/SimpleServiceRouteMapper.java
→
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/
discovery/
SimpleServiceRouteMapper.java
View file @
3ecd9cb0
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
;
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
discovery
;
/**
* @author Stéphane Leroy
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/web/ZuulHandlerMapping.java
View file @
3ecd9cb0
...
...
@@ -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
;
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/ContextPathZuulProxyApplicationTests.java
View file @
3ecd9cb0
...
...
@@ -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
Proxy
RouteLocator
routes
;
private
DiscoveryClient
RouteLocator
routes
;
@Autowired
private
RoutesEndpoint
endpoint
;
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/RetryableZuulProxyApplicationTests.java
View file @
3ecd9cb0
...
...
@@ -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.
Proxy
RouteLocator
;
import
org.springframework.cloud.netflix.zuul.filters.
discovery.DiscoveryClient
RouteLocator
;
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
Proxy
RouteLocator
routes
;
private
DiscoveryClient
RouteLocator
routes
;
@Autowired
private
RoutesEndpoint
endpoint
;
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyAppTestsWithHttpClient.java
View file @
3ecd9cb0
...
...
@@ -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
Proxy
RouteLocator
routes
;
private
DiscoveryClient
RouteLocator
routes
;
@Autowired
private
RoutesEndpoint
endpoint
;
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java
View file @
3ecd9cb0
...
...
@@ -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
Proxy
RouteLocator
routes
;
private
DiscoveryClient
RouteLocator
routes
;
@Autowired
private
RoutesEndpoint
endpoint
;
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/ServletPathZuulProxyApplicationTests.java
View file @
3ecd9cb0
...
...
@@ -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
Proxy
RouteLocator
routes
;
private
DiscoveryClient
RouteLocator
routes
;
@Autowired
private
RoutesEndpoint
endpoint
;
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/CustomHostRoutingFilterTests.java
View file @
3ecd9cb0
...
...
@@ -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
Proxy
RouteLocator
routes
;
private
DiscoveryClient
RouteLocator
routes
;
@Autowired
private
RoutesEndpoint
endpoint
;
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/
Proxy
RouteLocatorTests.java
→
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/
discovery/DiscoveryClient
RouteLocatorTests.java
View file @
3ecd9cb0
This diff is collapsed.
Click to expand it.
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/
regex/RegEx
ServiceRouteMapperIntegrationTests.java
→
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/
discovery/Pattern
ServiceRouteMapperIntegrationTests.java
View file @
3ecd9cb0
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
.
RegEx
ServiceRouteMapperIntegrationTests
.
SERVICE_ID
;
import
static
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
discovery
.
Pattern
ServiceRouteMapperIntegrationTests
.
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
RegEx
ServiceRouteMapperIntegrationTests
{
public
class
Pattern
ServiceRouteMapperIntegrationTests
{
protected
static
final
String
SERVICE_ID
=
"domain-service-v1"
;
...
...
@@ -60,14 +56,14 @@ public class RegExServiceRouteMapperIntegrationTests {
private
int
port
;
@Autowired
private
Proxy
RouteLocator
routes
;
private
DiscoveryClient
RouteLocator
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
);
}
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/
regex/RegEx
ServiceRouteMapperTests.java
→
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/
discovery/Pattern
ServiceRouteMapperTests.java
View file @
3ecd9cb0
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
RegEx
ServiceRouteMapperTests
{
public
class
Pattern
ServiceRouteMapperTests
{
/**
* 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
RegEx
ServiceRouteMapper
(
SERVICE_PATTERN
,
PatternServiceRouteMapper
toTest
=
new
Pattern
ServiceRouteMapper
(
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
RegEx
ServiceRouteMapper
(
SERVICE_PATTERN
,
PatternServiceRouteMapper
toTest
=
new
Pattern
ServiceRouteMapper
(
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
RegEx
ServiceRouteMapper
(
SERVICE_PATTERN
PatternServiceRouteMapper
toTest
=
new
Pattern
ServiceRouteMapper
(
SERVICE_PATTERN
+
"(?<nevermatch>.)?"
,
"/${version}/${nevermatch}/${domain}/${name}/"
);
assertEquals
(
"No matches for this service id"
,
"v1/domain/service"
,
toTest
.
apply
(
"domain-service-v1"
));
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilterTests.java
View file @
3ecd9cb0
...
...
@@ -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
Proxy
RouteLocator
routeLocator
;
private
DiscoveryClient
RouteLocator
routeLocator
;
private
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
@Before
public
void
init
()
{
initMocks
(
this
);
this
.
routeLocator
=
new
Proxy
RouteLocator
(
"/"
,
this
.
discovery
,
this
.
routeLocator
=
new
DiscoveryClient
RouteLocator
(
"/"
,
this
.
discovery
,
this
.
properties
);
this
.
filter
=
new
PreDecorationFilter
(
this
.
routeLocator
,
true
);
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment