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

public Class PayloadMethodArgumentResolver

extends Object
implements HandlerMethodArgumentResolver
Class Inheritance
All Implemented Interfaces
org.springframework.messaging.handler.invocation.reactive.HandlerMethodArgumentResolver
Imports
java.lang.annotation.Annotation, java.util.Collections, .List, .Map, java.util.function.Consumer, org.apache.commons.logging.Log, .LogFactory, org.reactivestreams.Publisher, reactor.core.publisher.Flux, .Mono, org.springframework.core.Conventions, .MethodParameter, .ReactiveAdapter, .ReactiveAdapterRegistry, .ResolvableType, org.springframework.core.codec.Decoder, .DecodingException, org.springframework.core.io.buffer.DataBuffer, .DataBufferUtils, org.springframework.lang.Nullable, org.springframework.messaging.Message, .MessageHeaders, org.springframework.messaging.handler.annotation.Payload, org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException, org.springframework.messaging.handler.invocation.MethodArgumentResolutionException, org.springframework.messaging.handler.invocation.reactive.HandlerMethodArgumentResolver, org.springframework.util.Assert, .CollectionUtils, .MimeType, .MimeTypeUtils, .ObjectUtils, .StringUtils, org.springframework.validation.BeanPropertyBindingResult, .SmartValidator, .Validator, org.springframework.validation.annotation.ValidationAnnotationUtils

A resolver to extract and decode the payload of a message using a Decoder, where the payload is expected to be a Publisher of DataBuffer.

Validation is applied if the method argument is annotated with org.springframework.validation.annotation.Validated or @jakarta.validation.Valid. Validation failure results in an MethodArgumentNotValidException.

This resolver should be ordered last if useDefaultResolution is set to true since in that case it supports all types and does not require the presence of Payload.

Author
Rossen Stoyanchev
Since
5.2

Field Summary

Modifier and TypeField and Description
private final ReactiveAdapterRegistry
private final List<Decoder<?>>
protected final Log
private final boolean
private final Validator

Constructor Summary

AccessConstructor and Description
public
PayloadMethodArgumentResolver(List<? extends Decoder<?>> decoders, Validator validator, ReactiveAdapterRegistry registry, boolean useDefaultResolution)

Method Summary

Modifier and TypeMethod and Description
private Mono<Object>
decodeContent(MethodParameter parameter, Message<?> message, boolean isContentRequired, Flux<DataBuffer> content, MimeType mimeType)

private Flux<DataBuffer>
extractContent(MethodParameter parameter, Message<?> message)

public ReactiveAdapterRegistry
public List<Decoder<?>>
getDecoders()

Return a read-only list of the configured decoders.

protected MimeType
getMimeType(Message<?>
the input message
message
)

Return the mime type for the content.

private MethodArgumentResolutionException
getUnexpectedPayloadError(Message<?> message, MethodParameter parameter, String actualType)

public Validator
getValidator()

Return the configured validator, if any.

private Consumer<Object>
getValidator(Message<?> message, MethodParameter parameter)

private MethodArgumentResolutionException
private Throwable
handleReadError(MethodParameter parameter, Message<?> message, Throwable ex)

public boolean
isUseDefaultResolution()

Whether this resolver is configured to use default resolution, i.e. works for any argument type regardless of whether @Payload is present or not.

private boolean
public final Mono<Object>

Returns:

a Mono with the result of argument resolution
resolveArgument
(MethodParameter
the target method argument that we are decoding to
parameter
,
Message<?>
the message from which the content was extracted
message
)

Implements org.springframework.messaging.handler.invocation.reactive.HandlerMethodArgumentResolver.resolveArgument.

Decode the content of the given message payload through a compatible Decoder.

public boolean
supportsParameter(MethodParameter
the method parameter to check
parameter
)

Implements org.springframework.messaging.handler.invocation.reactive.HandlerMethodArgumentResolver.supportsParameter.

Whether the given method parameter is supported by this resolver.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

adapterRegistryback to summary
private final ReactiveAdapterRegistry adapterRegistry
decodersback to summary
private final List<Decoder<?>> decoders
loggerback to summary
protected final Log logger
useDefaultResolutionback to summary
private final boolean useDefaultResolution
validatorback to summary
private final Validator validator
Annotations
@Nullable

Constructor Detail

PayloadMethodArgumentResolverback to summary
public PayloadMethodArgumentResolver(List<? extends Decoder<?>> decoders, Validator validator, ReactiveAdapterRegistry registry, boolean useDefaultResolution)

Method Detail

decodeContentback to summary
private Mono<Object> decodeContent(MethodParameter parameter, Message<?> message, boolean isContentRequired, Flux<DataBuffer> content, MimeType mimeType)
extractContentback to summary
private Flux<DataBuffer> extractContent(MethodParameter parameter, Message<?> message)
Annotations
@SuppressWarnings:unchecked
getAdapterRegistryback to summary
public ReactiveAdapterRegistry getAdapterRegistry()

Return the configured ReactiveAdapterRegistry.

getDecodersback to summary
public List<Decoder<?>> getDecoders()

Return a read-only list of the configured decoders.

getMimeTypeback to summary
protected MimeType getMimeType(Message<?> message)

Return the mime type for the content. By default this method checks the MessageHeaders#CONTENT_TYPE header expecting to find a MimeType value or a String to parse to a MimeType.

Parameters
message:Message<?>

the input message

Annotations
@Nullable
getUnexpectedPayloadErrorback to summary
private MethodArgumentResolutionException getUnexpectedPayloadError(Message<?> message, MethodParameter parameter, String actualType)
getValidatorback to summary
public Validator getValidator()

Return the configured validator, if any.

Annotations
@Nullable
getValidatorback to summary
private Consumer<Object> getValidator(Message<?> message, MethodParameter parameter)
Annotations
@Nullable
handleMissingBodyback to summary
private MethodArgumentResolutionException handleMissingBody(MethodParameter param, Message<?> message)
handleReadErrorback to summary
private Throwable handleReadError(MethodParameter parameter, Message<?> message, Throwable ex)
isUseDefaultResolutionback to summary
public boolean isUseDefaultResolution()

Whether this resolver is configured to use default resolution, i.e. works for any argument type regardless of whether @Payload is present or not.

nonEmptyDataBufferback to summary
private boolean nonEmptyDataBuffer(DataBuffer buffer)
resolveArgumentback to summary
public final Mono<Object> resolveArgument(MethodParameter parameter, Message<?> message)

Implements org.springframework.messaging.handler.invocation.reactive.HandlerMethodArgumentResolver.resolveArgument.

Decode the content of the given message payload through a compatible Decoder.

Validation is applied if the method argument is annotated with @jakarta.validation.Valid or org.springframework.validation.annotation.Validated. Validation failure results in an MethodArgumentNotValidException.

Parameters
parameter:MethodParameter

the target method argument that we are decoding to

message:Message<?>

the message from which the content was extracted

Returns:Mono<Object>

a Mono with the result of argument resolution

Annotations
@Override
See Also
extractContent(MethodParameter, Message), getMimeType(Message)
supportsParameterback to summary
public boolean supportsParameter(MethodParameter parameter)

Implements org.springframework.messaging.handler.invocation.reactive.HandlerMethodArgumentResolver.supportsParameter.

Doc from org.springframework.messaging.handler.invocation.reactive.HandlerMethodArgumentResolver.supportsParameter.

Whether the given method parameter is supported by this resolver.

Parameters
parameter:MethodParameter

the method parameter to check

Returns:boolean

true if this resolver supports the supplied parameter; false otherwise

Annotations
@Override