Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
带水的鱼儿
spring-framework
提交
b5f2e56e
S
spring-framework
项目概览
带水的鱼儿
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
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,发现更多精彩内容 >>
提交
b5f2e56e
编写于
12月 19, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
594f4d56
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
99 addition
and
88 deletion
+99
-88
spring-core/src/main/java/org/springframework/core/Conventions.java
...e/src/main/java/org/springframework/core/Conventions.java
+1
-1
spring-core/src/main/java/org/springframework/core/convert/support/CollectionToStringConverter.java
...ork/core/convert/support/CollectionToStringConverter.java
+8
-4
spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
...mework/core/convert/support/GenericConversionService.java
+15
-15
spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java
...ework/core/convert/support/ObjectToOptionalConverter.java
+5
-5
spring-core/src/test/java/org/springframework/util/xml/AbstractStaxHandlerTestCase.java
...springframework/util/xml/AbstractStaxHandlerTestCase.java
+5
-7
spring-core/src/test/java/org/springframework/util/xml/StaxEventHandlerTests.java
...a/org/springframework/util/xml/StaxEventHandlerTests.java
+2
-3
spring-core/src/test/java/org/springframework/util/xml/StaxStreamHandlerTests.java
.../org/springframework/util/xml/StaxStreamHandlerTests.java
+2
-3
spring-oxm/src/main/java/org/springframework/oxm/Marshaller.java
...oxm/src/main/java/org/springframework/oxm/Marshaller.java
+3
-3
spring-oxm/src/main/java/org/springframework/oxm/Unmarshaller.java
...m/src/main/java/org/springframework/oxm/Unmarshaller.java
+3
-3
spring-web/src/main/java/org/springframework/web/client/AsyncRestOperations.java
...a/org/springframework/web/client/AsyncRestOperations.java
+30
-22
spring-web/src/main/java/org/springframework/web/client/AsyncRestTemplate.java
...ava/org/springframework/web/client/AsyncRestTemplate.java
+2
-4
spring-web/src/main/java/org/springframework/web/method/annotation/ModelFactory.java
...g/springframework/web/method/annotation/ModelFactory.java
+2
-4
spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java
...g/springframework/web/util/HierarchicalUriComponents.java
+2
-2
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java
...d/annotation/AbstractMessageConverterMethodProcessor.java
+2
-5
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java
...d/annotation/RequestResponseBodyMethodProcessorTests.java
+17
-7
未找到文件。
spring-core/src/main/java/org/springframework/core/Conventions.java
浏览文件 @
b5f2e56e
...
...
@@ -281,7 +281,7 @@ public abstract class Conventions {
/**
* Retrieves the {@code Class} of an element in the {@code Collection}.
* The exact element for which the {@code Class} is retr
ei
ved will depend
* The exact element for which the {@code Class} is retr
ie
ved will depend
* on the concrete {@code Collection} implementation.
*/
private
static
<
E
>
E
peekAhead
(
Collection
<
E
>
collection
)
{
...
...
spring-core/src/main/java/org/springframework/core/convert/support/CollectionToStringConverter.java
浏览文件 @
b5f2e56e
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
6
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,10 +36,12 @@ final class CollectionToStringConverter implements ConditionalGenericConverter {
private
final
ConversionService
conversionService
;
public
CollectionToStringConverter
(
ConversionService
conversionService
)
{
this
.
conversionService
=
conversionService
;
}
@Override
public
Set
<
ConvertiblePair
>
getConvertibleTypes
()
{
return
Collections
.
singleton
(
new
ConvertiblePair
(
Collection
.
class
,
String
.
class
));
...
...
@@ -47,7 +49,8 @@ final class CollectionToStringConverter implements ConditionalGenericConverter {
@Override
public
boolean
matches
(
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
return
ConversionUtils
.
canConvertElements
(
sourceType
.
getElementTypeDescriptor
(),
targetType
,
this
.
conversionService
);
return
ConversionUtils
.
canConvertElements
(
sourceType
.
getElementTypeDescriptor
(),
targetType
,
this
.
conversionService
);
}
@Override
...
...
@@ -56,7 +59,7 @@ final class CollectionToStringConverter implements ConditionalGenericConverter {
return
null
;
}
Collection
<?>
sourceCollection
=
(
Collection
<?>)
source
;
if
(
sourceCollection
.
size
()
==
0
)
{
if
(
sourceCollection
.
isEmpty
()
)
{
return
""
;
}
StringBuilder
sb
=
new
StringBuilder
();
...
...
@@ -65,7 +68,8 @@ final class CollectionToStringConverter implements ConditionalGenericConverter {
if
(
i
>
0
)
{
sb
.
append
(
DELIMITER
);
}
Object
targetElement
=
this
.
conversionService
.
convert
(
sourceElement
,
sourceType
.
elementTypeDescriptor
(
sourceElement
),
targetType
);
Object
targetElement
=
this
.
conversionService
.
convert
(
sourceElement
,
sourceType
.
elementTypeDescriptor
(
sourceElement
),
targetType
);
sb
.
append
(
targetElement
);
i
++;
}
...
...
spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
浏览文件 @
b5f2e56e
...
...
@@ -145,14 +145,14 @@ public class GenericConversionService implements ConfigurableConversionService {
@Override
public
boolean
canConvert
(
Class
<?>
sourceType
,
Class
<?>
targetType
)
{
Assert
.
notNull
(
targetType
,
"
targetT
ype to convert to cannot be null"
);
Assert
.
notNull
(
targetType
,
"
Target t
ype to convert to cannot be null"
);
return
canConvert
((
sourceType
!=
null
?
TypeDescriptor
.
valueOf
(
sourceType
)
:
null
),
TypeDescriptor
.
valueOf
(
targetType
));
}
@Override
public
boolean
canConvert
(
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
Assert
.
notNull
(
targetType
,
"
targetT
ype to convert to cannot be null"
);
Assert
.
notNull
(
targetType
,
"
Target t
ype to convert to cannot be null"
);
if
(
sourceType
==
null
)
{
return
true
;
}
...
...
@@ -161,9 +161,9 @@ public class GenericConversionService implements ConfigurableConversionService {
}
/**
* Return whether conversion between the source
Type and targetT
ype can be bypassed.
* Return whether conversion between the source
type and the target t
ype can be bypassed.
* <p>More precisely, this method will return true if objects of sourceType can be
* converted to the target
T
ype by returning the source object unchanged.
* converted to the target
t
ype by returning the source object unchanged.
* @param sourceType context about the source type to convert from
* (may be {@code null} if source is {@code null})
* @param targetType context about the target type to convert to (required)
...
...
@@ -172,7 +172,7 @@ public class GenericConversionService implements ConfigurableConversionService {
* @since 3.2
*/
public
boolean
canBypassConvert
(
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
Assert
.
notNull
(
targetType
,
"
targetT
ype to convert to cannot be null"
);
Assert
.
notNull
(
targetType
,
"
Target t
ype to convert to cannot be null"
);
if
(
sourceType
==
null
)
{
return
true
;
}
...
...
@@ -183,20 +183,20 @@ public class GenericConversionService implements ConfigurableConversionService {
@Override
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
convert
(
Object
source
,
Class
<
T
>
targetType
)
{
Assert
.
notNull
(
targetType
,
"
targetT
ype to convert to cannot be null"
);
Assert
.
notNull
(
targetType
,
"
Target t
ype to convert to cannot be null"
);
return
(
T
)
convert
(
source
,
TypeDescriptor
.
forObject
(
source
),
TypeDescriptor
.
valueOf
(
targetType
));
}
@Override
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
Assert
.
notNull
(
targetType
,
"
targetT
ype to convert to cannot be null"
);
Assert
.
notNull
(
targetType
,
"
Target t
ype to convert to cannot be null"
);
if
(
sourceType
==
null
)
{
Assert
.
isTrue
(
source
==
null
,
"
source must be [null] if sourceT
ype == [null]"
);
Assert
.
isTrue
(
source
==
null
,
"
Source must be [null] if source t
ype == [null]"
);
return
handleResult
(
null
,
targetType
,
convertNullSource
(
null
,
targetType
));
}
if
(
source
!=
null
&&
!
sourceType
.
getObjectType
().
isInstance
(
source
))
{
throw
new
IllegalArgumentException
(
"
source to convert from must be an instance of
"
+
sourceType
+
"
; instead it was a "
+
source
.
getClass
().
getName
()
);
throw
new
IllegalArgumentException
(
"
Source to convert from must be an instance of [
"
+
sourceType
+
"
]; instead it was a ["
+
source
.
getClass
().
getName
()
+
"]"
);
}
GenericConverter
converter
=
getConverter
(
sourceType
,
targetType
);
if
(
converter
!=
null
)
{
...
...
@@ -208,9 +208,9 @@ public class GenericConversionService implements ConfigurableConversionService {
/**
* Convenience operation for converting a source object to the specified targetType,
* where the target
T
ype is a descriptor that provides additional conversion context.
* where the target
t
ype is a descriptor that provides additional conversion context.
* Simply delegates to {@link #convert(Object, TypeDescriptor, TypeDescriptor)} and
* encapsulates the construction of the source
T
ype descriptor using
* encapsulates the construction of the source
t
ype descriptor using
* {@link TypeDescriptor#forObject(Object)}.
* @param source the source object
* @param targetType the target type
...
...
@@ -237,8 +237,8 @@ public class GenericConversionService implements ConfigurableConversionService {
* {@link java.util.Optional#empty()} instance if the target type is
* {@code java.util.Optional}. Subclasses may override this to return
* custom {@code null} objects for specific target types.
* @param sourceType the source
T
ype to convert from
* @param targetType the target
T
ype to convert to
* @param sourceType the source
t
ype to convert from
* @param targetType the target
t
ype to convert to
* @return the converted null object
*/
protected
Object
convertNullSource
(
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
...
...
@@ -282,7 +282,7 @@ public class GenericConversionService implements ConfigurableConversionService {
/**
* Return the default converter if no converter is found for the given sourceType/targetType pair.
* <p>Returns a NO_OP Converter if the source
Type is assignable to the targetT
ype.
* <p>Returns a NO_OP Converter if the source
type is assignable to the target t
ype.
* Returns {@code null} otherwise, indicating no suitable converter could be found.
* @param sourceType the source type to convert from
* @param targetType the target type to convert to
...
...
spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java
浏览文件 @
b5f2e56e
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -68,13 +68,13 @@ final class ObjectToOptionalConverter implements ConditionalGenericConverter {
else
if
(
source
instanceof
Optional
)
{
return
source
;
}
else
if
(
targetType
.
getResolvableType
()
==
null
)
{
return
Optional
.
of
(
source
);
}
else
{
else
if
(
targetType
.
getResolvableType
()
!=
null
)
{
Object
target
=
this
.
conversionService
.
convert
(
source
,
sourceType
,
new
GenericTypeDescriptor
(
targetType
));
return
Optional
.
ofNullable
(
target
);
}
else
{
return
Optional
.
of
(
source
);
}
}
...
...
spring-core/src/test/java/org/springframework/util/xml/AbstractStaxHandlerTestCase.java
浏览文件 @
b5f2e56e
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -19,7 +19,6 @@ package org.springframework.util.xml;
import
java.io.StringReader
;
import
java.io.StringWriter
;
import
java.net.Socket
;
import
javax.xml.parsers.DocumentBuilder
;
import
javax.xml.parsers.DocumentBuilderFactory
;
import
javax.xml.stream.XMLStreamException
;
...
...
@@ -30,7 +29,6 @@ import javax.xml.transform.stream.StreamResult;
import
org.junit.Assume
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.w3c.dom.Document
;
import
org.xml.sax.InputSource
;
import
org.xml.sax.XMLReader
;
...
...
@@ -58,11 +56,13 @@ public abstract class AbstractStaxHandlerTestCase {
private
XMLReader
xmlReader
;
@Before
public
void
createXMLReader
()
throws
Exception
{
xmlReader
=
XMLReaderFactory
.
createXMLReader
();
}
@Test
public
void
noNamespacePrefixes
()
throws
Exception
{
Assume
.
assumeTrue
(
wwwSpringframeworkOrgIsAccessible
());
...
...
@@ -109,8 +109,7 @@ public abstract class AbstractStaxHandlerTestCase {
@Test
public
void
noNamespacePrefixesDom
()
throws
Exception
{
DocumentBuilderFactory
documentBuilderFactory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilderFactory
documentBuilderFactory
=
DocumentBuilderFactory
.
newInstance
();
documentBuilderFactory
.
setNamespaceAware
(
true
);
DocumentBuilder
documentBuilder
=
documentBuilderFactory
.
newDocumentBuilder
();
...
...
@@ -131,8 +130,7 @@ public abstract class AbstractStaxHandlerTestCase {
@Test
public
void
namespacePrefixesDom
()
throws
Exception
{
DocumentBuilderFactory
documentBuilderFactory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilderFactory
documentBuilderFactory
=
DocumentBuilderFactory
.
newInstance
();
documentBuilderFactory
.
setNamespaceAware
(
true
);
DocumentBuilder
documentBuilder
=
documentBuilderFactory
.
newDocumentBuilder
();
...
...
spring-core/src/test/java/org/springframework/util/xml/StaxEventHandlerTests.java
浏览文件 @
b5f2e56e
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -27,8 +27,7 @@ import javax.xml.transform.Result;
public
class
StaxEventHandlerTests
extends
AbstractStaxHandlerTestCase
{
@Override
protected
AbstractStaxHandler
createStaxHandler
(
Result
result
)
throws
XMLStreamException
{
protected
AbstractStaxHandler
createStaxHandler
(
Result
result
)
throws
XMLStreamException
{
XMLOutputFactory
outputFactory
=
XMLOutputFactory
.
newFactory
();
XMLEventWriter
eventWriter
=
outputFactory
.
createXMLEventWriter
(
result
);
return
new
StaxEventHandler
(
eventWriter
);
...
...
spring-core/src/test/java/org/springframework/util/xml/StaxStreamHandlerTests.java
浏览文件 @
b5f2e56e
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -27,8 +27,7 @@ import javax.xml.transform.Result;
public
class
StaxStreamHandlerTests
extends
AbstractStaxHandlerTestCase
{
@Override
protected
AbstractStaxHandler
createStaxHandler
(
Result
result
)
throws
XMLStreamException
{
protected
AbstractStaxHandler
createStaxHandler
(
Result
result
)
throws
XMLStreamException
{
XMLOutputFactory
outputFactory
=
XMLOutputFactory
.
newFactory
();
XMLStreamWriter
streamWriter
=
outputFactory
.
createXMLStreamWriter
(
result
);
return
new
StaxStreamHandler
(
streamWriter
);
...
...
spring-oxm/src/main/java/org/springframework/oxm/Marshaller.java
浏览文件 @
b5f2e56e
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -35,7 +35,7 @@ import javax.xml.transform.Result;
public
interface
Marshaller
{
/**
* Indicate
s
whether this marshaller can marshal instances of the supplied type.
* Indicate whether this marshaller can marshal instances of the supplied type.
* @param clazz the class that this marshaller is being asked if it can marshal
* @return {@code true} if this marshaller can indeed marshal instances of the supplied class;
* {@code false} otherwise
...
...
@@ -43,7 +43,7 @@ public interface Marshaller {
boolean
supports
(
Class
<?>
clazz
);
/**
* Marshal
s
the object graph with the given root into the provided {@link Result}.
* Marshal the object graph with the given root into the provided {@link Result}.
* @param graph the root of the object graph to marshal
* @param result the result to marshal to
* @throws IOException if an I/O error occurs
...
...
spring-oxm/src/main/java/org/springframework/oxm/Unmarshaller.java
浏览文件 @
b5f2e56e
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -30,7 +30,7 @@ import javax.xml.transform.Source;
public
interface
Unmarshaller
{
/**
* Indicate
s
whether this unmarshaller can unmarshal instances of the supplied type.
* Indicate whether this unmarshaller can unmarshal instances of the supplied type.
* @param clazz the class that this unmarshaller is being asked if it can marshal
* @return {@code true} if this unmarshaller can indeed unmarshal to the supplied class;
* {@code false} otherwise
...
...
@@ -38,7 +38,7 @@ public interface Unmarshaller {
boolean
supports
(
Class
<?>
clazz
);
/**
* Unmarshal
s
the given {@link Source} into an object graph.
* Unmarshal the given {@link Source} into an object graph.
* @param source the source to marshal from
* @return the object graph
* @throws IOException if an I/O error occurs
...
...
spring-web/src/main/java/org/springframework/web/client/AsyncRestOperations.java
浏览文件 @
b5f2e56e
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -29,12 +29,14 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.util.concurrent.ListenableFuture
;
/**
* Interface specifying a basic set of asynchronous RESTful operations.
Implemented by
*
{@link AsyncRestTemplate}. Not often used directly, but a useful option to enhance
* testability, as it can easily be mocked or stubbed.
* Interface specifying a basic set of asynchronous RESTful operations.
*
Implemented by {@link AsyncRestTemplate}. Not often used directly, but a useful
*
option to enhance
testability, as it can easily be mocked or stubbed.
*
* @author Arjen Poutsma
* @since 4.0
* @see AsyncRestTemplate
* @see RestOperations
*/
public
interface
AsyncRestOperations
{
...
...
@@ -47,8 +49,8 @@ public interface AsyncRestOperations {
// GET
/**
* Asynchronously retrieve an entity by doing a GET on the specified URL.
The response is
* converted and stored in an {@link ResponseEntity}.
* Asynchronously retrieve an entity by doing a GET on the specified URL.
*
The response is
converted and stored in an {@link ResponseEntity}.
* <p>URI Template variables are expanded using the given URI variables, if any.
* @param url the URL
* @param responseType the type of the return value
...
...
@@ -59,8 +61,8 @@ public interface AsyncRestOperations {
Object
...
uriVariables
)
throws
RestClientException
;
/**
* Asynchronously retrieve a representation by doing a GET on the URI template.
The
* response is converted and stored in an {@link ResponseEntity}.
* Asynchronously retrieve a representation by doing a GET on the URI template.
*
The
response is converted and stored in an {@link ResponseEntity}.
* <p>URI Template variables are expanded using the given map.
* @param url the URL
* @param responseType the type of the return value
...
...
@@ -80,6 +82,7 @@ public interface AsyncRestOperations {
<
T
>
ListenableFuture
<
ResponseEntity
<
T
>>
getForEntity
(
URI
url
,
Class
<
T
>
responseType
)
throws
RestClientException
;
// HEAD
/**
...
...
@@ -109,6 +112,7 @@ public interface AsyncRestOperations {
*/
ListenableFuture
<
HttpHeaders
>
headForHeaders
(
URI
url
)
throws
RestClientException
;
// POST
/**
...
...
@@ -117,7 +121,7 @@ public interface AsyncRestOperations {
* typically indicates where the new resource is stored.
* <p>URI Template variables are expanded using the given URI variables, if any.
* @param url the URL
* @param request the Object to be POSTed
, may be {@code null}
* @param request the Object to be POSTed
(may be {@code null})
* @param uriVariables the variables to expand the template
* @return the value for the {@code Location} header wrapped in a {@link Future}
* @see org.springframework.http.HttpEntity
...
...
@@ -131,7 +135,7 @@ public interface AsyncRestOperations {
* typically indicates where the new resource is stored.
* <p>URI Template variables are expanded using the given map.
* @param url the URL
* @param request the Object to be POSTed
, may be {@code null}
* @param request the Object to be POSTed
(may be {@code null})
* @param uriVariables the variables to expand the template
* @return the value for the {@code Location} header wrapped in a {@link Future}
* @see org.springframework.http.HttpEntity
...
...
@@ -144,7 +148,7 @@ public interface AsyncRestOperations {
* returns the value of the {@code Location} header. This header typically indicates
* where the new resource is stored.
* @param url the URL
* @param request the Object to be POSTed
, may be {@code null}
* @param request the Object to be POSTed
(may be {@code null})
* @return the value for the {@code Location} header wrapped in a {@link Future}
* @see org.springframework.http.HttpEntity
*/
...
...
@@ -155,7 +159,7 @@ public interface AsyncRestOperations {
* and asynchronously returns the response as {@link ResponseEntity}.
* <p>URI Template variables are expanded using the given URI variables, if any.
* @param url the URL
* @param request the Object to be POSTed
, may be {@code null}
* @param request the Object to be POSTed
(may be {@code null})
* @param uriVariables the variables to expand the template
* @return the entity wrapped in a {@link Future}
* @see org.springframework.http.HttpEntity
...
...
@@ -168,26 +172,26 @@ public interface AsyncRestOperations {
* and asynchronously returns the response as {@link ResponseEntity}.
* <p>URI Template variables are expanded using the given map.
* @param url the URL
* @param request the Object to be POSTed
, may be {@code null}
* @param request the Object to be POSTed
(may be {@code null})
* @param uriVariables the variables to expand the template
* @return the entity wrapped in a {@link Future}
* @see org.springframework.http.HttpEntity
*/
<
T
>
ListenableFuture
<
ResponseEntity
<
T
>>
postForEntity
(
String
url
,
HttpEntity
<?>
request
,
Class
<
T
>
responseType
,
Map
<
String
,
?>
uriVariables
)
throws
RestClientException
;
Class
<
T
>
responseType
,
Map
<
String
,
?>
uriVariables
)
throws
RestClientException
;
/**
* Create a new resource by POSTing the given object to the URL,
* and asynchronously returns the response as {@link ResponseEntity}.
* @param url the URL
* @param request the Object to be POSTed
, may be {@code null}
* @param request the Object to be POSTed
(may be {@code null})
* @return the entity wrapped in a {@link Future}
* @see org.springframework.http.HttpEntity
*/
<
T
>
ListenableFuture
<
ResponseEntity
<
T
>>
postForEntity
(
URI
url
,
HttpEntity
<?>
request
,
Class
<
T
>
responseType
)
throws
RestClientException
;
// PUT
/**
...
...
@@ -195,7 +199,7 @@ public interface AsyncRestOperations {
* <p>URI Template variables are expanded using the given URI variables, if any.
* <p>The Future will return a {@code null} result upon completion.
* @param url the URL
* @param request the Object to be PUT
, may be {@code null}
* @param request the Object to be PUT
(may be {@code null})
* @param uriVariables the variables to expand the template
* @see HttpEntity
*/
...
...
@@ -207,7 +211,7 @@ public interface AsyncRestOperations {
* <p>URI Template variables are expanded using the given map.
* <p>The Future will return a {@code null} result upon completion.
* @param url the URL
* @param request the Object to be PUT
, may be {@code null}
* @param request the Object to be PUT
(may be {@code null})
* @param uriVariables the variables to expand the template
* @see HttpEntity
*/
...
...
@@ -218,11 +222,12 @@ public interface AsyncRestOperations {
* Creates a new resource by PUTting the given object to URL.
* <p>The Future will return a {@code null} result upon completion.
* @param url the URL
* @param request the Object to be PUT
, may be {@code null}
* @param request the Object to be PUT
(may be {@code null})
* @see HttpEntity
*/
ListenableFuture
<?>
put
(
URI
url
,
HttpEntity
<?>
request
)
throws
RestClientException
;
// DELETE
/**
...
...
@@ -251,6 +256,7 @@ public interface AsyncRestOperations {
*/
ListenableFuture
<?>
delete
(
URI
url
)
throws
RestClientException
;
// OPTIONS
/**
...
...
@@ -344,7 +350,7 @@ public interface AsyncRestOperations {
* @param url the URL
* @param method the HTTP method (GET, POST, etc)
* @param requestEntity the entity (headers and/or body) to write to the
* request
, may be {@code null}
* request
(may be {@code null})
* @param responseType the type of the return value
* @param uriVariables the variables to expand in the template
* @return the response as entity wrapped in a {@link Future}
...
...
@@ -364,7 +370,8 @@ public interface AsyncRestOperations {
* </pre>
* @param url the URL
* @param method the HTTP method (GET, POST, etc)
* @param requestEntity the entity (headers and/or body) to write to the request, may be {@code null}
* @param requestEntity the entity (headers and/or body) to write to the request
* (may be {@code null})
* @param responseType the type of the return value
* @param uriVariables the variables to expand in the template
* @return the response as entity wrapped in a {@link Future}
...
...
@@ -384,7 +391,8 @@ public interface AsyncRestOperations {
* </pre>
* @param url the URL
* @param method the HTTP method (GET, POST, etc)
* @param requestEntity the entity (headers and/or body) to write to the request, may be {@code null}
* @param requestEntity the entity (headers and/or body) to write to the request
* (may be {@code null})
* @param responseType the type of the return value
* @return the response as entity wrapped in a {@link Future}
*/
...
...
spring-web/src/main/java/org/springframework/web/client/AsyncRestTemplate.java
浏览文件 @
b5f2e56e
...
...
@@ -53,10 +53,8 @@ import org.springframework.web.util.UriTemplateHandler;
* wrappers as opposed to concrete results.
*
* <p>The {@code AsyncRestTemplate} exposes a synchronous {@link RestTemplate} via the
* {@link #getRestOperations()} method, and it shares its
* {@linkplain #setErrorHandler(ResponseErrorHandler) error handler} and
* {@linkplain #setMessageConverters(List) message converters} with this
* {@code RestTemplate}.
* {@link #getRestOperations()} method and shares its {@linkplain #setErrorHandler error handler}
* and {@linkplain #setMessageConverters message converters} with that {@code RestTemplate}.
*
* <p><strong>Note:</strong> by default {@code AsyncRestTemplate} relies on
* standard JDK facilities to establish HTTP connections. You can switch to use
...
...
spring-web/src/main/java/org/springframework/web/method/annotation/ModelFactory.java
浏览文件 @
b5f2e56e
...
...
@@ -250,10 +250,8 @@ public final class ModelFactory {
List
<
String
>
keyNames
=
new
ArrayList
<
String
>(
model
.
keySet
());
for
(
String
name
:
keyNames
)
{
Object
value
=
model
.
get
(
name
);
if
(
isBindingCandidate
(
name
,
value
))
{
String
bindingResultKey
=
BindingResult
.
MODEL_KEY_PREFIX
+
name
;
if
(!
model
.
containsAttribute
(
bindingResultKey
))
{
WebDataBinder
dataBinder
=
this
.
dataBinderFactory
.
createBinder
(
request
,
value
,
name
);
model
.
put
(
bindingResultKey
,
dataBinder
.
getBindingResult
());
...
...
@@ -270,7 +268,7 @@ public final class ModelFactory {
return
false
;
}
Class
<?>
attrType
=
(
value
!=
null
)
?
value
.
getClass
()
:
null
;
Class
<?>
attrType
=
(
value
!=
null
?
value
.
getClass
()
:
null
)
;
if
(
this
.
sessionAttributesHandler
.
isHandlerSessionAttribute
(
attributeName
,
attrType
))
{
return
true
;
}
...
...
@@ -286,7 +284,7 @@ public final class ModelFactory {
private
final
Set
<
String
>
dependencies
=
new
HashSet
<
String
>();
p
rivate
ModelMethod
(
InvocableHandlerMethod
handlerMethod
)
{
p
ublic
ModelMethod
(
InvocableHandlerMethod
handlerMethod
)
{
this
.
handlerMethod
=
handlerMethod
;
for
(
MethodParameter
parameter
:
handlerMethod
.
getMethodParameters
())
{
if
(
parameter
.
hasParameterAnnotation
(
ModelAttribute
.
class
))
{
...
...
spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java
浏览文件 @
b5f2e56e
...
...
@@ -194,7 +194,7 @@ final class HierarchicalUriComponents extends UriComponents {
String
hostTo
=
encodeUriComponent
(
this
.
host
,
encoding
,
getHostType
());
PathComponent
pathTo
=
this
.
path
.
encode
(
encoding
);
MultiValueMap
<
String
,
String
>
paramsTo
=
encodeQueryParams
(
encoding
);
String
fragmentTo
=
encodeUriComponent
(
this
.
getFragment
(),
encoding
,
Type
.
FRAGMENT
);
String
fragmentTo
=
encodeUriComponent
(
getFragment
(),
encoding
,
Type
.
FRAGMENT
);
return
new
HierarchicalUriComponents
(
schemeTo
,
userInfoTo
,
hostTo
,
this
.
port
,
pathTo
,
paramsTo
,
fragmentTo
,
true
,
false
);
}
...
...
@@ -328,7 +328,7 @@ final class HierarchicalUriComponents extends UriComponents {
String
portTo
=
expandUriComponent
(
this
.
port
,
uriVariables
);
PathComponent
pathTo
=
this
.
path
.
expand
(
uriVariables
);
MultiValueMap
<
String
,
String
>
paramsTo
=
expandQueryParams
(
uriVariables
);
String
fragmentTo
=
expandUriComponent
(
this
.
getFragment
(),
uriVariables
);
String
fragmentTo
=
expandUriComponent
(
getFragment
(),
uriVariables
);
return
new
HierarchicalUriComponents
(
schemeTo
,
userInfoTo
,
hostTo
,
portTo
,
pathTo
,
paramsTo
,
fragmentTo
,
false
,
false
);
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java
浏览文件 @
b5f2e56e
...
...
@@ -90,7 +90,6 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
private
final
Set
<
String
>
safeExtensions
=
new
HashSet
<
String
>();
/**
* Constructor with list of converters only.
*/
...
...
@@ -348,9 +347,7 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
* header with a safe attachment file name ("f.txt") is added to prevent
* RFD exploits.
*/
private
void
addContentDispositionHeader
(
ServletServerHttpRequest
request
,
ServletServerHttpResponse
response
)
{
private
void
addContentDispositionHeader
(
ServletServerHttpRequest
request
,
ServletServerHttpResponse
response
)
{
HttpHeaders
headers
=
response
.
getHeaders
();
if
(
headers
.
containsKey
(
HttpHeaders
.
CONTENT_DISPOSITION
))
{
return
;
...
...
@@ -363,7 +360,7 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
}
}
catch
(
Throwable
ex
)
{
//
I
gnore
//
i
gnore
}
HttpServletRequest
servletRequest
=
request
.
getServletRequest
();
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java
浏览文件 @
b5f2e56e
...
...
@@ -69,11 +69,7 @@ import org.springframework.web.servlet.ModelAndView;
import
org.springframework.web.servlet.view.json.MappingJackson2JsonView
;
import
org.springframework.web.util.WebUtils
;
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
.
junit
.
Assert
.*;
/**
* Test fixture for a {@link RequestResponseBodyMethodProcessor} with
...
...
@@ -732,7 +728,6 @@ public class RequestResponseBodyMethodProcessorTests {
}
String
handle
(
@RequestBody
List
<
SimpleBean
>
list
,
@RequestBody
SimpleBean
simpleBean
,
...
...
@@ -751,15 +746,18 @@ public class RequestResponseBodyMethodProcessorTests {
return
null
;
}
private
static
abstract
class
MyParameterizedController
<
DTO
extends
Identifiable
>
{
@SuppressWarnings
(
"unused"
)
public
void
handleDto
(
@RequestBody
DTO
dto
)
{}
}
private
static
class
MySimpleParameterizedController
extends
MyParameterizedController
<
SimpleBean
>
{
}
private
interface
Identifiable
extends
Serializable
{
Long
getId
();
...
...
@@ -767,6 +765,7 @@ public class RequestResponseBodyMethodProcessorTests {
void
setId
(
Long
id
);
}
@SuppressWarnings
(
"unused"
)
private
static
abstract
class
MyParameterizedControllerWithList
<
DTO
extends
Identifiable
>
{
...
...
@@ -774,6 +773,7 @@ public class RequestResponseBodyMethodProcessorTests {
}
}
@SuppressWarnings
(
"unused"
)
private
static
class
MySimpleParameterizedControllerWithList
extends
MyParameterizedControllerWithList
<
SimpleBean
>
{
}
...
...
@@ -843,9 +843,12 @@ public class RequestResponseBodyMethodProcessorTests {
}
}
private
interface
MyJacksonView1
{}
private
interface
MyJacksonView2
{}
private
static
class
JacksonViewBean
{
@JsonView
(
MyJacksonView1
.
class
)
...
...
@@ -881,6 +884,7 @@ public class RequestResponseBodyMethodProcessorTests {
}
}
@JsonTypeInfo
(
use
=
JsonTypeInfo
.
Id
.
NAME
,
include
=
JsonTypeInfo
.
As
.
PROPERTY
,
property
=
"type"
)
public
static
class
ParentClass
{
...
...
@@ -902,6 +906,7 @@ public class RequestResponseBodyMethodProcessorTests {
}
}
@JsonTypeName
(
"foo"
)
public
static
class
Foo
extends
ParentClass
{
...
...
@@ -913,6 +918,7 @@ public class RequestResponseBodyMethodProcessorTests {
}
}
@JsonTypeName
(
"bar"
)
public
static
class
Bar
extends
ParentClass
{
...
...
@@ -924,6 +930,7 @@ public class RequestResponseBodyMethodProcessorTests {
}
}
private
static
class
JacksonController
{
@RequestMapping
...
...
@@ -996,9 +1003,9 @@ public class RequestResponseBodyMethodProcessorTests {
public
String
defaultCharset
()
{
return
"foo"
;
}
}
private
static
class
EmptyRequestBodyAdvice
implements
RequestBodyAdvice
{
@Override
...
...
@@ -1030,12 +1037,15 @@ public class RequestResponseBodyMethodProcessorTests {
}
}
interface
MappingInterface
<
A
>
{
default
A
handle
(
@RequestBody
A
arg
)
{
return
arg
;
}
}
static
class
MyControllerImplementingInterface
implements
MappingInterface
<
String
>
{
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录