Top Description Fields Constructors Methods
org.springframework.messaging.handler.invocation.reactive

public abstract Class AbstractEncoderMethodReturnValueHandler

extends Object
implements HandlerMethodReturnValueHandler
Class Inheritance
All Implemented Interfaces
org.springframework.messaging.handler.invocation.reactive.HandlerMethodReturnValueHandler
Known Direct Subclasses
org.springframework.messaging.rsocket.annotation.support.RSocketPayloadReturnValueHandler
Imports
java.lang.reflect.Method, java.util.Collections, .List, .Map, org.apache.commons.logging.Log, .LogFactory, org.reactivestreams.Publisher, reactor.core.publisher.Flux, .Mono, org.springframework.core.KotlinDetector, .MethodParameter, .ReactiveAdapter, .ReactiveAdapterRegistry, .ResolvableType, org.springframework.core.codec.Encoder, org.springframework.core.io.buffer.DataBuffer, .DataBufferFactory, .DefaultDataBufferFactory, org.springframework.lang.Nullable, org.springframework.messaging.Message, .MessageHeaders, .MessagingException, org.springframework.util.Assert, .ClassUtils, .MimeType

Base class for a return value handler that encodes return values to Flux<DataBuffer> through the configured Encoders.

Subclasses must implement the abstract method handleEncodedContent to handle the resulting encoded content.

This handler should be ordered last since its supportsReturnType returns true for any method parameter type.

Author
Rossen Stoyanchev
Since
5.2

Field Summary

Modifier and TypeField and Description
private final ReactiveAdapterRegistry
private static final String
private final List<Encoder<?>>
protected final Log
private static final ResolvableType
private static final ResolvableType

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
private Flux<DataBuffer>
encodeContent(Object content, MethodParameter returnType, DataBufferFactory bufferFactory, MimeType mimeType, Map<String, Object> hints)

private <T> DataBuffer
encodeValue(Object element, ResolvableType elementType, Encoder<T> encoder, DataBufferFactory bufferFactory, MimeType mimeType, Map<String, Object> hints)

public ReactiveAdapterRegistry
getAdapterRegistry()

The configured adapter registry.

private ResolvableType
private <T> Encoder<T>
getEncoder(ResolvableType elementType, MimeType mimeType)

public List<Encoder<?>>
getEncoders()

The configured encoders.

protected abstract Mono<Void>

Returns:

completion Mono<Void> for the handling
handleEncodedContent
(Flux<DataBuffer>
the encoded content; each DataBuffer represents the fully-aggregated, encoded content for one value (i.e. payload) returned from the HandlerMethod.
encodedContent
,
MethodParameter
return type of the handler method that produced the data
returnType
,
Message<?>
the input message handled by the handler method
message
)

Subclasses implement this method to handle encoded values in some way such as creating and sending messages.

protected abstract Mono<Void>

Returns:

completion Mono<Void> for the handling
handleNoContent
(MethodParameter
return type of the handler method that produced the data
returnType
,
Message<?>
the input message handled by the handler method
message
)

Invoked for a null return value, which could mean a void method or method returning an async type parameterized by void.

public Mono<Void>
handleReturnValue(Object
the value returned from the handler method
returnValue
,
MethodParameter
the type of the return value. This type must have previously been passed to supportsReturnType(MethodParameter) and it must have returned true.
returnType
,
Message<?> message)

Implements org.springframework.messaging.handler.invocation.reactive.HandlerMethodReturnValueHandler.handleReturnValue.

Handle the given return value.

public boolean
supportsReturnType(MethodParameter
the method return type to check
returnType
)

Implements org.springframework.messaging.handler.invocation.reactive.HandlerMethodReturnValueHandler.supportsReturnType.

Whether the given method return type is supported by this handler.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

adapterRegistryback to summary
private final ReactiveAdapterRegistry adapterRegistry
COROUTINES_FLOW_CLASS_NAMEback to summary
private static final String COROUTINES_FLOW_CLASS_NAME
encodersback to summary
private final List<Encoder<?>> encoders
loggerback to summary
protected final Log logger
OBJECT_RESOLVABLE_TYPEback to summary
private static final ResolvableType OBJECT_RESOLVABLE_TYPE
VOID_RESOLVABLE_TYPEback to summary
private static final ResolvableType VOID_RESOLVABLE_TYPE

Constructor Detail

AbstractEncoderMethodReturnValueHandlerback to summary
protected AbstractEncoderMethodReturnValueHandler(List<Encoder<?>> encoders, ReactiveAdapterRegistry registry)

Method Detail

encodeContentback to summary
private Flux<DataBuffer> encodeContent(Object content, MethodParameter returnType, DataBufferFactory bufferFactory, MimeType mimeType, Map<String, Object> hints)
encodeValueback to summary
private <T> DataBuffer encodeValue(Object element, ResolvableType elementType, Encoder<T> encoder, DataBufferFactory bufferFactory, MimeType mimeType, Map<String, Object> hints)
Annotations
@SuppressWarnings:unchecked
getAdapterRegistryback to summary
public ReactiveAdapterRegistry getAdapterRegistry()

The configured adapter registry.

getElementTypeback to summary
private ResolvableType getElementType(ReactiveAdapter adapter, ResolvableType type)
getEncoderback to summary
private <T> Encoder<T> getEncoder(ResolvableType elementType, MimeType mimeType)
Annotations
@Nullable
@SuppressWarnings:unchecked
getEncodersback to summary
public List<Encoder<?>> getEncoders()

The configured encoders.

handleEncodedContentback to summary
protected abstract Mono<Void> handleEncodedContent(Flux<DataBuffer> encodedContent, MethodParameter returnType, Message<?> message)

Subclasses implement this method to handle encoded values in some way such as creating and sending messages.

Parameters
encodedContent:Flux<DataBuffer>

the encoded content; each DataBuffer represents the fully-aggregated, encoded content for one value (i.e. payload) returned from the HandlerMethod.

returnType:MethodParameter

return type of the handler method that produced the data

message:Message<?>

the input message handled by the handler method

Returns:Mono<Void>

completion Mono<Void> for the handling

handleNoContentback to summary
protected abstract Mono<Void> handleNoContent(MethodParameter returnType, Message<?> message)

Invoked for a null return value, which could mean a void method or method returning an async type parameterized by void.

Parameters
returnType:MethodParameter

return type of the handler method that produced the data

message:Message<?>

the input message handled by the handler method

Returns:Mono<Void>

completion Mono<Void> for the handling

handleReturnValueback to summary
public Mono<Void> handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message)

Implements org.springframework.messaging.handler.invocation.reactive.HandlerMethodReturnValueHandler.handleReturnValue.

Doc from org.springframework.messaging.handler.invocation.reactive.HandlerMethodReturnValueHandler.handleReturnValue.

Handle the given return value.

Parameters
returnValue:Object

the value returned from the handler method

returnType:MethodParameter

the type of the return value. This type must have previously been passed to supportsReturnType(MethodParameter) and it must have returned true.

Returns:Mono<Void>

Mono<Void> to indicate when handling is complete.

Annotations
@Override
supportsReturnTypeback to summary
public boolean supportsReturnType(MethodParameter returnType)

Implements org.springframework.messaging.handler.invocation.reactive.HandlerMethodReturnValueHandler.supportsReturnType.

Doc from org.springframework.messaging.handler.invocation.reactive.HandlerMethodReturnValueHandler.supportsReturnType.

Whether the given method return type is supported by this handler.

Parameters
returnType:MethodParameter

the method return type to check

Returns:boolean

true if this handler supports the supplied return type; false otherwise

Annotations
@Override