Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
572c6687
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 搜索 >>
提交
572c6687
编写于
1月 19, 2018
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
5520e730
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
110 addition
and
109 deletion
+110
-109
spring-context/src/main/java/org/springframework/cache/interceptor/CacheProxyFactoryBean.java
...ingframework/cache/interceptor/CacheProxyFactoryBean.java
+4
-4
spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java
...ontext/support/ReloadableResourceBundleMessageSource.java
+5
-4
spring-core/src/test/java/org/springframework/core/BridgeMethodResolverTests.java
...a/org/springframework/core/BridgeMethodResolverTests.java
+1
-1
spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java
...pringframework/expression/spel/ast/FunctionReference.java
+7
-6
spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlParameter.java
...main/java/org/springframework/jdbc/core/SqlParameter.java
+5
-5
spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataContext.java
...ringframework/jdbc/core/metadata/CallMetaDataContext.java
+13
-13
spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataContext.java
...ingframework/jdbc/core/metadata/TableMetaDataContext.java
+9
-9
spring-jms/src/main/java/org/springframework/jms/config/MethodJmsListenerEndpoint.java
...springframework/jms/config/MethodJmsListenerEndpoint.java
+7
-6
spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java
...g/springframework/web/util/HierarchicalUriComponents.java
+3
-3
spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java
...ava/org/springframework/web/client/RestTemplateTests.java
+37
-37
spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java
...g/springframework/web/util/UriComponentsBuilderTests.java
+19
-21
未找到文件。
spring-context/src/main/java/org/springframework/cache/interceptor/CacheProxyFactoryBean.java
浏览文件 @
572c6687
...
...
@@ -54,7 +54,7 @@ public class CacheProxyFactoryBean extends AbstractSingletonProxyFactoryBean
/**
* Set
the sources used
to find cache operations.
* Set
one or more sources
to find cache operations.
* @see CacheInterceptor#setCacheOperationSources
*/
public
void
setCacheOperationSources
(
CacheOperationSource
...
cacheOperationSources
)
{
...
...
@@ -95,9 +95,9 @@ public class CacheProxyFactoryBean extends AbstractSingletonProxyFactoryBean
}
/**
* Set a pointcut, i.e
a bean that can cause conditional invocation
*
of the CacheInterceptor depending on
method and attributes passed.
* Note: Additional interceptors are always invoked.
* Set a pointcut, i.e
. a bean that triggers conditional invocation of the
*
{@link CacheInterceptor} depending on the
method and attributes passed.
*
<p>
Note: Additional interceptors are always invoked.
* @see #setPreInterceptors
* @see #setPostInterceptors
*/
...
...
spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java
浏览文件 @
572c6687
...
...
@@ -85,7 +85,8 @@ import org.springframework.util.StringUtils;
* @see ResourceBundleMessageSource
* @see java.util.ResourceBundle
*/
public
class
ReloadableResourceBundleMessageSource
extends
AbstractResourceBasedMessageSource
implements
ResourceLoaderAware
{
public
class
ReloadableResourceBundleMessageSource
extends
AbstractResourceBasedMessageSource
implements
ResourceLoaderAware
{
private
static
final
String
PROPERTIES_SUFFIX
=
".properties"
;
...
...
@@ -101,13 +102,13 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
private
ResourceLoader
resourceLoader
=
new
DefaultResourceLoader
();
/
** Cache to hold filename lists per Locale */
/
/ Cache to hold filename lists per Locale
private
final
ConcurrentMap
<
String
,
Map
<
Locale
,
List
<
String
>>>
cachedFilenames
=
new
ConcurrentHashMap
<>();
/
** Cache to hold already loaded properties per filename */
/
/ Cache to hold already loaded properties per filename
private
final
ConcurrentMap
<
String
,
PropertiesHolder
>
cachedProperties
=
new
ConcurrentHashMap
<>();
/
** Cache to hold merged loaded properties per locale */
/
/ Cache to hold already loaded properties per filename
private
final
ConcurrentMap
<
Locale
,
PropertiesHolder
>
cachedMergedProperties
=
new
ConcurrentHashMap
<>();
...
...
spring-core/src/test/java/org/springframework/core/BridgeMethodResolverTests.java
浏览文件 @
572c6687
...
...
@@ -741,7 +741,7 @@ public class BridgeMethodResolverTests {
}
@SuppressWarnings
({
"unused"
,
"unchecked"
})
@SuppressWarnings
({
"unused"
,
"unchecked"
})
public
static
abstract
class
GenericEventBroadcasterImpl
<
T
extends
Event
>
extends
GenericBroadcasterImpl
implements
EventBroadcaster
{
...
...
spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java
浏览文件 @
572c6687
...
...
@@ -72,9 +72,8 @@ public class FunctionReference extends SpelNodeImpl {
if
(
value
==
TypedValue
.
NULL
)
{
throw
new
SpelEvaluationException
(
getStartPosition
(),
SpelMessage
.
FUNCTION_NOT_DEFINED
,
this
.
name
);
}
// Two possibilities: a lambda function or a Java static method registered as a function
if
(!(
value
.
getValue
()
instanceof
Method
))
{
// Two possibilities: a lambda function or a Java static method registered as a function
throw
new
SpelEvaluationException
(
SpelMessage
.
FUNCTION_REFERENCE_CANNOT_BE_INVOKED
,
this
.
name
,
value
.
getClass
());
}
...
...
@@ -98,11 +97,13 @@ public class FunctionReference extends SpelNodeImpl {
private
TypedValue
executeFunctionJLRMethod
(
ExpressionState
state
,
Method
method
)
throws
EvaluationException
{
Object
[]
functionArgs
=
getArguments
(
state
);
if
(!
method
.
isVarArgs
()
&&
method
.
getParameterCount
()
!=
functionArgs
.
length
)
{
throw
new
SpelEvaluationException
(
SpelMessage
.
INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION
,
functionArgs
.
length
,
method
.
getParameterCount
());
if
(!
method
.
isVarArgs
())
{
int
declaredParamCount
=
method
.
getParameterCount
();
if
(
declaredParamCount
!=
functionArgs
.
length
)
{
throw
new
SpelEvaluationException
(
SpelMessage
.
INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION
,
functionArgs
.
length
,
declaredParamCount
);
}
}
// Only static methods can be called in this way
if
(!
Modifier
.
isStatic
(
method
.
getModifiers
()))
{
throw
new
SpelEvaluationException
(
getStartPosition
(),
SpelMessage
.
FUNCTION_MUST_BE_STATIC
,
ClassUtils
.
getQualifiedMethodName
(
method
),
this
.
name
);
...
...
spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlParameter.java
浏览文件 @
572c6687
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -36,18 +36,18 @@ import org.springframework.util.Assert;
*/
public
class
SqlParameter
{
/
** The name of the parameter, if any */
/
/ The name of the parameter, if any
@Nullable
private
String
name
;
/
** SQL type constant from {@code java.sql.Types} */
/
/ SQL type constant from {@code java.sql.Types}
private
final
int
sqlType
;
/
** Used for types that are user-named like: STRUCT, DISTINCT, JAVA_OBJECT, named array types */
/
/ Used for types that are user-named like: STRUCT, DISTINCT, JAVA_OBJECT, named array types
@Nullable
private
String
typeName
;
/
** The scale to apply in case of a NUMERIC or DECIMAL type, if any */
/
/ The scale to apply in case of a NUMERIC or DECIMAL type, if any
@Nullable
private
Integer
scale
;
...
...
spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataContext.java
浏览文件 @
572c6687
...
...
@@ -53,47 +53,47 @@ import org.springframework.util.StringUtils;
*/
public
class
CallMetaDataContext
{
/
** Logger available to subclasses */
/
/ Logger available to subclasses
protected
final
Log
logger
=
LogFactory
.
getLog
(
getClass
());
/
** Name of procedure to call **/
/
/ Name of procedure to call
@Nullable
private
String
procedureName
;
/
** Name of catalog for call **/
/
/ Name of catalog for call
@Nullable
private
String
catalogName
;
/
** Name of schema for call **/
/
/ Name of schema for call
@Nullable
private
String
schemaName
;
/
** List of SqlParameter objects to be used in call execution */
/
/ List of SqlParameter objects to be used in call execution
private
List
<
SqlParameter
>
callParameters
=
new
ArrayList
<>();
/
** Actual name to use for the return value in the output map */
/
/ Actual name to use for the return value in the output map
@Nullable
private
String
actualFunctionReturnName
;
/
** Set of in parameter names to exclude use for any not listed */
/
/ Set of in parameter names to exclude use for any not listed
private
Set
<
String
>
limitedInParameterNames
=
new
HashSet
<>();
/
** List of SqlParameter names for out parameters */
/
/ List of SqlParameter names for out parameters
private
List
<
String
>
outParameterNames
=
new
ArrayList
<>();
/
** Indicates whether this is a procedure or a function **/
/
/ Indicates whether this is a procedure or a function
private
boolean
function
=
false
;
/
** Indicates whether this procedure's return value should be included **/
/
/ Indicates whether this procedure's return value should be included
private
boolean
returnValueRequired
=
false
;
/
** Should we access call parameter meta data info or not */
/
/ Should we access call parameter meta data info or not
private
boolean
accessCallParameterMetaData
=
true
;
/
** Should we bind parameter by name **/
/
/ Should we bind parameter by name
private
boolean
namedBinding
;
/
** The provider of call meta data */
/
/ The provider of call meta data
@Nullable
private
CallMetaDataProvider
metaDataProvider
;
...
...
spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataContext.java
浏览文件 @
572c6687
...
...
@@ -45,35 +45,35 @@ import org.springframework.util.Assert;
*/
public
class
TableMetaDataContext
{
/
** Logger available to subclasses */
/
/ Logger available to subclasses
protected
final
Log
logger
=
LogFactory
.
getLog
(
getClass
());
/
** Name of table for this context */
/
/ Name of table for this context
@Nullable
private
String
tableName
;
/
** Name of catalog for this context */
/
/ Name of catalog for this context
@Nullable
private
String
catalogName
;
/
** Name of schema for this context */
/
/ Name of schema for this context
@Nullable
private
String
schemaName
;
/
** List of columns objects to be used in this context */
/
/ List of columns objects to be used in this context
private
List
<
String
>
tableColumns
=
new
ArrayList
<>();
/
** should we access insert parameter meta data info or not */
/
/ Should we access insert parameter meta data info or not
private
boolean
accessTableColumnMetaData
=
true
;
/
** should we override default for including synonyms for meta data lookups */
/
/ Should we override default for including synonyms for meta data lookups
private
boolean
overrideIncludeSynonymsDefault
=
false
;
/
** the provider of table meta data */
/
/ The provider of table meta data
@Nullable
private
TableMetaDataProvider
metaDataProvider
;
/
** are we using generated key columns */
/
/ Are we using generated key columns
private
boolean
generatedKeyColumnsUsed
=
false
;
...
...
spring-jms/src/main/java/org/springframework/jms/config/MethodJmsListenerEndpoint.java
浏览文件 @
572c6687
...
...
@@ -105,13 +105,14 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple
return
this
.
mostSpecificMethod
;
}
Method
method
=
getMethod
();
if
(
method
!=
null
&&
AopUtils
.
isAopProxy
(
this
.
bean
)
)
{
Class
<?>
targetClass
=
AopProxyUtils
.
ultimateTargetClass
(
this
.
bean
);
return
AopUtils
.
getMostSpecificMethod
(
method
,
targetClass
);
}
else
{
return
method
;
if
(
method
!=
null
)
{
Object
bean
=
getBean
(
);
if
(
AopUtils
.
isAopProxy
(
bean
))
{
Class
<?>
targetClass
=
AopProxyUtils
.
ultimateTargetClass
(
bean
);
method
=
AopUtils
.
getMostSpecificMethod
(
method
,
targetClass
);
}
}
return
method
;
}
/**
...
...
spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java
浏览文件 @
572c6687
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -702,7 +702,7 @@ final class HierarchicalUriComponents extends UriComponents {
@Override
public
List
<
String
>
getPathSegments
()
{
String
[]
segments
=
StringUtils
.
tokenizeToStringArray
(
this
.
path
,
PATH_DELIMITER_STRING
);
String
[]
segments
=
StringUtils
.
tokenizeToStringArray
(
getPath
()
,
PATH_DELIMITER_STRING
);
return
Collections
.
unmodifiableList
(
Arrays
.
asList
(
segments
));
}
...
...
@@ -714,7 +714,7 @@ final class HierarchicalUriComponents extends UriComponents {
@Override
public
void
verify
()
{
verifyUriComponent
(
this
.
path
,
Type
.
PATH
);
verifyUriComponent
(
getPath
()
,
Type
.
PATH
);
}
@Override
...
...
spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java
浏览文件 @
572c6687
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -50,7 +50,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import
static
org
.
hamcrest
.
collection
.
IsIterableContainingInOrder
.
contains
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
mockito
.
BDDMockito
.*;
import
static
org
.
springframework
.
http
.
HttpMethod
.
POST
;
import
static
org
.
springframework
.
http
.
HttpMethod
.
*
;
import
static
org
.
springframework
.
http
.
MediaType
.*;
/**
...
...
@@ -89,7 +89,7 @@ public class RestTemplateTests {
@Test
public
void
varArgsTemplateVariables
()
throws
Exception
{
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com/hotels/42/bookings/21"
),
HttpMethod
.
GET
))
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com/hotels/42/bookings/21"
),
GET
))
.
willReturn
(
request
);
given
(
request
.
execute
()).
willReturn
(
response
);
given
(
errorHandler
.
hasError
(
response
)).
willReturn
(
false
);
...
...
@@ -97,7 +97,7 @@ public class RestTemplateTests {
given
(
response
.
getStatusCode
()).
willReturn
(
status
);
given
(
response
.
getStatusText
()).
willReturn
(
status
.
getReasonPhrase
());
template
.
execute
(
"http://example.com/hotels/{hotel}/bookings/{booking}"
,
HttpMethod
.
GET
,
null
,
null
,
"42"
,
template
.
execute
(
"http://example.com/hotels/{hotel}/bookings/{booking}"
,
GET
,
null
,
null
,
"42"
,
"21"
);
verify
(
response
).
close
();
...
...
@@ -105,7 +105,7 @@ public class RestTemplateTests {
@Test
public
void
varArgsNullTemplateVariable
()
throws
Exception
{
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com/-foo"
),
HttpMethod
.
GET
))
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com/-foo"
),
GET
))
.
willReturn
(
request
);
given
(
request
.
execute
()).
willReturn
(
response
);
given
(
errorHandler
.
hasError
(
response
)).
willReturn
(
false
);
...
...
@@ -113,14 +113,14 @@ public class RestTemplateTests {
given
(
response
.
getStatusCode
()).
willReturn
(
status
);
given
(
response
.
getStatusText
()).
willReturn
(
status
.
getReasonPhrase
());
template
.
execute
(
"http://example.com/{first}-{last}"
,
HttpMethod
.
GET
,
null
,
null
,
null
,
"foo"
);
template
.
execute
(
"http://example.com/{first}-{last}"
,
GET
,
null
,
null
,
null
,
"foo"
);
verify
(
response
).
close
();
}
@Test
public
void
mapTemplateVariables
()
throws
Exception
{
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com/hotels/42/bookings/42"
),
HttpMethod
.
GET
))
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com/hotels/42/bookings/42"
),
GET
))
.
willReturn
(
request
);
given
(
request
.
execute
()).
willReturn
(
response
);
given
(
errorHandler
.
hasError
(
response
)).
willReturn
(
false
);
...
...
@@ -129,14 +129,14 @@ public class RestTemplateTests {
given
(
response
.
getStatusText
()).
willReturn
(
status
.
getReasonPhrase
());
Map
<
String
,
String
>
vars
=
Collections
.
singletonMap
(
"hotel"
,
"42"
);
template
.
execute
(
"http://example.com/hotels/{hotel}/bookings/{hotel}"
,
HttpMethod
.
GET
,
null
,
null
,
vars
);
template
.
execute
(
"http://example.com/hotels/{hotel}/bookings/{hotel}"
,
GET
,
null
,
null
,
vars
);
verify
(
response
).
close
();
}
@Test
public
void
mapNullTemplateVariable
()
throws
Exception
{
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com/-foo"
),
HttpMethod
.
GET
))
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com/-foo"
),
GET
))
.
willReturn
(
request
);
given
(
request
.
execute
()).
willReturn
(
response
);
given
(
errorHandler
.
hasError
(
response
)).
willReturn
(
false
);
...
...
@@ -147,7 +147,7 @@ public class RestTemplateTests {
Map
<
String
,
String
>
vars
=
new
HashMap
<>(
2
);
vars
.
put
(
"first"
,
null
);
vars
.
put
(
"last"
,
"foo"
);
template
.
execute
(
"http://example.com/{first}-{last}"
,
HttpMethod
.
GET
,
null
,
null
,
vars
);
template
.
execute
(
"http://example.com/{first}-{last}"
,
GET
,
null
,
null
,
vars
);
verify
(
response
).
close
();
}
...
...
@@ -155,14 +155,14 @@ public class RestTemplateTests {
@Test
// SPR-15201
public
void
uriTemplateWithTrailingSlash
()
throws
Exception
{
String
url
=
"http://example.com/spring/"
;
given
(
requestFactory
.
createRequest
(
new
URI
(
url
),
HttpMethod
.
GET
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
new
URI
(
url
),
GET
)).
willReturn
(
request
);
given
(
request
.
execute
()).
willReturn
(
response
);
given
(
errorHandler
.
hasError
(
response
)).
willReturn
(
false
);
HttpStatus
status
=
HttpStatus
.
OK
;
given
(
response
.
getStatusCode
()).
willReturn
(
status
);
given
(
response
.
getStatusText
()).
willReturn
(
status
.
getReasonPhrase
());
template
.
execute
(
url
,
HttpMethod
.
GET
,
null
,
null
);
template
.
execute
(
url
,
GET
,
null
,
null
);
verify
(
response
).
close
();
}
...
...
@@ -170,16 +170,16 @@ public class RestTemplateTests {
@Test
public
void
errorHandling
()
throws
Exception
{
URI
uri
=
new
URI
(
"http://example.com"
);
given
(
requestFactory
.
createRequest
(
uri
,
HttpMethod
.
GET
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
uri
,
GET
)).
willReturn
(
request
);
given
(
request
.
execute
()).
willReturn
(
response
);
given
(
errorHandler
.
hasError
(
response
)).
willReturn
(
true
);
given
(
response
.
getStatusCode
()).
willReturn
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
given
(
response
.
getStatusText
()).
willReturn
(
"Internal Server Error"
);
willThrow
(
new
HttpServerErrorException
(
HttpStatus
.
INTERNAL_SERVER_ERROR
))
.
given
(
errorHandler
).
handleError
(
uri
,
HttpMethod
.
GET
,
response
);
.
given
(
errorHandler
).
handleError
(
uri
,
GET
,
response
);
try
{
template
.
execute
(
"http://example.com"
,
HttpMethod
.
GET
,
null
,
null
);
template
.
execute
(
"http://example.com"
,
GET
,
null
,
null
);
fail
(
"HttpServerErrorException expected"
);
}
catch
(
HttpServerErrorException
ex
)
{
...
...
@@ -194,7 +194,7 @@ public class RestTemplateTests {
given
(
converter
.
canRead
(
String
.
class
,
null
)).
willReturn
(
true
);
MediaType
textPlain
=
new
MediaType
(
"text"
,
"plain"
);
given
(
converter
.
getSupportedMediaTypes
()).
willReturn
(
Collections
.
singletonList
(
textPlain
));
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
HttpMethod
.
GET
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
GET
)).
willReturn
(
request
);
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
given
(
request
.
getHeaders
()).
willReturn
(
requestHeaders
);
given
(
request
.
execute
()).
willReturn
(
response
);
...
...
@@ -224,7 +224,7 @@ public class RestTemplateTests {
given
(
converter
.
canRead
(
String
.
class
,
null
)).
willReturn
(
true
);
MediaType
supportedMediaType
=
new
MediaType
(
"foo"
,
"bar"
);
given
(
converter
.
getSupportedMediaTypes
()).
willReturn
(
Collections
.
singletonList
(
supportedMediaType
));
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com/resource"
),
HttpMethod
.
GET
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com/resource"
),
GET
)).
willReturn
(
request
);
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
given
(
request
.
getHeaders
()).
willReturn
(
requestHeaders
);
given
(
request
.
execute
()).
willReturn
(
response
);
...
...
@@ -258,7 +258,7 @@ public class RestTemplateTests {
given
(
converter
.
canRead
(
String
.
class
,
null
)).
willReturn
(
true
);
MediaType
textPlain
=
new
MediaType
(
"text"
,
"plain"
);
given
(
converter
.
getSupportedMediaTypes
()).
willReturn
(
Collections
.
singletonList
(
textPlain
));
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
HttpMethod
.
GET
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
GET
)).
willReturn
(
request
);
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
given
(
request
.
getHeaders
()).
willReturn
(
requestHeaders
);
given
(
request
.
execute
()).
willReturn
(
response
);
...
...
@@ -289,7 +289,7 @@ public class RestTemplateTests {
template
.
setUriTemplateHandler
(
uriTemplateHandler
);
URI
expectedUri
=
new
URI
(
"http://example.com/hotels/1/pic/pics%2Flogo.png/size/150x150"
);
given
(
requestFactory
.
createRequest
(
expectedUri
,
HttpMethod
.
GET
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
expectedUri
,
GET
)).
willReturn
(
request
);
given
(
request
.
getHeaders
()).
willReturn
(
new
HttpHeaders
());
given
(
request
.
execute
()).
willReturn
(
response
);
...
...
@@ -312,7 +312,7 @@ public class RestTemplateTests {
@Test
public
void
headForHeaders
()
throws
Exception
{
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
H
ttpMethod
.
H
EAD
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
HEAD
)).
willReturn
(
request
);
given
(
request
.
execute
()).
willReturn
(
response
);
given
(
errorHandler
.
hasError
(
response
)).
willReturn
(
false
);
HttpHeaders
responseHeaders
=
new
HttpHeaders
();
...
...
@@ -574,7 +574,7 @@ public class RestTemplateTests {
@Test
public
void
put
()
throws
Exception
{
given
(
converter
.
canWrite
(
String
.
class
,
null
)).
willReturn
(
true
);
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
HttpMethod
.
PUT
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
PUT
)).
willReturn
(
request
);
String
helloWorld
=
"Hello World"
;
converter
.
write
(
helloWorld
,
null
,
request
);
given
(
request
.
execute
()).
willReturn
(
response
);
...
...
@@ -590,7 +590,7 @@ public class RestTemplateTests {
@Test
public
void
putNull
()
throws
Exception
{
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
HttpMethod
.
PUT
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
PUT
)).
willReturn
(
request
);
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
given
(
request
.
getHeaders
()).
willReturn
(
requestHeaders
);
given
(
request
.
execute
()).
willReturn
(
response
);
...
...
@@ -610,7 +610,7 @@ public class RestTemplateTests {
MediaType
textPlain
=
new
MediaType
(
"text"
,
"plain"
);
given
(
converter
.
canRead
(
Integer
.
class
,
null
)).
willReturn
(
true
);
given
(
converter
.
getSupportedMediaTypes
()).
willReturn
(
Collections
.
singletonList
(
textPlain
));
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
HttpMethod
.
PATCH
)).
willReturn
(
this
.
request
);
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
PATCH
)).
willReturn
(
this
.
request
);
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
given
(
this
.
request
.
getHeaders
()).
willReturn
(
requestHeaders
);
String
request
=
"Hello World"
;
...
...
@@ -643,7 +643,7 @@ public class RestTemplateTests {
MediaType
textPlain
=
new
MediaType
(
"text"
,
"plain"
);
given
(
converter
.
canRead
(
Integer
.
class
,
null
)).
willReturn
(
true
);
given
(
converter
.
getSupportedMediaTypes
()).
willReturn
(
Collections
.
singletonList
(
textPlain
));
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
HttpMethod
.
PATCH
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
PATCH
)).
willReturn
(
request
);
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
given
(
request
.
getHeaders
()).
willReturn
(
requestHeaders
);
given
(
request
.
execute
()).
willReturn
(
response
);
...
...
@@ -671,7 +671,7 @@ public class RestTemplateTests {
@Test
public
void
delete
()
throws
Exception
{
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
HttpMethod
.
DELETE
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
DELETE
)).
willReturn
(
request
);
given
(
request
.
execute
()).
willReturn
(
response
);
given
(
errorHandler
.
hasError
(
response
)).
willReturn
(
false
);
HttpStatus
status
=
HttpStatus
.
OK
;
...
...
@@ -685,11 +685,11 @@ public class RestTemplateTests {
@Test
public
void
optionsForAllow
()
throws
Exception
{
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
HttpMethod
.
OPTIONS
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
OPTIONS
)).
willReturn
(
request
);
given
(
request
.
execute
()).
willReturn
(
response
);
given
(
errorHandler
.
hasError
(
response
)).
willReturn
(
false
);
HttpHeaders
responseHeaders
=
new
HttpHeaders
();
EnumSet
<
HttpMethod
>
expected
=
EnumSet
.
of
(
HttpMethod
.
GET
,
POST
);
EnumSet
<
HttpMethod
>
expected
=
EnumSet
.
of
(
GET
,
POST
);
responseHeaders
.
setAllow
(
expected
);
given
(
response
.
getHeaders
()).
willReturn
(
responseHeaders
);
HttpStatus
status
=
HttpStatus
.
OK
;
...
...
@@ -702,14 +702,14 @@ public class RestTemplateTests {
verify
(
response
).
close
();
}
@Test
// Issue:
SPR-9325, SPR-13860
@Test
//
SPR-9325, SPR-13860
public
void
ioException
()
throws
Exception
{
String
url
=
"http://example.com/resource?access_token=123"
;
given
(
converter
.
canRead
(
String
.
class
,
null
)).
willReturn
(
true
);
MediaType
mediaType
=
new
MediaType
(
"foo"
,
"bar"
);
given
(
converter
.
getSupportedMediaTypes
()).
willReturn
(
Collections
.
singletonList
(
mediaType
));
given
(
requestFactory
.
createRequest
(
new
URI
(
url
),
HttpMethod
.
GET
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
new
URI
(
url
),
GET
)).
willReturn
(
request
);
given
(
request
.
getHeaders
()).
willReturn
(
new
HttpHeaders
());
given
(
request
.
execute
()).
willThrow
(
new
IOException
(
"Socket failure"
));
...
...
@@ -724,7 +724,7 @@ public class RestTemplateTests {
}
}
@Test
// SPR-15900
@Test
// SPR-15900
public
void
ioExceptionWithEmptyQueryString
()
throws
Exception
{
// http://example.com/resource?
...
...
@@ -732,7 +732,7 @@ public class RestTemplateTests {
given
(
converter
.
canRead
(
String
.
class
,
null
)).
willReturn
(
true
);
given
(
converter
.
getSupportedMediaTypes
()).
willReturn
(
Collections
.
singletonList
(
parseMediaType
(
"foo/bar"
)));
given
(
requestFactory
.
createRequest
(
uri
,
HttpMethod
.
GET
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
uri
,
GET
)).
willReturn
(
request
);
given
(
request
.
getHeaders
()).
willReturn
(
new
HttpHeaders
());
given
(
request
.
execute
()).
willThrow
(
new
IOException
(
"Socket failure"
));
...
...
@@ -825,7 +825,7 @@ public class RestTemplateTests {
verify
(
response
).
close
();
}
@Test
// SPR-15066
@Test
// SPR-15066
public
void
requestInterceptorCanAddExistingHeaderValueWithoutBody
()
throws
Exception
{
ClientHttpRequestInterceptor
interceptor
=
(
request
,
body
,
execution
)
->
{
request
.
getHeaders
().
add
(
"MyHeader"
,
"MyInterceptorValue"
);
...
...
@@ -833,7 +833,7 @@ public class RestTemplateTests {
};
template
.
setInterceptors
(
Collections
.
singletonList
(
interceptor
));
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
HttpMethod
.
POST
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
POST
)).
willReturn
(
request
);
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
given
(
request
.
getHeaders
()).
willReturn
(
requestHeaders
);
given
(
request
.
execute
()).
willReturn
(
response
);
...
...
@@ -845,13 +845,13 @@ public class RestTemplateTests {
HttpHeaders
entityHeaders
=
new
HttpHeaders
();
entityHeaders
.
add
(
"MyHeader"
,
"MyEntityValue"
);
HttpEntity
<
Void
>
entity
=
new
HttpEntity
<>(
null
,
entityHeaders
);
template
.
exchange
(
"http://example.com"
,
HttpMethod
.
POST
,
entity
,
Void
.
class
);
template
.
exchange
(
"http://example.com"
,
POST
,
entity
,
Void
.
class
);
assertThat
(
requestHeaders
.
get
(
"MyHeader"
),
contains
(
"MyEntityValue"
,
"MyInterceptorValue"
));
verify
(
response
).
close
();
}
@Test
// SPR-15066
@Test
// SPR-15066
public
void
requestInterceptorCanAddExistingHeaderValueWithBody
()
throws
Exception
{
ClientHttpRequestInterceptor
interceptor
=
(
request
,
body
,
execution
)
->
{
request
.
getHeaders
().
add
(
"MyHeader"
,
"MyInterceptorValue"
);
...
...
@@ -861,7 +861,7 @@ public class RestTemplateTests {
MediaType
contentType
=
MediaType
.
TEXT_PLAIN
;
given
(
converter
.
canWrite
(
String
.
class
,
contentType
)).
willReturn
(
true
);
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
HttpMethod
.
POST
)).
willReturn
(
request
);
given
(
requestFactory
.
createRequest
(
new
URI
(
"http://example.com"
),
POST
)).
willReturn
(
request
);
String
helloWorld
=
"Hello World"
;
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
given
(
request
.
getHeaders
()).
willReturn
(
requestHeaders
);
...
...
@@ -876,7 +876,7 @@ public class RestTemplateTests {
entityHeaders
.
setContentType
(
contentType
);
entityHeaders
.
add
(
"MyHeader"
,
"MyEntityValue"
);
HttpEntity
<
String
>
entity
=
new
HttpEntity
<>(
helloWorld
,
entityHeaders
);
template
.
exchange
(
"http://example.com"
,
HttpMethod
.
POST
,
entity
,
Void
.
class
);
template
.
exchange
(
"http://example.com"
,
POST
,
entity
,
Void
.
class
);
assertThat
(
requestHeaders
.
get
(
"MyHeader"
),
contains
(
"MyEntityValue"
,
"MyInterceptorValue"
));
verify
(
response
).
close
();
...
...
spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java
浏览文件 @
572c6687
...
...
@@ -185,7 +185,7 @@ public class UriComponentsBuilderTests {
}
@Test
// SPR-9832
public
void
fromUriStringQueryParamWithReservedCharInValue
()
throws
URISyntaxException
{
public
void
fromUriStringQueryParamWithReservedCharInValue
()
{
String
uri
=
"http://www.google.com/ig/calculator?q=1USD=?EUR"
;
UriComponents
result
=
UriComponentsBuilder
.
fromUriString
(
uri
).
build
();
...
...
@@ -194,7 +194,7 @@ public class UriComponentsBuilderTests {
}
@Test
// SPR-14828
public
void
fromUriStringQueryParamEncodedAndContainingPlus
()
throws
Exception
{
public
void
fromUriStringQueryParamEncodedAndContainingPlus
()
{
String
httpUrl
=
"http://localhost:8080/test/print?value=%EA%B0%80+%EB%82%98"
;
URI
uri
=
UriComponentsBuilder
.
fromHttpUrl
(
httpUrl
).
build
(
true
).
toUri
();
...
...
@@ -207,10 +207,8 @@ public class UriComponentsBuilderTests {
assertEquals
(
"https"
,
UriComponentsBuilder
.
fromHttpUrl
(
"HTTPS://www.google.com"
).
build
().
getScheme
());
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
// SPR-10539
public
void
fromHttpUrlStringInvalidIPv6Host
()
throws
URISyntaxException
{
@Test
(
expected
=
IllegalArgumentException
.
class
)
// SPR-10539
public
void
fromHttpUrlStringInvalidIPv6Host
()
{
UriComponentsBuilder
.
fromHttpUrl
(
"http://[1abc:2abc:3abc::5ABC:6abc:8080/resource"
).
build
().
encode
();
}
...
...
@@ -256,7 +254,7 @@ public class UriComponentsBuilderTests {
}
@Test
// SPR-12771
public
void
fromHttpRequestResetsPortBeforeSettingIt
()
throws
Exception
{
public
void
fromHttpRequestResetsPortBeforeSettingIt
()
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
request
.
addHeader
(
"X-Forwarded-Proto"
,
"https"
);
request
.
addHeader
(
"X-Forwarded-Host"
,
"84.198.58.199"
);
...
...
@@ -497,7 +495,7 @@ public class UriComponentsBuilderTests {
}
@Test
// SPR-12742
public
void
fromHttpRequestWithTrailingSlash
()
throws
Exception
{
public
void
fromHttpRequestWithTrailingSlash
()
{
UriComponents
before
=
UriComponentsBuilder
.
fromPath
(
"/foo/"
).
build
();
UriComponents
after
=
UriComponentsBuilder
.
newInstance
().
uriComponents
(
before
).
build
();
assertEquals
(
"/foo/"
,
after
.
getPath
());
...
...
@@ -666,21 +664,21 @@ public class UriComponentsBuilderTests {
}
@Test
public
void
queryParamWithValueWithEquals
()
throws
Exception
{
public
void
queryParamWithValueWithEquals
()
{
UriComponents
uriComponents
=
UriComponentsBuilder
.
fromUriString
(
"http://example.com/foo?bar=baz"
).
build
();
assertThat
(
uriComponents
.
toUriString
(),
equalTo
(
"http://example.com/foo?bar=baz"
));
assertThat
(
uriComponents
.
getQueryParams
().
get
(
"bar"
).
get
(
0
),
equalTo
(
"baz"
));
}
@Test
public
void
queryParamWithoutValueWithEquals
()
throws
Exception
{
public
void
queryParamWithoutValueWithEquals
()
{
UriComponents
uriComponents
=
UriComponentsBuilder
.
fromUriString
(
"http://example.com/foo?bar="
).
build
();
assertThat
(
uriComponents
.
toUriString
(),
equalTo
(
"http://example.com/foo?bar="
));
assertThat
(
uriComponents
.
getQueryParams
().
get
(
"bar"
).
get
(
0
),
equalTo
(
""
));
}
@Test
public
void
queryParamWithoutValueWithoutEquals
()
throws
Exception
{
public
void
queryParamWithoutValueWithoutEquals
()
{
UriComponents
uriComponents
=
UriComponentsBuilder
.
fromUriString
(
"http://example.com/foo?bar"
).
build
();
assertThat
(
uriComponents
.
toUriString
(),
equalTo
(
"http://example.com/foo?bar"
));
...
...
@@ -689,7 +687,7 @@ public class UriComponentsBuilderTests {
}
@Test
public
void
relativeUrls
()
throws
Exception
{
public
void
relativeUrls
()
{
String
baseUrl
=
"http://example.com"
;
assertThat
(
UriComponentsBuilder
.
fromUriString
(
baseUrl
+
"/foo/../bar"
).
build
().
toString
(),
equalTo
(
baseUrl
+
"/foo/../bar"
));
...
...
@@ -712,7 +710,7 @@ public class UriComponentsBuilderTests {
}
@Test
public
void
emptySegments
()
throws
Exception
{
public
void
emptySegments
()
{
String
baseUrl
=
"http://example.com/abc/"
;
assertThat
(
UriComponentsBuilder
.
fromUriString
(
baseUrl
).
path
(
"/x/y/z"
).
build
().
toString
(),
equalTo
(
"http://example.com/abc/x/y/z"
));
...
...
@@ -761,7 +759,7 @@ public class UriComponentsBuilderTests {
}
@Test
// SPR-11856
public
void
fromHttpRequestForwardedHeader
()
throws
Exception
{
public
void
fromHttpRequestForwardedHeader
()
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
request
.
addHeader
(
"Forwarded"
,
"proto=https; host=84.198.58.199"
);
request
.
setScheme
(
"http"
);
...
...
@@ -777,7 +775,7 @@ public class UriComponentsBuilderTests {
}
@Test
public
void
fromHttpRequestForwardedHeaderQuoted
()
throws
Exception
{
public
void
fromHttpRequestForwardedHeaderQuoted
()
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
request
.
addHeader
(
"Forwarded"
,
"proto=\"https\"; host=\"84.198.58.199\""
);
request
.
setScheme
(
"http"
);
...
...
@@ -793,7 +791,7 @@ public class UriComponentsBuilderTests {
}
@Test
public
void
fromHttpRequestMultipleForwardedHeader
()
throws
Exception
{
public
void
fromHttpRequestMultipleForwardedHeader
()
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
request
.
addHeader
(
"Forwarded"
,
"host=84.198.58.199;proto=https"
);
request
.
addHeader
(
"Forwarded"
,
"proto=ftp; host=1.2.3.4"
);
...
...
@@ -810,7 +808,7 @@ public class UriComponentsBuilderTests {
}
@Test
public
void
fromHttpRequestMultipleForwardedHeaderComma
()
throws
Exception
{
public
void
fromHttpRequestMultipleForwardedHeaderComma
()
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
request
.
addHeader
(
"Forwarded"
,
"host=84.198.58.199 ;proto=https, proto=ftp; host=1.2.3.4"
);
request
.
setScheme
(
"http"
);
...
...
@@ -826,7 +824,7 @@ public class UriComponentsBuilderTests {
}
@Test
public
void
fromHttpRequestForwardedHeaderWithHostPortAndWithoutServerPort
()
throws
Exception
{
public
void
fromHttpRequestForwardedHeaderWithHostPortAndWithoutServerPort
()
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
request
.
addHeader
(
"Forwarded"
,
"proto=https; host=84.198.58.199:9090"
);
request
.
setScheme
(
"http"
);
...
...
@@ -844,7 +842,7 @@ public class UriComponentsBuilderTests {
}
@Test
public
void
fromHttpRequestForwardedHeaderWithHostPortAndServerPort
()
throws
Exception
{
public
void
fromHttpRequestForwardedHeaderWithHostPortAndServerPort
()
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
request
.
addHeader
(
"Forwarded"
,
"proto=https; host=84.198.58.199:9090"
);
request
.
setScheme
(
"http"
);
...
...
@@ -863,7 +861,7 @@ public class UriComponentsBuilderTests {
}
@Test
public
void
fromHttpRequestForwardedHeaderWithoutHostPortAndWithServerPort
()
throws
Exception
{
public
void
fromHttpRequestForwardedHeaderWithoutHostPortAndWithServerPort
()
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
request
.
addHeader
(
"Forwarded"
,
"proto=https; host=84.198.58.199"
);
request
.
setScheme
(
"http"
);
...
...
@@ -882,7 +880,7 @@ public class UriComponentsBuilderTests {
}
@Test
// SPR-16262
public
void
fromHttpRequestForwardedHeaderWithProtoAndServerPort
()
throws
Exception
{
public
void
fromHttpRequestForwardedHeaderWithProtoAndServerPort
()
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
request
.
addHeader
(
"Forwarded"
,
"proto=https"
);
request
.
setScheme
(
"http"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录