Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
6e79dcdc
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6e79dcdc
编写于
7月 02, 2019
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #23070 from L00kian/23060-fix
上级
ac29e9de
29b76590
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
73 addition
and
15 deletion
+73
-15
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolver.java
.../method/annotation/RequestPartMethodArgumentResolver.java
+4
-11
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolverTests.java
...od/annotation/RequestPartMethodArgumentResolverTests.java
+69
-4
未找到文件。
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolver.java
浏览文件 @
6e79dcdc
/*
* Copyright 2002-201
8
the original author or authors.
* Copyright 2002-201
9
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -96,19 +96,12 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageReaderArgu
ReactiveAdapter
adapter
=
getAdapterRegistry
().
getAdapter
(
parameter
.
getParameterType
());
if
(
adapter
!=
null
)
{
// Mono<Part> or Flux<Part>
MethodParameter
elementType
=
parameter
.
nested
();
if
(
Part
.
class
.
isAssignableFrom
(
elementType
.
getNestedParameterType
()))
{
parts
=
(
adapter
.
isMultiValue
()
?
parts
:
parts
.
take
(
1
));
return
Mono
.
just
(
adapter
.
fromPublisher
(
parts
));
}
// We have to decode the content for each part, one at a time
if
(
adapter
.
isMultiValue
())
{
return
Mono
.
just
(
decodePartValues
(
parts
,
elementType
,
bindingContext
,
exchange
,
isRequired
));
}
return
Mono
.
just
(
adapter
.
fromPublisher
(
Part
.
class
.
isAssignableFrom
(
elementType
.
getNestedParameterType
())
?
parts
:
decodePartValues
(
parts
,
elementType
,
bindingContext
,
exchange
,
isRequired
)));
}
// <T> or Mono<T>
return
decodePartValues
(
parts
,
parameter
,
bindingContext
,
exchange
,
isRequired
)
.
next
().
cast
(
Object
.
class
);
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolverTests.java
浏览文件 @
6e79dcdc
/*
* Copyright 2002-201
8
the original author or authors.
* Copyright 2002-201
9
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -53,13 +53,18 @@ import org.springframework.web.reactive.BindingContext;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.ServerWebInputException
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
springframework
.
core
.
ResolvableType
.*;
import
static
org
.
springframework
.
web
.
method
.
MvcAnnotationPredicates
.*;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
core
.
ResolvableType
.
forClass
;
import
static
org
.
springframework
.
web
.
method
.
MvcAnnotationPredicates
.
requestPart
;
/**
* Unit tests for {@link RequestPartMethodArgumentResolver}.
* @author Rossen Stoyanchev
* @author Ilya Lukyanovich
*/
public
class
RequestPartMethodArgumentResolverTests
{
...
...
@@ -131,6 +136,15 @@ public class RequestPartMethodArgumentResolverTests {
assertEquals
(
"James"
,
actual
.
get
(
1
).
getName
());
}
@Test
// gh-23060
public
void
listPersonNotRequired
()
{
MethodParameter
param
=
this
.
testMethod
.
annot
(
requestPart
().
notRequired
()).
arg
(
List
.
class
,
Person
.
class
);
MultipartBodyBuilder
bodyBuilder
=
new
MultipartBodyBuilder
();
List
<
Person
>
actual
=
resolveArgument
(
param
,
bodyBuilder
);
assertEquals
(
Collections
.
emptyList
(),
actual
);
}
@Test
public
void
monoPerson
()
{
MethodParameter
param
=
this
.
testMethod
.
annot
(
requestPart
()).
arg
(
Mono
.
class
,
Person
.
class
);
...
...
@@ -141,6 +155,15 @@ public class RequestPartMethodArgumentResolverTests {
assertEquals
(
"Jones"
,
actual
.
block
().
getName
());
}
@Test
// gh-23060
public
void
monoPersonNotRequired
()
{
MethodParameter
param
=
this
.
testMethod
.
annot
(
requestPart
().
notRequired
()).
arg
(
Mono
.
class
,
Person
.
class
);
MultipartBodyBuilder
bodyBuilder
=
new
MultipartBodyBuilder
();
Mono
<
Person
>
actual
=
resolveArgument
(
param
,
bodyBuilder
);
assertNull
(
actual
.
block
());
}
@Test
public
void
fluxPerson
()
{
MethodParameter
param
=
this
.
testMethod
.
annot
(
requestPart
()).
arg
(
Flux
.
class
,
Person
.
class
);
...
...
@@ -154,6 +177,15 @@ public class RequestPartMethodArgumentResolverTests {
assertEquals
(
"James"
,
persons
.
get
(
1
).
getName
());
}
@Test
// gh-23060
public
void
fluxPersonNotRequired
()
{
MethodParameter
param
=
this
.
testMethod
.
annot
(
requestPart
().
notRequired
()).
arg
(
Flux
.
class
,
Person
.
class
);
MultipartBodyBuilder
bodyBuilder
=
new
MultipartBodyBuilder
();
Flux
<
Person
>
actual
=
resolveArgument
(
param
,
bodyBuilder
);
assertEquals
(
Collections
.
emptyList
(),
actual
.
collectList
().
block
());
}
@Test
public
void
part
()
{
MethodParameter
param
=
this
.
testMethod
.
annot
(
requestPart
()).
arg
(
Part
.
class
);
...
...
@@ -177,6 +209,15 @@ public class RequestPartMethodArgumentResolverTests {
assertEquals
(
"{\"name\":\"James\"}"
,
partToUtf8String
(
actual
.
get
(
1
)));
}
@Test
// gh-23060
public
void
listPartNotRequired
()
{
MethodParameter
param
=
this
.
testMethod
.
annot
(
requestPart
().
notRequired
()).
arg
(
List
.
class
,
Part
.
class
);
MultipartBodyBuilder
bodyBuilder
=
new
MultipartBodyBuilder
();
List
<
Part
>
actual
=
resolveArgument
(
param
,
bodyBuilder
);
assertEquals
(
Collections
.
emptyList
(),
actual
);
}
@Test
public
void
monoPart
()
{
MethodParameter
param
=
this
.
testMethod
.
annot
(
requestPart
()).
arg
(
Mono
.
class
,
Part
.
class
);
...
...
@@ -188,6 +229,15 @@ public class RequestPartMethodArgumentResolverTests {
assertEquals
(
"{\"name\":\"Jones\"}"
,
partToUtf8String
(
part
));
}
@Test
// gh-23060
public
void
monoPartNotRequired
()
{
MethodParameter
param
=
this
.
testMethod
.
annot
(
requestPart
().
notRequired
()).
arg
(
Mono
.
class
,
Part
.
class
);
MultipartBodyBuilder
bodyBuilder
=
new
MultipartBodyBuilder
();
Mono
<
Part
>
actual
=
resolveArgument
(
param
,
bodyBuilder
);
assertNull
(
actual
.
block
());
}
@Test
public
void
fluxPart
()
{
MethodParameter
param
=
this
.
testMethod
.
annot
(
requestPart
()).
arg
(
Flux
.
class
,
Part
.
class
);
...
...
@@ -201,6 +251,15 @@ public class RequestPartMethodArgumentResolverTests {
assertEquals
(
"{\"name\":\"James\"}"
,
partToUtf8String
(
parts
.
get
(
1
)));
}
@Test
// gh-23060
public
void
fluxPartNotRequired
()
{
MethodParameter
param
=
this
.
testMethod
.
annot
(
requestPart
().
notRequired
()).
arg
(
Flux
.
class
,
Part
.
class
);
MultipartBodyBuilder
bodyBuilder
=
new
MultipartBodyBuilder
();
Flux
<
Part
>
actual
=
resolveArgument
(
param
,
bodyBuilder
);
assertEquals
(
Collections
.
emptyList
(),
actual
.
collectList
().
block
());
}
@Test
public
void
personRequired
()
{
MethodParameter
param
=
this
.
testMethod
.
annot
(
requestPart
()).
arg
(
Person
.
class
);
...
...
@@ -278,7 +337,13 @@ public class RequestPartMethodArgumentResolverTests {
@RequestPart
(
"name"
)
Flux
<
Part
>
partFlux
,
@RequestPart
(
"name"
)
List
<
Part
>
partList
,
@RequestPart
(
name
=
"anotherPart"
,
required
=
false
)
Person
anotherPerson
,
@RequestPart
(
name
=
"name"
,
required
=
false
)
Mono
<
Person
>
anotherPersonMono
,
@RequestPart
(
name
=
"name"
,
required
=
false
)
Flux
<
Person
>
anotherPersonFlux
,
@RequestPart
(
name
=
"name"
,
required
=
false
)
List
<
Person
>
anotherPersonList
,
@RequestPart
(
name
=
"anotherPart"
,
required
=
false
)
Part
anotherPart
,
@RequestPart
(
name
=
"name"
,
required
=
false
)
Mono
<
Part
>
anotherPartMono
,
@RequestPart
(
name
=
"name"
,
required
=
false
)
Flux
<
Part
>
anotherPartFlux
,
@RequestPart
(
name
=
"name"
,
required
=
false
)
List
<
Part
>
anotherPartList
,
Person
notAnnotated
)
{}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录