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
8a2a608a
Commit
8a2a608a
authored
Mar 02, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add zuul.removeSemicolonContent to enable matrix params.
fixes gh-542
parent
60f4a5bc
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
13 deletions
+50
-13
ZuulProxyConfiguration.java
...gframework/cloud/netflix/zuul/ZuulProxyConfiguration.java
+2
-1
ZuulProperties.java
...gframework/cloud/netflix/zuul/filters/ZuulProperties.java
+2
-0
PreDecorationFilter.java
...k/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java
+2
-1
SampleZuulProxyApplicationTests.java
...k/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java
+32
-9
ZuulProxyTestBase.java
...springframework/cloud/netflix/zuul/ZuulProxyTestBase.java
+10
-1
PreDecorationFilterTests.java
...ud/netflix/zuul/filters/pre/PreDecorationFilterTests.java
+2
-1
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulProxyConfiguration.java
View file @
8a2a608a
...
...
@@ -87,7 +87,8 @@ public class ZuulProxyConfiguration extends ZuulConfiguration {
@Bean
public
PreDecorationFilter
preDecorationFilter
(
RouteLocator
routeLocator
)
{
return
new
PreDecorationFilter
(
routeLocator
,
this
.
zuulProperties
.
isAddProxyHeaders
());
this
.
zuulProperties
.
isAddProxyHeaders
(),
this
.
zuulProperties
.
isRemoveSemicolonContent
());
}
// route filters
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ZuulProperties.java
View file @
8a2a608a
...
...
@@ -74,6 +74,8 @@ public class ZuulProperties {
private
boolean
traceRequestBody
=
true
;
private
boolean
removeSemicolonContent
=
true
;
public
Set
<
String
>
getIgnoredHeaders
()
{
Set
<
String
>
ignoredHeaders
=
new
LinkedHashSet
<>(
this
.
ignoredHeaders
);
if
(
ClassUtils
.
isPresent
(
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java
View file @
8a2a608a
...
...
@@ -39,9 +39,10 @@ public class PreDecorationFilter extends ZuulFilter {
private
UrlPathHelper
urlPathHelper
=
new
UrlPathHelper
();
public
PreDecorationFilter
(
RouteLocator
routeLocator
,
boolean
addProxyHeaders
)
{
public
PreDecorationFilter
(
RouteLocator
routeLocator
,
boolean
addProxyHeaders
,
boolean
removeSemicolonContent
)
{
this
.
routeLocator
=
routeLocator
;
this
.
addProxyHeaders
=
addProxyHeaders
;
this
.
urlPathHelper
.
setRemoveSemicolonContent
(
removeSemicolonContent
);
}
@Override
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java
View file @
8a2a608a
...
...
@@ -50,6 +50,8 @@ import org.springframework.test.annotation.DirtiesContext;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.bind.annotation.MatrixVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -60,19 +62,20 @@ import com.netflix.loadbalancer.Server;
import
com.netflix.loadbalancer.ServerList
;
import
com.netflix.niws.client.http.RestClient
;
import
lombok.SneakyThrows
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
lombok.SneakyThrows
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
SampleZuulProxyApplication
.
class
)
@WebAppConfiguration
@IntegrationTest
({
"server.port: 0"
,
@IntegrationTest
({
"server.port: 0"
,
"zuul.routes.other: /test/**=http://localhost:7777/local"
,
"zuul.routes.another: /another/twolevel/**"
,
"zuul.routes.simple: /simple/**"
,
"zuul.routes.badhost: /badhost/**"
,
"zuul.ignoredHeaders: X-Header"
})
"zuul.routes.badhost: /badhost/**"
,
"zuul.ignoredHeaders: X-Header"
,
"zuul.removeSemicolonContent: false"
})
@DirtiesContext
public
class
SampleZuulProxyApplicationTests
extends
ZuulProxyTestBase
{
...
...
@@ -122,12 +125,24 @@ public class SampleZuulProxyApplicationTests extends ZuulProxyTestBase {
}
@Test
public
void
simpleHostRouteWithMatrix
()
{
this
.
routes
.
addRoute
(
"/self/**"
,
"http://localhost:"
+
this
.
port
+
"/"
);
this
.
endpoint
.
reset
();
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/self/matrix/my;q=2;p=1/more;x=2"
,
HttpMethod
.
GET
,
new
HttpEntity
<>((
Void
)
null
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
result
.
getStatusCode
());
assertEquals
(
"my=1-2;more=2"
,
result
.
getBody
());
}
@Test
public
void
simpleHostRouteWithEncodedQuery
()
{
this
.
routes
.
addRoute
(
"/self/**"
,
"http://localhost:"
+
this
.
port
+
"/"
);
this
.
endpoint
.
reset
();
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/self/query?foo={foo}"
,
HttpMethod
.
GET
,
new
HttpEntity
<>((
Void
)
null
),
String
.
class
,
"weird#chars"
);
"http://localhost:"
+
this
.
port
+
"/self/query?foo={foo}"
,
HttpMethod
.
GET
,
new
HttpEntity
<>((
Void
)
null
),
String
.
class
,
"weird#chars"
);
assertEquals
(
HttpStatus
.
OK
,
result
.
getStatusCode
());
assertEquals
(
"/query?foo=weird#chars"
,
result
.
getBody
());
}
...
...
@@ -175,12 +190,12 @@ public class SampleZuulProxyApplicationTests extends ZuulProxyTestBase {
@RibbonClient
(
name
=
"another"
,
configuration
=
AnotherRibbonClientConfiguration
.
class
)
})
class
SampleZuulProxyApplication
extends
ZuulProxyTestBase
.
AbstractZuulProxyApplication
{
@RequestMapping
(
value
=
"/trailing-slash"
)
@RequestMapping
(
"/trailing-slash"
)
public
String
trailingSlash
(
HttpServletRequest
request
)
{
return
request
.
getRequestURI
();
}
@RequestMapping
(
value
=
"/add-header"
)
@RequestMapping
(
"/add-header"
)
public
ResponseEntity
<
String
>
addHeader
(
HttpServletRequest
request
)
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
set
(
"X-Header"
,
"FOO"
);
...
...
@@ -189,11 +204,19 @@ class SampleZuulProxyApplication extends ZuulProxyTestBase.AbstractZuulProxyAppl
return
result
;
}
@RequestMapping
(
value
=
"/query"
)
@RequestMapping
(
"/query"
)
public
String
addQuery
(
HttpServletRequest
request
,
@RequestParam
String
foo
)
{
return
request
.
getRequestURI
()
+
"?foo="
+
foo
;
}
@RequestMapping
(
"/matrix/{name}/{another}"
)
public
String
matrix
(
@PathVariable
(
"name"
)
String
name
,
@MatrixVariable
(
value
=
"p"
,
pathVar
=
"name"
)
int
p
,
@MatrixVariable
(
value
=
"q"
,
pathVar
=
"name"
)
int
q
,
@PathVariable
(
"another"
)
String
another
,
@MatrixVariable
(
value
=
"x"
,
pathVar
=
"another"
)
int
x
)
{
return
name
+
"="
+
p
+
"-"
+
q
+
";"
+
another
+
"="
+
x
;
}
@Bean
public
RibbonCommandFactory
<?>
ribbonCommandFactory
(
SpringClientFactory
clientFactory
)
{
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/ZuulProxyTestBase.java
View file @
8a2a608a
...
...
@@ -27,6 +27,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration
;
import
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
;
import
com.netflix.loadbalancer.Server
;
import
com.netflix.loadbalancer.ServerList
;
...
...
@@ -182,7 +184,7 @@ public abstract class ZuulProxyTestBase {
assertEquals
(
"Received {key=[overridden]}"
,
result
.
getBody
());
}
protected
static
abstract
class
AbstractZuulProxyApplication
{
protected
static
abstract
class
AbstractZuulProxyApplication
extends
DelegatingWebMvcConfiguration
{
@RequestMapping
(
"/testing123"
)
public
String
testing123
()
{
...
...
@@ -258,6 +260,13 @@ public abstract class ZuulProxyTestBase {
}
};
}
@Override
public
RequestMappingHandlerMapping
requestMappingHandlerMapping
()
{
RequestMappingHandlerMapping
mapping
=
super
.
requestMappingHandlerMapping
();
mapping
.
setRemoveSemicolonContent
(
false
);
return
mapping
;
}
}
}
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilterTests.java
View file @
8a2a608a
...
...
@@ -54,7 +54,8 @@ public class PreDecorationFilterTests {
initMocks
(
this
);
this
.
routeLocator
=
new
DiscoveryClientRouteLocator
(
"/"
,
this
.
discovery
,
this
.
properties
);
this
.
filter
=
new
PreDecorationFilter
(
this
.
routeLocator
,
true
);
this
.
filter
=
new
PreDecorationFilter
(
this
.
routeLocator
,
true
,
this
.
properties
.
isRemoveSemicolonContent
());
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
ctx
.
clear
();
ctx
.
setRequest
(
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