Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
b6449baa
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,体验更适合开发者的 AI 搜索 >>
提交
b6449baa
编写于
4月 06, 2015
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
List all unsatisfied request param groups
Issue: SPR-12854
上级
0b8554f9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
79 addition
and
21 deletion
+79
-21
spring-web/src/main/java/org/springframework/web/bind/UnsatisfiedServletRequestParameterException.java
...web/bind/UnsatisfiedServletRequestParameterException.java
+46
-5
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java
.../servlet/mvc/method/RequestMappingInfoHandlerMapping.java
+14
-11
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java
...let/mvc/method/RequestMappingInfoHandlerMappingTests.java
+19
-5
未找到文件。
spring-web/src/main/java/org/springframework/web/bind/UnsatisfiedServletRequestParameterException.java
浏览文件 @
b6449baa
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -16,9 +16,13 @@
package
org.springframework.web.bind
;
import
java.util.Arrays
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.util.Assert
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
...
...
@@ -34,7 +38,7 @@ import org.springframework.util.StringUtils;
@SuppressWarnings
(
"serial"
)
public
class
UnsatisfiedServletRequestParameterException
extends
ServletRequestBindingException
{
private
final
String
[]
paramConditions
;
private
final
List
<
String
[]>
paramConditions
;
private
final
Map
<
String
,
String
[]>
actualParams
;
...
...
@@ -46,6 +50,21 @@ public class UnsatisfiedServletRequestParameterException extends ServletRequestB
*/
public
UnsatisfiedServletRequestParameterException
(
String
[]
paramConditions
,
Map
<
String
,
String
[]>
actualParams
)
{
super
(
""
);
this
.
paramConditions
=
Arrays
.<
String
[]>
asList
(
paramConditions
);
this
.
actualParams
=
actualParams
;
}
/**
* Create a new UnsatisfiedServletRequestParameterException.
* @param paramConditions all sets of parameter conditions that have been violated
* @param actualParams the actual parameter Map associated with the ServletRequest
* @since 4.2
*/
public
UnsatisfiedServletRequestParameterException
(
List
<
String
[]>
paramConditions
,
Map
<
String
,
String
[]>
actualParams
)
{
super
(
""
);
Assert
.
isTrue
(!
CollectionUtils
.
isEmpty
(
paramConditions
));
this
.
paramConditions
=
paramConditions
;
this
.
actualParams
=
actualParams
;
}
...
...
@@ -53,8 +72,20 @@ public class UnsatisfiedServletRequestParameterException extends ServletRequestB
@Override
public
String
getMessage
()
{
return
"Parameter conditions \""
+
StringUtils
.
arrayToDelimitedString
(
this
.
paramConditions
,
", "
)
+
"\" not met for actual request parameters: "
+
requestParameterMapToString
(
this
.
actualParams
);
StringBuilder
sb
=
new
StringBuilder
(
"Parameter conditions "
);
int
i
=
0
;
for
(
String
[]
conditions
:
this
.
paramConditions
)
{
if
(
i
>
0
)
{
sb
.
append
(
" OR "
);
}
sb
.
append
(
"\""
);
sb
.
append
(
StringUtils
.
arrayToDelimitedString
(
conditions
,
", "
));
sb
.
append
(
"\""
);
i
++;
}
sb
.
append
(
" not met for actual request parameters: "
);
sb
.
append
(
requestParameterMapToString
(
this
.
actualParams
));
return
sb
.
toString
();
}
private
static
String
requestParameterMapToString
(
Map
<
String
,
String
[]>
actualParams
)
{
...
...
@@ -70,10 +101,20 @@ public class UnsatisfiedServletRequestParameterException extends ServletRequestB
}
/**
* Return the parameter conditions that have been violated.
* Return the parameter conditions that have been violated or the first group
* in case of multiple groups.
* @see org.springframework.web.bind.annotation.RequestMapping#params()
*/
public
final
String
[]
getParamConditions
()
{
return
this
.
paramConditions
.
get
(
0
);
}
/**
* Return all parameter condition groups that have been violated.
* @see org.springframework.web.bind.annotation.RequestMapping#params()
* @since 4.2
*/
public
final
List
<
String
[]>
getParamConditionGroups
()
{
return
this
.
paramConditions
;
}
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java
浏览文件 @
b6449baa
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -22,6 +22,7 @@ import java.util.Comparator;
import
java.util.HashSet
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
...
...
@@ -205,7 +206,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
Set
<
MediaType
>
consumableMediaTypes
;
Set
<
MediaType
>
producibleMediaTypes
;
Set
<
String
>
paramConditions
;
List
<
String
[]
>
paramConditions
;
if
(
patternAndMethodMatches
.
isEmpty
())
{
consumableMediaTypes
=
getConsumableMediaTypes
(
request
,
patternMatches
);
...
...
@@ -234,8 +235,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
throw
new
HttpMediaTypeNotAcceptableException
(
new
ArrayList
<
MediaType
>(
producibleMediaTypes
));
}
else
if
(!
CollectionUtils
.
isEmpty
(
paramConditions
))
{
String
[]
params
=
paramConditions
.
toArray
(
new
String
[
paramConditions
.
size
()]);
throw
new
UnsatisfiedServletRequestParameterException
(
params
,
request
.
getParameterMap
());
throw
new
UnsatisfiedServletRequestParameterException
(
paramConditions
,
request
.
getParameterMap
());
}
else
{
return
null
;
...
...
@@ -262,18 +262,21 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
return
result
;
}
private
Set
<
String
>
getRequestParams
(
HttpServletRequest
request
,
Set
<
RequestMappingInfo
>
partialMatches
)
{
private
List
<
String
[]>
getRequestParams
(
HttpServletRequest
request
,
Set
<
RequestMappingInfo
>
partialMatches
)
{
List
<
String
[]>
result
=
new
ArrayList
<
String
[]>();
for
(
RequestMappingInfo
partialMatch
:
partialMatches
)
{
ParamsRequestCondition
condition
=
partialMatch
.
getParamsCondition
();
if
(!
CollectionUtils
.
isEmpty
(
condition
.
getExpressions
())
&&
(
condition
.
getMatchingCondition
(
request
)
==
null
))
{
Set
<
String
>
expressions
=
new
HashSet
<
String
>();
for
(
NameValueExpression
<
String
>
expr
:
condition
.
getExpressions
())
{
expressions
.
add
(
expr
.
toString
());
Set
<
NameValueExpression
<
String
>>
expressions
=
condition
.
getExpressions
();
if
(!
CollectionUtils
.
isEmpty
(
expressions
)
&&
condition
.
getMatchingCondition
(
request
)
==
null
)
{
int
i
=
0
;
String
[]
array
=
new
String
[
expressions
.
size
()];
for
(
NameValueExpression
<
String
>
expression
:
expressions
)
{
array
[
i
++]
=
expression
.
toString
();
}
re
turn
expressions
;
re
sult
.
add
(
array
)
;
}
}
return
null
;
return
result
;
}
}
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java
浏览文件 @
b6449baa
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -16,12 +16,17 @@
package
org.springframework.web.servlet.mvc.method
;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
junit
.
Assert
.*;
import
java.lang.reflect.Method
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
javax.servlet.http.HttpServletRequest
;
import
org.junit.Before
;
...
...
@@ -54,8 +59,6 @@ import org.springframework.web.servlet.mvc.condition.ProducesRequestCondition;
import
org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition
;
import
org.springframework.web.util.UrlPathHelper
;
import
static
org
.
junit
.
Assert
.*;
/**
* Test fixture with {@link RequestMappingInfoHandlerMapping}.
*
...
...
@@ -211,6 +214,8 @@ public class RequestMappingInfoHandlerMappingTests {
}
}
// SPR-12854
@Test
public
void
testUnsatisfiedServletRequestParameterException
()
throws
Exception
{
try
{
...
...
@@ -219,8 +224,10 @@ public class RequestMappingInfoHandlerMappingTests {
fail
(
"UnsatisfiedServletRequestParameterException expected"
);
}
catch
(
UnsatisfiedServletRequestParameterException
ex
)
{
assertArrayEquals
(
"Invalid request parameter conditions"
,
new
String
[]
{
"foo=bar"
},
ex
.
getParamConditions
());
List
<
String
[]>
groups
=
ex
.
getParamConditionGroups
();
assertEquals
(
2
,
groups
.
size
());
assertThat
(
Arrays
.
asList
(
"foo=bar"
,
"bar=baz"
),
containsInAnyOrder
(
groups
.
get
(
0
)[
0
],
groups
.
get
(
1
)[
0
]));
}
}
...
...
@@ -408,6 +415,7 @@ public class RequestMappingInfoHandlerMappingTests {
}
@SuppressWarnings
(
"unused"
)
@Controller
private
static
class
TestController
{
...
...
@@ -441,6 +449,11 @@ public class RequestMappingInfoHandlerMappingTests {
return
""
;
}
@RequestMapping
(
value
=
"/params"
,
params
=
"bar=baz"
)
public
String
param2
()
{
return
""
;
}
@RequestMapping
(
value
=
"/content"
,
produces
=
"application/xml"
)
public
String
xmlContent
()
{
return
""
;
...
...
@@ -452,6 +465,7 @@ public class RequestMappingInfoHandlerMappingTests {
}
}
@SuppressWarnings
(
"unused"
)
@Controller
private
static
class
UserController
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录