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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
16 deletions
+22
-16
FormBodyWrapperFilter.java
...cloud/netflix/zuul/filters/pre/FormBodyWrapperFilter.java
+22
-16
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;
...
@@ -20,6 +20,7 @@ import java.io.ByteArrayOutputStream;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.util.List
;
import
java.util.Map.Entry
;
import
java.util.Map.Entry
;
import
javax.servlet.ServletInputStream
;
import
javax.servlet.ServletInputStream
;
...
@@ -54,7 +55,8 @@ public class FormBodyWrapperFilter extends ZuulFilter {
...
@@ -54,7 +55,8 @@ public class FormBodyWrapperFilter extends ZuulFilter {
public
FormBodyWrapperFilter
()
{
public
FormBodyWrapperFilter
()
{
this
.
requestField
=
ReflectionUtils
.
findField
(
HttpServletRequestWrapper
.
class
,
this
.
requestField
=
ReflectionUtils
.
findField
(
HttpServletRequestWrapper
.
class
,
"req"
,
HttpServletRequest
.
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
);
this
.
requestField
.
setAccessible
(
true
);
}
}
...
@@ -82,8 +84,8 @@ public class FormBodyWrapperFilter extends ZuulFilter {
...
@@ -82,8 +84,8 @@ public class FormBodyWrapperFilter extends ZuulFilter {
try
{
try
{
MediaType
mediaType
=
MediaType
.
valueOf
(
contentType
);
MediaType
mediaType
=
MediaType
.
valueOf
(
contentType
);
return
MediaType
.
APPLICATION_FORM_URLENCODED
.
includes
(
mediaType
)
return
MediaType
.
APPLICATION_FORM_URLENCODED
.
includes
(
mediaType
)
||
(
isDispatcherServletRequest
(
request
)
&&
MediaType
.
MULTIPART_FORM_DATA
||
(
isDispatcherServletRequest
(
request
)
.
includes
(
mediaType
));
&&
MediaType
.
MULTIPART_FORM_DATA
.
includes
(
mediaType
));
}
}
catch
(
InvalidMediaTypeException
ex
)
{
catch
(
InvalidMediaTypeException
ex
)
{
return
false
;
return
false
;
...
@@ -91,7 +93,8 @@ public class FormBodyWrapperFilter extends ZuulFilter {
...
@@ -91,7 +93,8 @@ public class FormBodyWrapperFilter extends ZuulFilter {
}
}
private
boolean
isDispatcherServletRequest
(
HttpServletRequest
request
)
{
private
boolean
isDispatcherServletRequest
(
HttpServletRequest
request
)
{
return
request
.
getAttribute
(
DispatcherServlet
.
WEB_APPLICATION_CONTEXT_ATTRIBUTE
)
!=
null
;
return
request
.
getAttribute
(
DispatcherServlet
.
WEB_APPLICATION_CONTEXT_ATTRIBUTE
)
!=
null
;
}
}
@Override
@Override
...
@@ -100,8 +103,8 @@ public class FormBodyWrapperFilter extends ZuulFilter {
...
@@ -100,8 +103,8 @@ public class FormBodyWrapperFilter extends ZuulFilter {
HttpServletRequest
request
=
ctx
.
getRequest
();
HttpServletRequest
request
=
ctx
.
getRequest
();
FormBodyRequestWrapper
wrapper
=
null
;
FormBodyRequestWrapper
wrapper
=
null
;
if
(
request
instanceof
HttpServletRequestWrapper
)
{
if
(
request
instanceof
HttpServletRequestWrapper
)
{
HttpServletRequest
wrapped
=
(
HttpServletRequest
)
ReflectionUtils
.
getField
(
HttpServletRequest
wrapped
=
(
HttpServletRequest
)
ReflectionUtils
this
.
requestField
,
request
);
.
getField
(
this
.
requestField
,
request
);
wrapper
=
new
FormBodyRequestWrapper
(
wrapped
);
wrapper
=
new
FormBodyRequestWrapper
(
wrapped
);
ReflectionUtils
.
setField
(
this
.
requestField
,
request
,
wrapper
);
ReflectionUtils
.
setField
(
this
.
requestField
,
request
,
wrapper
);
}
}
...
@@ -170,16 +173,19 @@ public class FormBodyWrapperFilter extends ZuulFilter {
...
@@ -170,16 +173,19 @@ public class FormBodyWrapperFilter extends ZuulFilter {
}
}
if
(
this
.
request
instanceof
MultipartRequest
)
{
if
(
this
.
request
instanceof
MultipartRequest
)
{
MultipartRequest
multi
=
(
MultipartRequest
)
this
.
request
;
MultipartRequest
multi
=
(
MultipartRequest
)
this
.
request
;
for
(
Entry
<
String
,
MultipartFile
>
part
:
multi
.
getFileMap
()
for
(
Entry
<
String
,
List
<
MultipartFile
>>
parts
:
multi
.
entrySet
())
{
.
getMultiFileMap
().
entrySet
())
{
MultipartFile
file
=
part
.
getValue
();
for
(
MultipartFile
part
:
parts
.
getValue
())
{
HttpHeaders
headers
=
new
HttpHeaders
();
MultipartFile
file
=
part
;
headers
.
setContentDispositionFormData
(
file
.
getName
(),
HttpHeaders
headers
=
new
HttpHeaders
();
file
.
getOriginalFilename
());
headers
.
setContentDispositionFormData
(
file
.
getName
(),
headers
.
setContentType
(
MediaType
.
valueOf
(
file
.
getContentType
()));
file
.
getOriginalFilename
());
HttpEntity
<
byte
[]>
entity
=
new
HttpEntity
<
byte
[]>(
headers
.
setContentType
(
file
.
getBytes
(),
headers
);
MediaType
.
valueOf
(
file
.
getContentType
()));
builder
.
set
(
part
.
getKey
(),
entity
);
HttpEntity
<
byte
[]>
entity
=
new
HttpEntity
<
byte
[]>(
file
.
getBytes
(),
headers
);
builder
.
add
(
parts
.
getKey
(),
entity
);
}
}
}
}
}
FormHttpOutputMessage
data
=
new
FormHttpOutputMessage
();
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