public class ResponseBodyEmitter extends Object
DeferredResult
is used to produce a single result, a ResponseBodyEmitter can be used
to send multiple objects where each object is written with a compatible
HttpMessageConverter.
Supported as a return type on its own as well as within a
ResponseEntity.
@RequestMapping(value="/stream", method=RequestMethod.GET)
public ResponseBodyEmitter handle() {
ResponseBodyEmitter emitter = new ResponseBodyEmitter();
// Pass the emitter to another component...
return emitter;
}
// in another thread
emitter.send(foo1);
// and again
emitter.send(foo2);
// and done
emitter.complete();
| Constructor and Description |
|---|
ResponseBodyEmitter() |
| Modifier and Type | Method and Description |
|---|---|
void |
complete()
Complete request processing.
|
void |
completeWithError(Throwable ex)
Complete request processing with an error.
|
protected void |
extendResponse(org.springframework.http.server.ServerHttpResponse outputMessage)
Invoked after the response is updated with the status code and headers,
if the ResponseBodyEmitter is wrapped in a ResponseEntity, but before the
response is committed, i.e.
|
void |
onCompletion(Runnable callback)
Register code to invoke when the async request completes.
|
void |
onTimeout(Runnable callback)
Register code to invoke when the async request times out.
|
void |
send(Object object)
Write the given object to the response.
|
void |
send(Object object,
org.springframework.http.MediaType mediaType)
Write the given object to the response also using a MediaType hint.
|
protected void extendResponse(org.springframework.http.server.ServerHttpResponse outputMessage)
The default implementation is empty.
public void send(Object object) throws IOException
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.
object - the object to writeIOException - raised when an I/O error occursIllegalStateException - wraps any other errorspublic void send(Object object, org.springframework.http.MediaType mediaType) throws IOException
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.
object - the object to writemediaType - a MediaType hint for selecting an HttpMessageConverterIOException - raised when an I/O error occursIllegalStateException - wraps any other errorspublic void complete()
A dispatch is made into the app server where Spring MVC completes asynchronous request processing.
public void completeWithError(Throwable ex)
A dispatch is made into the app server where Spring MVC will pass the exception through its exception handling mechanism.
public void onTimeout(Runnable callback)
public void onCompletion(Runnable callback)
ResponseBodyEmitter instance is no longer usable.