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
f9fc8ba8
Commit
f9fc8ba8
authored
Jan 15, 2016
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change signature of RouteLocator.getRoutes()
If it returns Routes instead of Strings it's a lot more obvious what it's supposed.
parent
2585798a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
42 additions
and
18 deletions
+42
-18
RoutesEndpoint.java
...rg/springframework/cloud/netflix/zuul/RoutesEndpoint.java
+7
-1
RouteLocator.java
...ingframework/cloud/netflix/zuul/filters/RouteLocator.java
+2
-2
SimpleRouteLocator.java
...mework/cloud/netflix/zuul/filters/SimpleRouteLocator.java
+7
-3
ZuulHandlerMapping.java
...gframework/cloud/netflix/zuul/web/ZuulHandlerMapping.java
+4
-3
SampleZuulProxyAppTestsWithHttpClient.java
...d/netflix/zuul/SampleZuulProxyAppTestsWithHttpClient.java
+7
-1
SampleZuulProxyApplicationTests.java
...k/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java
+7
-1
SimpleZuulServerApplicationTests.java
.../cloud/netflix/zuul/SimpleZuulServerApplicationTests.java
+1
-1
DiscoveryClientRouteLocatorTests.java
...l/filters/discovery/DiscoveryClientRouteLocatorTests.java
+0
-0
ZuulHandlerMappingTests.java
...ework/cloud/netflix/zuul/web/ZuulHandlerMappingTests.java
+7
-6
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/RoutesEndpoint.java
View file @
f9fc8ba8
...
...
@@ -16,11 +16,13 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.actuate.endpoint.Endpoint
;
import
org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint
;
import
org.springframework.cloud.netflix.zuul.filters.Route
;
import
org.springframework.cloud.netflix.zuul.filters.RouteLocator
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.context.ApplicationEventPublisherAware
;
...
...
@@ -66,7 +68,11 @@ public class RoutesEndpoint implements MvcEndpoint, ApplicationEventPublisherAwa
@ResponseBody
@ManagedAttribute
public
Map
<
String
,
String
>
getRoutes
()
{
return
this
.
routes
.
getRoutes
();
Map
<
String
,
String
>
map
=
new
LinkedHashMap
<>();
for
(
Route
route
:
this
.
routes
.
getRoutes
())
{
map
.
put
(
route
.
getPath
(),
route
.
getLocation
());
}
return
map
;
}
@Override
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/RouteLocator.java
View file @
f9fc8ba8
...
...
@@ -17,7 +17,7 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
;
import
java.util.Collection
;
import
java.util.
Map
;
import
java.util.
List
;
/**
* @author Dave Syer
...
...
@@ -32,7 +32,7 @@ public interface RouteLocator {
/**
* A map of route path (pattern) to location (e.g. service id or URL).
*/
Map
<
String
,
String
>
getRoutes
();
List
<
Route
>
getRoutes
();
/**
* Maps a path to an actual route with full metadata.
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocator.java
View file @
f9fc8ba8
...
...
@@ -16,8 +16,10 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.concurrent.atomic.AtomicReference
;
...
...
@@ -58,13 +60,15 @@ public class SimpleRouteLocator implements RouteLocator {
}
@Override
public
Map
<
String
,
String
>
getRoutes
()
{
public
List
<
Route
>
getRoutes
()
{
if
(
this
.
routes
.
get
()
==
null
)
{
this
.
routes
.
set
(
locateRoutes
());
}
Map
<
String
,
String
>
values
=
new
LinkedHashMap
<>();
List
<
Route
>
values
=
new
ArrayList
<>();
for
(
String
url
:
this
.
routes
.
get
().
keySet
())
{
values
.
put
(
url
,
this
.
routes
.
get
().
get
(
url
).
getLocation
());
ZuulRoute
route
=
this
.
routes
.
get
().
get
(
url
);
String
path
=
route
.
getPath
();
values
.
add
(
getRoute
(
route
,
path
));
}
return
values
;
}
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/web/ZuulHandlerMapping.java
View file @
f9fc8ba8
...
...
@@ -22,6 +22,7 @@ import javax.servlet.http.HttpServletRequest;
import
org.springframework.boot.autoconfigure.web.ErrorController
;
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.util.PatternMatchUtils
;
import
org.springframework.web.servlet.handler.AbstractUrlHandlerMapping
;
...
...
@@ -88,13 +89,13 @@ public class ZuulHandlerMapping extends AbstractUrlHandlerMapping {
}
private
void
registerHandlers
()
{
Collection
<
String
>
routes
=
this
.
routeLocator
.
getRoutes
().
keySet
();
Collection
<
Route
>
routes
=
this
.
routeLocator
.
getRoutes
();
if
(
routes
.
isEmpty
())
{
this
.
logger
.
warn
(
"No routes found from RouteLocator"
);
}
else
{
for
(
String
url
:
routes
)
{
registerHandler
(
url
,
this
.
zuul
);
for
(
Route
route
:
routes
)
{
registerHandler
(
route
.
getPrefix
()
+
route
.
getPath
()
,
this
.
zuul
);
}
}
}
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyAppTestsWithHttpClient.java
View file @
f9fc8ba8
...
...
@@ -33,6 +33,7 @@ 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.Route
;
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
;
...
...
@@ -82,7 +83,12 @@ public class SampleZuulProxyAppTestsWithHttpClient {
private
RibbonCommandFactory
<?>
ribbonCommandFactory
;
private
String
getRoute
(
String
path
)
{
return
this
.
routes
.
getRoutes
().
get
(
path
);
for
(
Route
route
:
this
.
routes
.
getRoutes
())
{
if
(
path
.
equals
(
route
.
getPrefix
()
+
route
.
getPath
()))
{
return
route
.
getLocation
();
}
}
return
null
;
}
@Test
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java
View file @
f9fc8ba8
...
...
@@ -36,6 +36,7 @@ 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.Route
;
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
;
...
...
@@ -88,7 +89,12 @@ public class SampleZuulProxyApplicationTests {
private
RibbonCommandFactory
<?>
ribbonCommandFactory
;
private
String
getRoute
(
String
path
)
{
return
this
.
routes
.
getRoutes
().
get
(
path
);
for
(
Route
route
:
this
.
routes
.
getRoutes
())
{
if
(
path
.
equals
(
route
.
getPrefix
()
+
route
.
getPath
()))
{
return
route
.
getLocation
();
}
}
return
null
;
}
@Test
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SimpleZuulServerApplicationTests.java
View file @
f9fc8ba8
...
...
@@ -57,7 +57,7 @@ public class SimpleZuulServerApplicationTests {
private
RouteLocator
routes
;
private
String
getRoute
(
String
path
)
{
return
this
.
routes
.
get
Routes
().
get
(
path
);
return
this
.
routes
.
get
MatchingRoute
(
path
).
getLocation
(
);
}
@Test
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/discovery/DiscoveryClientRouteLocatorTests.java
View file @
f9fc8ba8
This diff is collapsed.
Click to expand it.
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/web/ZuulHandlerMappingTests.java
View file @
f9fc8ba8
...
...
@@ -22,6 +22,7 @@ import org.junit.Before;
import
org.junit.Test
;
import
org.mockito.Mockito
;
import
org.springframework.boot.autoconfigure.web.ErrorController
;
import
org.springframework.cloud.netflix.zuul.filters.Route
;
import
org.springframework.cloud.netflix.zuul.filters.RouteLocator
;
import
org.springframework.mock.web.MockHttpServletRequest
;
...
...
@@ -53,8 +54,8 @@ public class ZuulHandlerMappingTests {
@Test
public
void
mappedPath
()
throws
Exception
{
Mockito
.
when
(
this
.
locator
.
getRoutes
())
.
thenReturn
(
Collections
.
singletonMap
(
"/foo/**"
,
"foo"
));
Mockito
.
when
(
this
.
locator
.
getRoutes
())
.
thenReturn
(
Collections
.
singletonList
(
new
Route
(
"foo"
,
"/foo/**"
,
"foo"
,
""
,
null
)
));
this
.
request
.
setServletPath
(
"/foo/"
);
this
.
mapping
.
setDirty
(
true
);
assertNotNull
(
this
.
mapping
.
getHandler
(
this
.
request
));
...
...
@@ -62,8 +63,8 @@ public class ZuulHandlerMappingTests {
@Test
public
void
defaultPath
()
throws
Exception
{
Mockito
.
when
(
this
.
locator
.
getRoutes
())
.
thenReturn
(
Collections
.
singletonMap
(
"/**"
,
"default"
));
Mockito
.
when
(
this
.
locator
.
getRoutes
())
.
thenReturn
(
Collections
.
singletonList
(
new
Route
(
"default"
,
"/**"
,
"foo"
,
""
,
null
)
));
;
this
.
request
.
setServletPath
(
"/"
);
this
.
mapping
.
setDirty
(
true
);
...
...
@@ -72,8 +73,8 @@ public class ZuulHandlerMappingTests {
@Test
public
void
errorPath
()
throws
Exception
{
Mockito
.
when
(
this
.
locator
.
getRoutes
())
.
thenReturn
(
Collections
.
singletonMap
(
"/**"
,
"default"
));
Mockito
.
when
(
this
.
locator
.
getRoutes
())
.
thenReturn
(
Collections
.
singletonList
(
new
Route
(
"default"
,
"/**"
,
"foo"
,
""
,
null
)
));
this
.
request
.
setServletPath
(
"/error"
);
this
.
mapping
.
setDirty
(
true
);
assertNull
(
this
.
mapping
.
getHandler
(
this
.
request
));
...
...
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