Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sesemomo
spring-framework
提交
e2065200
S
spring-framework
项目概览
sesemomo
/
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,发现更多精彩内容 >>
提交
e2065200
编写于
3月 07, 2018
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve docs on SseEmitter onComplete/onError
Issue: SPR-16548
上级
b14301bf
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
42 addition
and
13 deletion
+42
-13
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java
...eb/servlet/mvc/method/annotation/ResponseBodyEmitter.java
+25
-13
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/SseEmitter.java
...amework/web/servlet/mvc/method/annotation/SseEmitter.java
+8
-0
src/docs/asciidoc/web/webmvc.adoc
src/docs/asciidoc/web/webmvc.adoc
+9
-0
未找到文件。
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java
浏览文件 @
e2065200
...
...
@@ -66,13 +66,16 @@ public class ResponseBodyEmitter {
@Nullable
private
final
Long
timeout
;
private
final
Set
<
DataWithMediaType
>
earlySendAttempts
=
new
LinkedHashSet
<>(
8
);
@Nullable
private
Handler
handler
;
/** Store send data before handler is initialized */
private
final
Set
<
DataWithMediaType
>
earlySendAttempts
=
new
LinkedHashSet
<>(
8
);
/** Store complete invocation before handler is initialized */
private
boolean
complete
;
/** Store completeWithError invocation before handler is initialized */
@Nullable
private
Throwable
failure
;
...
...
@@ -147,6 +150,11 @@ public class ResponseBodyEmitter {
* Write the given object to the response.
* <p>If any exception occurs a dispatch is made back to the app server where
* Spring MVC will pass the exception through its exception handling mechanism.
* <p><strong>Note:</strong> if the send fails with an IOException, you do
* not need to call {@link #completeWithError(Throwable)} in order to clean
* up. Instead the Servlet container creates a notification that results in a
* dispatch where Spring MVC invokes exception resolvers and completes
* processing.
* @param object the object to write
* @throws IOException raised when an I/O error occurs
* @throws java.lang.IllegalStateException wraps any other errors
...
...
@@ -156,9 +164,8 @@ public class ResponseBodyEmitter {
}
/**
* Write the given object to the response also using a MediaType hint.
* <p>If any exception occurs a dispatch is made back to the app server where
* Spring MVC will pass the exception through its exception handling mechanism.
* Overloaded variant of {@link #send(Object)} that also accepts a MediaType
* hint for how to serialize the given Object.
* @param object the object to write
* @param mediaType a MediaType hint for selecting an HttpMessageConverter
* @throws IOException raised when an I/O error occurs
...
...
@@ -187,13 +194,12 @@ public class ResponseBodyEmitter {
}
/**
* Complete request processing.
* <p>A dispatch is made into the app server where Spring MVC completes
* asynchronous request processing.
* <p><strong>Note:</strong> you do not need to call this method after an
* {@link IOException} from any of the {@code send} methods. The Servlet
* container will generate an error notification that Spring MVC will process
* and handle through the exception resolver mechanism and then complete.
* Complete request processing by performing a dispatch into the servlet
* container, where Spring MVC is invoked once more, and completes the
* request processing lifecycle.
* <p><strong>Note:</strong> this method should be called by the application
* to complete request processing. It should not be used after container
* related events such as an error while {@link #send(Object) sending}.
*/
public
synchronized
void
complete
()
{
this
.
complete
=
true
;
...
...
@@ -205,7 +211,13 @@ public class ResponseBodyEmitter {
/**
* Complete request processing with an error.
* <p>A dispatch is made into the app server where Spring MVC will pass the
* exception through its exception handling mechanism.
* exception through its exception handling mechanism. Note however that
* at this stage of request processing, the response is committed and the
* response status can no longer be changed.
* <p><strong>Note:</strong> this method should be called by the application
* to complete request processing with an error. It should not be used after
* container related events such as an error while
* {@link #send(Object) sending}.
*/
public
synchronized
void
completeWithError
(
Throwable
ex
)
{
this
.
complete
=
true
;
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/SseEmitter.java
浏览文件 @
e2065200
...
...
@@ -82,6 +82,10 @@ public class SseEmitter extends ResponseBodyEmitter {
* SseEmitter emitter = new SseEmitter();
* emitter.send(event().data(myObject));
* </pre>
*
* <p>Please, see {@link ResponseBodyEmitter#send(Object) parent Javadoc}
* for important notes on exception handling.
*
* @param object the object to write
* @throws IOException raised when an I/O error occurs
* @throws java.lang.IllegalStateException wraps any other errors
...
...
@@ -99,6 +103,10 @@ public class SseEmitter extends ResponseBodyEmitter {
* SseEmitter emitter = new SseEmitter();
* emitter.send(event().data(myObject, MediaType.APPLICATION_JSON));
* </pre>
*
* <p>Please, see {@link ResponseBodyEmitter#send(Object) parent Javadoc}
* for important notes on exception handling.
*
* @param object the object to write
* @param mediaType a MediaType hint for selecting an HttpMessageConverter
* @throws IOException raised when an I/O error occurs
...
...
src/docs/asciidoc/web/webmvc.adoc
浏览文件 @
e2065200
...
...
@@ -3304,6 +3304,13 @@ response. For example:
`ResponseBodyEmitter` can also be used as the body in a `ResponseEntity` allowing you to
customize the status and headers of the response.
When an `emitter` throws an `IOException` (e.g. if the remote client went away) applications
are not responsible for cleaning up the connection, and should not invoke `emitter.complete`
or `emitter.completeWithError`. Instead the servlet container automatically initiates an
`AsyncListener` error notification in which Spring MVC makes a `completeWithError` call,
which in turn performs one a final ASYNC dispatch to the application during which Spring MVC
invokes the configured exception resolvers and completes the request.
[[mvc-ann-async-sse]]
==== SSE
...
...
@@ -3339,6 +3346,8 @@ does not support Server-Sent Events. Consider using Spring's
<
<
web.adoc#websocket-fallback
,
SockJS
fallback
>
> transports (including SSE) that target
a wide range of browsers.
Also see
<
<
mvc-ann-async-objects
,
previous
section
>
> for notes on exception handling.
[[mvc-ann-async-output-stream]]
==== Raw data
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录