Package org.springframework.web.servlet.mvc.method.annotation

# Class ResponseBodyEmitterReturnValueHandler

java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitterReturnValueHandler

All Implemented Interfaces:
  `org.springframework.web.method.support.HandlerMethodReturnValueHandler`

public class ResponseBodyEmitterReturnValueHandler extends Object implements org.springframework.web.method.support.HandlerMethodReturnValueHandler
Handler for return values of type:

- `ResponseBodyEmitter` including sub-class `SseEmitter` and others.
- Reactive return types known to `ReactiveAdapterRegistry`.
- Any of the above wrapped with `ResponseEntity`.

Single-value reactive types are adapted to `DeferredResult`. Multi-value reactive types are adapted to `ResponseBodyEmitter` or `SseEmitter` as follows:

- SSE stream, if the element type is `ServerSentEvent` or if negotiated by content type.
- Text stream for a `Publisher` of `CharSequence`.
- A JSON stream if negotiated by content type to `MediaType.APPLICATION_NDJSON`.

Since:
  4.2
Author:
  Rossen Stoyanchev

## Constructor Summary

Constructors
Constructor
Description
`ResponseBodyEmitterReturnValueHandler(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)`
Simple constructor with reactive type support based on a default instance of `ReactiveAdapterRegistry`, `SyncTaskExecutor`, and `ContentNegotiationManager` with an Accept header strategy.
`ResponseBodyEmitterReturnValueHandler(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters, org.springframework.core.ReactiveAdapterRegistry registry, org.springframework.core.task.TaskExecutor executor, org.springframework.web.accept.ContentNegotiationManager manager)`
Constructor that with added arguments to customize "reactive" type support.
`ResponseBodyEmitterReturnValueHandler(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters, org.springframework.core.ReactiveAdapterRegistry registry, org.springframework.core.task.TaskExecutor executor, org.springframework.web.accept.ContentNegotiationManager manager, List<ViewResolver> viewResolvers, LocaleResolver localeResolver)`
Constructor that with added arguments for view rendering.

## Method Summary

Modifier and Type
Method
Description
`void`
`handleReturnValue(Object returnValue, org.springframework.core.MethodParameter returnType, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest)`
`boolean`
`supportsReturnType(org.springframework.core.MethodParameter returnType)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ResponseBodyEmitterReturnValueHandler

public ResponseBodyEmitterReturnValueHandler(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
Simple constructor with reactive type support based on a default instance of `ReactiveAdapterRegistry`, `SyncTaskExecutor`, and `ContentNegotiationManager` with an Accept header strategy.

### ResponseBodyEmitterReturnValueHandler

public ResponseBodyEmitterReturnValueHandler(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters, org.springframework.core.ReactiveAdapterRegistry registry, org.springframework.core.task.TaskExecutor executor, org.springframework.web.accept.ContentNegotiationManager manager)
Constructor that with added arguments to customize "reactive" type support.

Parameters:
  `messageConverters` - converters to write emitted objects with
  `registry` - for reactive return value type support
  `executor` - for blocking I/O writes of items emitted from reactive types
  `manager` - for detecting streaming media types
Since:
  5.0

### ResponseBodyEmitterReturnValueHandler

public ResponseBodyEmitterReturnValueHandler(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters, org.springframework.core.ReactiveAdapterRegistry registry, org.springframework.core.task.TaskExecutor executor, org.springframework.web.accept.ContentNegotiationManager manager, List<ViewResolver> viewResolvers, @Nullable LocaleResolver localeResolver)
Constructor that with added arguments for view rendering.

Parameters:
  `messageConverters` - converters to write emitted objects with
  `registry` - for reactive return value type support
  `executor` - for blocking I/O writes of items emitted from reactive types
  `manager` - for detecting streaming media types
  `viewResolvers` - resolvers for fragment stream rendering
  `localeResolver` - the `LocaleResolver` for fragment stream rendering
Since:
  6.2

## Method Details

### supportsReturnType

public boolean supportsReturnType(org.springframework.core.MethodParameter returnType)

Specified by:
  `supportsReturnType` in interface `org.springframework.web.method.support.HandlerMethodReturnValueHandler`

### handleReturnValue

public void handleReturnValue(@Nullable Object returnValue, org.springframework.core.MethodParameter returnType, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest) throws Exception

Specified by:
  `handleReturnValue` in interface `org.springframework.web.method.support.HandlerMethodReturnValueHandler`
Throws:
  `Exception`