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
ef67fa32
Commit
ef67fa32
authored
Oct 09, 2015
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add local service to zuul ignoredServices by default.
fixes gh-447
parent
8058ced9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
9 deletions
+56
-9
ProxyRouteLocator.java
...amework/cloud/netflix/zuul/filters/ProxyRouteLocator.java
+12
-1
ZuulProperties.java
...gframework/cloud/netflix/zuul/filters/ZuulProperties.java
+2
-0
ProxyRouteLocatorTests.java
...rk/cloud/netflix/zuul/filters/ProxyRouteLocatorTests.java
+42
-8
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ProxyRouteLocator.java
View file @
ef67fa32
...
...
@@ -27,6 +27,7 @@ import lombok.AllArgsConstructor;
import
lombok.Data
;
import
lombok.extern.apachecommons.CommonsLog
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute
;
import
org.springframework.util.AntPathMatcher
;
...
...
@@ -62,7 +63,17 @@ public class ProxyRouteLocator implements RouteLocator {
//set Zuul servlet path
this
.
servletPath
=
properties
.
getServletPath
()
!=
null
?
properties
.
getServletPath
()
:
""
;
}
if
(
properties
.
isIgnoreLocalService
())
{
ServiceInstance
instance
=
discovery
.
getLocalServiceInstance
();
if
(
instance
!=
null
)
{
String
localServiceId
=
instance
.
getServiceId
();
if
(!
properties
.
getIgnoredServices
().
contains
(
localServiceId
))
{
properties
.
getIgnoredServices
().
add
(
localServiceId
);
}
}
}
this
.
discovery
=
discovery
;
this
.
properties
=
properties
;
}
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ZuulProperties.java
View file @
ef67fa32
...
...
@@ -55,6 +55,8 @@ public class ZuulProperties {
private
String
servletPath
=
"/zuul"
;
private
boolean
ignoreLocalService
=
true
;
@PostConstruct
public
void
init
()
{
for
(
Entry
<
String
,
ZuulRoute
>
entry
:
this
.
routes
.
entrySet
())
{
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/ProxyRouteLocatorTests.java
View file @
ef67fa32
...
...
@@ -16,6 +16,14 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
MockitoAnnotations
.
initMocks
;
import
java.util.Collections
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
...
...
@@ -23,19 +31,12 @@ import java.util.Map;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.Mock
;
import
org.springframework.cloud.client.DefaultServiceInstance
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator.ProxyRouteSpec
;
import
org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
MockitoAnnotations
.
initMocks
;
/**
* @author Spencer Gibb
* @author Dave Syer
...
...
@@ -485,6 +486,39 @@ public class ProxyRouteLocatorTests {
assertMapping
(
routesMap
,
"http://example.com/"
+
MYSERVICE
,
MYSERVICE
);
}
@Test
public
void
testIgnoredLocalServiceByDefault
()
{
given
(
this
.
discovery
.
getServices
()).
willReturn
(
Collections
.
singletonList
(
MYSERVICE
));
given
(
this
.
discovery
.
getLocalServiceInstance
()).
willReturn
(
new
DefaultServiceInstance
(
MYSERVICE
,
"localhost"
,
80
,
false
));
ProxyRouteLocator
routeLocator
=
new
ProxyRouteLocator
(
"/"
,
this
.
discovery
,
this
.
properties
);
LinkedHashMap
<
String
,
ZuulRoute
>
routes
=
routeLocator
.
locateRoutes
();
ZuulRoute
actual
=
routes
.
get
(
"/**"
);
assertNull
(
"routes didn't ignore "
+
MYSERVICE
,
actual
);
Map
<
String
,
String
>
routesMap
=
routeLocator
.
getRoutes
();
assertNotNull
(
"routesMap was null"
,
routesMap
);
assertTrue
(
"routesMap was empty"
,
routesMap
.
isEmpty
());
}
@Test
public
void
testIgnoredLocalServiceFalse
()
{
this
.
properties
.
setIgnoreLocalService
(
false
);
given
(
this
.
discovery
.
getServices
()).
willReturn
(
Collections
.
singletonList
(
MYSERVICE
));
ProxyRouteLocator
routeLocator
=
new
ProxyRouteLocator
(
"/"
,
this
.
discovery
,
this
.
properties
);
Map
<
String
,
String
>
routesMap
=
routeLocator
.
getRoutes
();
assertNotNull
(
"routesMap was null"
,
routesMap
);
assertFalse
(
"routesMap was empty"
,
routesMap
.
isEmpty
());
assertMapping
(
routesMap
,
MYSERVICE
);
}
protected
void
assertMapping
(
Map
<
String
,
String
>
routesMap
,
String
serviceId
)
{
assertMapping
(
routesMap
,
serviceId
,
serviceId
);
}
...
...
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