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
908dcc0e
Commit
908dcc0e
authored
Mar 03, 2016
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for multivalued map of file uploads
i.e. user sends multiple files with the same parameter name. Fixes gh-870
parent
4f6b2bce
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
11 deletions
+17
-11
FormBodyWrapperFilter.java
...cloud/netflix/zuul/filters/pre/FormBodyWrapperFilter.java
+17
-11
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/FormBodyWrapperFilter.java
View file @
908dcc0e
...
...
@@ -20,6 +20,7 @@ import java.io.ByteArrayOutputStream;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.lang.reflect.Field
;
import
java.util.List
;
import
java.util.Map.Entry
;
import
javax.servlet.ServletInputStream
;
...
...
@@ -54,7 +55,8 @@ public class FormBodyWrapperFilter extends ZuulFilter {
public
FormBodyWrapperFilter
()
{
this
.
requestField
=
ReflectionUtils
.
findField
(
HttpServletRequestWrapper
.
class
,
"req"
,
HttpServletRequest
.
class
);
Assert
.
notNull
(
this
.
requestField
,
"HttpServletRequestWrapper.req field not found"
);
Assert
.
notNull
(
this
.
requestField
,
"HttpServletRequestWrapper.req field not found"
);
this
.
requestField
.
setAccessible
(
true
);
}
...
...
@@ -82,8 +84,8 @@ public class FormBodyWrapperFilter extends ZuulFilter {
try
{
MediaType
mediaType
=
MediaType
.
valueOf
(
contentType
);
return
MediaType
.
APPLICATION_FORM_URLENCODED
.
includes
(
mediaType
)
||
(
isDispatcherServletRequest
(
request
)
&&
MediaType
.
MULTIPART_FORM_DATA
.
includes
(
mediaType
));
||
(
isDispatcherServletRequest
(
request
)
&&
MediaType
.
MULTIPART_FORM_DATA
.
includes
(
mediaType
));
}
catch
(
InvalidMediaTypeException
ex
)
{
return
false
;
...
...
@@ -91,7 +93,8 @@ public class FormBodyWrapperFilter extends ZuulFilter {
}
private
boolean
isDispatcherServletRequest
(
HttpServletRequest
request
)
{
return
request
.
getAttribute
(
DispatcherServlet
.
WEB_APPLICATION_CONTEXT_ATTRIBUTE
)
!=
null
;
return
request
.
getAttribute
(
DispatcherServlet
.
WEB_APPLICATION_CONTEXT_ATTRIBUTE
)
!=
null
;
}
@Override
...
...
@@ -100,8 +103,8 @@ public class FormBodyWrapperFilter extends ZuulFilter {
HttpServletRequest
request
=
ctx
.
getRequest
();
FormBodyRequestWrapper
wrapper
=
null
;
if
(
request
instanceof
HttpServletRequestWrapper
)
{
HttpServletRequest
wrapped
=
(
HttpServletRequest
)
ReflectionUtils
.
getField
(
this
.
requestField
,
request
);
HttpServletRequest
wrapped
=
(
HttpServletRequest
)
ReflectionUtils
.
getField
(
this
.
requestField
,
request
);
wrapper
=
new
FormBodyRequestWrapper
(
wrapped
);
ReflectionUtils
.
setField
(
this
.
requestField
,
request
,
wrapper
);
}
...
...
@@ -170,16 +173,19 @@ public class FormBodyWrapperFilter extends ZuulFilter {
}
if
(
this
.
request
instanceof
MultipartRequest
)
{
MultipartRequest
multi
=
(
MultipartRequest
)
this
.
request
;
for
(
Entry
<
String
,
MultipartFile
>
part
:
multi
.
getFileMap
()
.
entrySet
())
{
MultipartFile
file
=
part
.
getValue
();
for
(
Entry
<
String
,
List
<
MultipartFile
>>
parts
:
multi
.
getMultiFileMap
().
entrySet
())
{
for
(
MultipartFile
part
:
parts
.
getValue
())
{
MultipartFile
file
=
part
;
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentDispositionFormData
(
file
.
getName
(),
file
.
getOriginalFilename
());
headers
.
setContentType
(
MediaType
.
valueOf
(
file
.
getContentType
()));
headers
.
setContentType
(
MediaType
.
valueOf
(
file
.
getContentType
()));
HttpEntity
<
byte
[]>
entity
=
new
HttpEntity
<
byte
[]>(
file
.
getBytes
(),
headers
);
builder
.
set
(
part
.
getKey
(),
entity
);
builder
.
add
(
parts
.
getKey
(),
entity
);
}
}
}
FormHttpOutputMessage
data
=
new
FormHttpOutputMessage
();
...
...
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