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
758ff920
Unverified
Commit
758ff920
authored
Sep 16, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1351 from VanRoy/improve-formbodywrapperfilter-test
* improve-formbodywrapperfilter-test: Add test on FormBodyWrapperFilter to avoid regressions (#1171)
parents
61de1181
7ba80639
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
18 deletions
+30
-18
FormZuulProxyApplicationTests.java
...ork/cloud/netflix/zuul/FormZuulProxyApplicationTests.java
+30
-18
No files found.
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/FormZuulProxyApplicationTests.java
View file @
758ff920
...
...
@@ -16,10 +16,7 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Map
;
import
org.junit.Before
;
...
...
@@ -59,6 +56,10 @@ import com.netflix.loadbalancer.ServerList;
import
com.netflix.zuul.ZuulFilter
;
import
com.netflix.zuul.context.RequestContext
;
import
static
java
.
nio
.
charset
.
Charset
.
defaultCharset
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
springframework
.
util
.
StreamUtils
.
copyToString
;
import
lombok.extern.slf4j.Slf4j
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
...
...
@@ -122,6 +123,24 @@ public class FormZuulProxyApplicationTests {
}
@Test
public
void
postWithMultipartFileAndForm
()
{
MultiValueMap
<
String
,
Object
>
form
=
new
LinkedMultiValueMap
<
String
,
Object
>();
HttpHeaders
part
=
new
HttpHeaders
();
part
.
setContentType
(
MediaType
.
TEXT_PLAIN
);
part
.
setContentDispositionFormData
(
"file"
,
"foo.txt"
);
form
.
set
(
"foo"
,
new
HttpEntity
<
byte
[]>(
"bar"
.
getBytes
(),
part
));
form
.
set
(
"field"
,
"data"
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
MULTIPART_FORM_DATA
);
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/simple/fileandform"
,
HttpMethod
.
POST
,
new
HttpEntity
<
MultiValueMap
<
String
,
Object
>>(
form
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
result
.
getStatusCode
());
assertEquals
(
"Posted! bar!field!data"
,
result
.
getBody
());
}
@Test
public
void
postWithUTF8Form
()
{
MultiValueMap
<
String
,
String
>
form
=
new
LinkedMultiValueMap
<
String
,
String
>();
form
.
set
(
"foo"
,
"bar"
);
...
...
@@ -190,22 +209,15 @@ class FormZuulProxyApplication {
@RequestMapping
(
value
=
"/file"
,
method
=
RequestMethod
.
POST
)
public
String
file
(
@RequestParam
(
required
=
false
)
MultipartFile
file
)
throws
IOException
{
byte
[]
bytes
=
new
byte
[
0
];
if
(
file
!=
null
)
{
if
(
file
.
getSize
()
>
1024
)
{
bytes
=
new
byte
[
1024
];
InputStream
inputStream
=
file
.
getInputStream
();
inputStream
.
read
(
bytes
);
byte
[]
buffer
=
new
byte
[
1024
*
1024
*
10
];
while
(
inputStream
.
read
(
buffer
)
>=
0
)
{
log
.
info
(
"Read more bytes"
);
}
}
else
{
bytes
=
file
.
getBytes
();
}
return
"Posted! "
+
copyToString
(
file
.
getInputStream
(),
defaultCharset
());
}
return
"Posted! "
+
new
String
(
bytes
);
@RequestMapping
(
value
=
"/fileandform"
,
method
=
RequestMethod
.
POST
)
public
String
fileAndForm
(
@RequestParam
MultipartFile
file
,
@RequestParam
String
field
)
throws
IOException
{
return
"Posted! "
+
copyToString
(
file
.
getInputStream
(),
defaultCharset
())
+
"!field!"
+
field
;
}
@Bean
...
...
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