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
acb12ea7
Unverified
Commit
acb12ea7
authored
Sep 13, 2016
by
Alena
Committed by
Spencer Gibb
Oct 13, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support DELETE method body for SimpleHostRoutingFilter
fixes gh-1329
parent
e94c35d3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
23 deletions
+58
-23
SimpleHostRoutingFilter.java
...d/netflix/zuul/filters/route/SimpleHostRoutingFilter.java
+40
-23
SimpleHostRoutingFilterTests.java
...flix/zuul/filters/route/SimpleHostRoutingFilterTests.java
+18
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java
View file @
acb12ea7
...
...
@@ -63,6 +63,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
;
import
org.apache.http.message.BasicHeader
;
import
org.apache.http.message.BasicHttpEntityEnclosingRequest
;
import
org.apache.http.message.BasicHttpRequest
;
import
org.apache.http.protocol.HttpContext
;
import
org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper
;
...
...
@@ -271,34 +272,13 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
URL
host
=
RequestContext
.
getCurrentContext
().
getRouteHost
();
HttpHost
httpHost
=
getHttpHost
(
host
);
uri
=
StringUtils
.
cleanPath
((
host
.
getPath
()
+
uri
).
replaceAll
(
"/{2,}"
,
"/"
));
HttpRequest
httpRequest
;
int
contentLength
=
request
.
getContentLength
();
InputStreamEntity
entity
=
new
InputStreamEntity
(
requestEntity
,
contentLength
,
request
.
getContentType
()
!=
null
?
ContentType
.
create
(
request
.
getContentType
())
:
null
);
switch
(
verb
.
toUpperCase
())
{
case
"POST"
:
HttpPost
httpPost
=
new
HttpPost
(
uri
+
this
.
helper
.
getQueryString
(
params
));
httpRequest
=
httpPost
;
httpPost
.
setEntity
(
entity
);
break
;
case
"PUT"
:
HttpPut
httpPut
=
new
HttpPut
(
uri
+
this
.
helper
.
getQueryString
(
params
));
httpRequest
=
httpPut
;
httpPut
.
setEntity
(
entity
);
break
;
case
"PATCH"
:
HttpPatch
httpPatch
=
new
HttpPatch
(
uri
+
this
.
helper
.
getQueryString
(
params
));
httpRequest
=
httpPatch
;
httpPatch
.
setEntity
(
entity
);
break
;
default
:
httpRequest
=
new
BasicHttpRequest
(
verb
,
uri
+
this
.
helper
.
getQueryString
(
params
));
log
.
debug
(
uri
+
this
.
helper
.
getQueryString
(
params
));
}
HttpRequest
httpRequest
=
buildHttpRequest
(
verb
,
uri
,
entity
,
headers
,
params
);
try
{
httpRequest
.
setHeaders
(
convertHeaders
(
headers
));
log
.
debug
(
httpHost
.
getHostName
()
+
" "
+
httpHost
.
getPort
()
+
" "
+
httpHost
.
getSchemeName
());
HttpResponse
zuulResponse
=
forwardRequest
(
httpclient
,
httpHost
,
httpRequest
);
...
...
@@ -314,6 +294,43 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
}
}
protected
HttpRequest
buildHttpRequest
(
String
verb
,
String
uri
,
InputStreamEntity
entity
,
MultiValueMap
<
String
,
String
>
headers
,
MultiValueMap
<
String
,
String
>
params
)
{
HttpRequest
httpRequest
;
switch
(
verb
.
toUpperCase
())
{
case
"POST"
:
HttpPost
httpPost
=
new
HttpPost
(
uri
+
this
.
helper
.
getQueryString
(
params
));
httpRequest
=
httpPost
;
httpPost
.
setEntity
(
entity
);
break
;
case
"PUT"
:
HttpPut
httpPut
=
new
HttpPut
(
uri
+
this
.
helper
.
getQueryString
(
params
));
httpRequest
=
httpPut
;
httpPut
.
setEntity
(
entity
);
break
;
case
"PATCH"
:
HttpPatch
httpPatch
=
new
HttpPatch
(
uri
+
this
.
helper
.
getQueryString
(
params
));
httpRequest
=
httpPatch
;
httpPatch
.
setEntity
(
entity
);
break
;
case
"DELETE"
:
BasicHttpEntityEnclosingRequest
entityRequest
=
new
BasicHttpEntityEnclosingRequest
(
verb
,
uri
+
this
.
helper
.
getQueryString
(
params
));
httpRequest
=
entityRequest
;
entityRequest
.
setEntity
(
entity
);
break
;
default
:
httpRequest
=
new
BasicHttpRequest
(
verb
,
uri
+
this
.
helper
.
getQueryString
(
params
));
log
.
debug
(
uri
+
this
.
helper
.
getQueryString
(
params
));
}
httpRequest
.
setHeaders
(
convertHeaders
(
headers
));
return
httpRequest
;
}
private
MultiValueMap
<
String
,
String
>
revertHeaders
(
Header
[]
headers
)
{
MultiValueMap
<
String
,
String
>
map
=
new
LinkedMultiValueMap
<
String
,
String
>();
for
(
Header
header
:
headers
)
{
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilterTests.java
View file @
acb12ea7
...
...
@@ -16,6 +16,11 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
route
;
import
java.io.ByteArrayInputStream
;
import
org.apache.http.HttpEntityEnclosingRequest
;
import
org.apache.http.HttpRequest
;
import
org.apache.http.entity.InputStreamEntity
;
import
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
;
import
org.junit.After
;
import
org.junit.Test
;
...
...
@@ -26,6 +31,7 @@ import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.util.LinkedMultiValueMap
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
...
...
@@ -80,6 +86,18 @@ public class SimpleHostRoutingFilterTests {
assertEquals
(
20
,
connMgr
.
getDefaultMaxPerRoute
());
}
@Test
public
void
deleteRequestBuiltWithBody
()
{
setupContext
();
InputStreamEntity
inputStreamEntity
=
new
InputStreamEntity
(
new
ByteArrayInputStream
(
new
byte
[]{
1
}));
HttpRequest
httpRequest
=
getFilter
().
buildHttpRequest
(
"DELETE"
,
"uri"
,
inputStreamEntity
,
new
LinkedMultiValueMap
<
String
,
String
>(),
new
LinkedMultiValueMap
<
String
,
String
>());
assertTrue
(
httpRequest
instanceof
HttpEntityEnclosingRequest
);
HttpEntityEnclosingRequest
httpEntityEnclosingRequest
=
(
HttpEntityEnclosingRequest
)
httpRequest
;
assertTrue
(
httpEntityEnclosingRequest
.
getEntity
()
!=
null
);
}
private
void
setupContext
()
{
this
.
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
TestConfiguration
.
class
);
...
...
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