Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
46fe74d2
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 搜索 >>
提交
46fe74d2
编写于
7月 14, 2018
作者:
M
Mark Hobson
提交者:
Rossen Stoyanchev
11月 14, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Preserve media type parameters when setting charset
Issue: SPR-17040
上级
905e3c1f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
5 deletion
+52
-5
spring-web/src/main/java/org/springframework/http/converter/feed/AbstractWireFeedHttpMessageConverter.java
.../converter/feed/AbstractWireFeedHttpMessageConverter.java
+1
-1
spring-web/src/test/java/org/springframework/http/converter/feed/AtomFeedHttpMessageConverterTests.java
...ttp/converter/feed/AtomFeedHttpMessageConverterTests.java
+24
-2
spring-web/src/test/java/org/springframework/http/converter/feed/RssChannelHttpMessageConverterTests.java
...p/converter/feed/RssChannelHttpMessageConverterTests.java
+27
-2
未找到文件。
spring-web/src/main/java/org/springframework/http/converter/feed/AbstractWireFeedHttpMessageConverter.java
浏览文件 @
46fe74d2
...
...
@@ -90,7 +90,7 @@ public abstract class AbstractWireFeedHttpMessageConverter<T extends WireFeed>
Charset
.
forName
(
wireFeed
.
getEncoding
())
:
DEFAULT_CHARSET
);
MediaType
contentType
=
outputMessage
.
getHeaders
().
getContentType
();
if
(
contentType
!=
null
)
{
contentType
=
new
MediaType
(
contentType
.
getType
(),
contentType
.
getSubtype
()
,
charset
);
contentType
=
new
MediaType
(
contentType
,
charset
);
outputMessage
.
getHeaders
().
setContentType
(
contentType
);
}
...
...
spring-web/src/test/java/org/springframework/http/converter/feed/AtomFeedHttpMessageConverterTests.java
浏览文件 @
46fe74d2
...
...
@@ -21,7 +21,9 @@ import java.io.InputStream;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
com.rometools.rome.feed.atom.Entry
;
import
com.rometools.rome.feed.atom.Feed
;
...
...
@@ -37,6 +39,7 @@ import org.springframework.http.MockHttpInputMessage;
import
org.springframework.http.MockHttpOutputMessage
;
import
org.springframework.tests.XmlContent
;
import
static
java
.
util
.
Collections
.
singletonMap
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
...
...
@@ -106,7 +109,9 @@ public class AtomFeedHttpMessageConverterTests {
MockHttpOutputMessage
outputMessage
=
new
MockHttpOutputMessage
();
converter
.
write
(
feed
,
null
,
outputMessage
);
assertThat
(
outputMessage
.
getHeaders
().
getContentType
()).
as
(
"Invalid content-type"
).
isEqualTo
(
new
MediaType
(
"application"
,
"atom+xml"
,
StandardCharsets
.
UTF_8
));
assertThat
(
outputMessage
.
getHeaders
().
getContentType
())
.
as
(
"Invalid content-type"
)
.
isEqualTo
(
new
MediaType
(
"application"
,
"atom+xml"
,
StandardCharsets
.
UTF_8
));
String
expected
=
"<feed xmlns=\"http://www.w3.org/2005/Atom\">"
+
"<title>title</title>"
+
"<entry><id>id1</id><title>title1</title></entry>"
+
"<entry><id>id2</id><title>title2</title></entry></feed>"
;
...
...
@@ -125,7 +130,24 @@ public class AtomFeedHttpMessageConverterTests {
MockHttpOutputMessage
outputMessage
=
new
MockHttpOutputMessage
();
converter
.
write
(
feed
,
null
,
outputMessage
);
assertThat
(
outputMessage
.
getHeaders
().
getContentType
()).
as
(
"Invalid content-type"
).
isEqualTo
(
new
MediaType
(
"application"
,
"atom+xml"
,
Charset
.
forName
(
encoding
)));
assertThat
(
outputMessage
.
getHeaders
().
getContentType
())
.
as
(
"Invalid content-type"
)
.
isEqualTo
(
new
MediaType
(
"application"
,
"atom+xml"
,
Charset
.
forName
(
encoding
)));
}
@Test
public
void
writeOtherContentTypeParameters
()
throws
IOException
{
Feed
feed
=
new
Feed
(
"atom_1.0"
);
MockHttpOutputMessage
outputMessage
=
new
MockHttpOutputMessage
();
converter
.
write
(
feed
,
new
MediaType
(
"application"
,
"atom+xml"
,
singletonMap
(
"type"
,
"feed"
)),
outputMessage
);
Map
<
String
,
String
>
expectedParameters
=
new
HashMap
<>();
expectedParameters
.
put
(
"charset"
,
"UTF-8"
);
expectedParameters
.
put
(
"type"
,
"feed"
);
assertThat
(
outputMessage
.
getHeaders
().
getContentType
())
.
as
(
"Invalid content-type"
)
.
isEqualTo
(
new
MediaType
(
"application"
,
"atom+xml"
,
expectedParameters
));
}
}
spring-web/src/test/java/org/springframework/http/converter/feed/RssChannelHttpMessageConverterTests.java
浏览文件 @
46fe74d2
...
...
@@ -21,7 +21,9 @@ import java.io.InputStream;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
com.rometools.rome.feed.rss.Channel
;
import
com.rometools.rome.feed.rss.Item
;
...
...
@@ -34,6 +36,7 @@ import org.springframework.http.MockHttpInputMessage;
import
org.springframework.http.MockHttpOutputMessage
;
import
org.springframework.tests.XmlContent
;
import
static
java
.
util
.
Collections
.
singletonMap
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
...
...
@@ -103,7 +106,9 @@ public class RssChannelHttpMessageConverterTests {
MockHttpOutputMessage
outputMessage
=
new
MockHttpOutputMessage
();
converter
.
write
(
channel
,
null
,
outputMessage
);
assertThat
(
outputMessage
.
getHeaders
().
getContentType
()).
as
(
"Invalid content-type"
).
isEqualTo
(
new
MediaType
(
"application"
,
"rss+xml"
,
StandardCharsets
.
UTF_8
));
assertThat
(
outputMessage
.
getHeaders
().
getContentType
())
.
as
(
"Invalid content-type"
)
.
isEqualTo
(
new
MediaType
(
"application"
,
"rss+xml"
,
StandardCharsets
.
UTF_8
));
String
expected
=
"<rss version=\"2.0\">"
+
"<channel><title>title</title><link>https://example.com</link><description>description</description>"
+
"<item><title>title1</title></item>"
+
...
...
@@ -129,7 +134,27 @@ public class RssChannelHttpMessageConverterTests {
MockHttpOutputMessage
outputMessage
=
new
MockHttpOutputMessage
();
converter
.
write
(
channel
,
null
,
outputMessage
);
assertThat
(
outputMessage
.
getHeaders
().
getContentType
()).
as
(
"Invalid content-type"
).
isEqualTo
(
new
MediaType
(
"application"
,
"rss+xml"
,
Charset
.
forName
(
encoding
)));
assertThat
(
outputMessage
.
getHeaders
().
getContentType
())
.
as
(
"Invalid content-type"
)
.
isEqualTo
(
new
MediaType
(
"application"
,
"rss+xml"
,
Charset
.
forName
(
encoding
)));
}
@Test
public
void
writeOtherContentTypeParameters
()
throws
IOException
{
Channel
channel
=
new
Channel
(
"rss_2.0"
);
channel
.
setTitle
(
"title"
);
channel
.
setLink
(
"http://example.com"
);
channel
.
setDescription
(
"description"
);
MockHttpOutputMessage
outputMessage
=
new
MockHttpOutputMessage
();
converter
.
write
(
channel
,
new
MediaType
(
"application"
,
"rss+xml"
,
singletonMap
(
"x"
,
"y"
)),
outputMessage
);
Map
<
String
,
String
>
expectedParameters
=
new
HashMap
<>();
expectedParameters
.
put
(
"charset"
,
"UTF-8"
);
expectedParameters
.
put
(
"x"
,
"y"
);
assertThat
(
outputMessage
.
getHeaders
().
getContentType
())
.
as
(
"Invalid content-type"
)
.
isEqualTo
(
new
MediaType
(
"application"
,
"rss+xml"
,
expectedParameters
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录