org.springframework.messaging.handler.annotation.reactive

## Class MessageMappingMessageHandler

- java.lang.Object
- - org.springframework.messaging.handler.invocation.reactive.AbstractMethodMessageHandler<CompositeMessageCondition>
  - - org.springframework.messaging.handler.annotation.reactive.MessageMappingMessageHandler

All Implemented Interfaces:
  org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.context.EmbeddedValueResolverAware, ReactiveMessageHandler

Direct Known Subclasses:
  RSocketMessageHandler

    public class MessageMappingMessageHandler
    extends AbstractMethodMessageHandler<CompositeMessageCondition>
    implements org.springframework.context.EmbeddedValueResolverAware

Extension of `AbstractMethodMessageHandler` for reactive, non-blocking handling of messages via `@MessageMapping` methods. By default such methods are detected in `@Controller` Spring beans but that can be changed via `AbstractMethodMessageHandler.setHandlerPredicate(Predicate)`.

Payloads for incoming messages are decoded through the configured `setDecoders(List)` decoders, with the help of `PayloadMethodArgumentResolver`.

There is no default handling for return values but `AbstractMethodMessageHandler.setReturnValueHandlerConfigurer(org.springframework.messaging.handler.invocation.reactive.ReturnValueHandlerConfigurer)` can be used to configure custom return value handlers. Sub-classes may also override `initReturnValueHandlers()` to set up default return value handlers.

Since:
  5.2
Author:
  Rossen Stoyanchev
See Also:
  `AbstractEncoderMethodReturnValueHandler`

### Field Summary

### Fields inherited from class org.springframework.messaging.handler.invocation.reactive.AbstractMethodMessageHandler

`logger`

### Constructor Summary

Constructors
Constructor and Description
`MessageMappingMessageHandler()`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `afterPropertiesSet()`
`protected AbstractExceptionHandlerMethodResolver` `createExceptionMethodResolverFor(Class<?> beanType)` Create a concrete instance of `AbstractExceptionHandlerMethodResolver` that finds exception handling methods based on some criteria, e.g.
`protected CompositeMessageCondition` `getCondition(AnnotatedElement element)` Determine the mapping condition for the given annotated element.
`org.springframework.core.convert.ConversionService` `getConversionService()` Return the configured ConversionService.
`List<? extends org.springframework.core.codec.Decoder<?>>` `getDecoders()` Return the configured decoders.
`protected org.springframework.util.RouteMatcher.Route` `getDestination(Message<?> message)` Extract the destination from the given message.
`protected Set<String>` `getDirectLookupMappings(CompositeMessageCondition mapping)` Return String-based destinations for the given mapping, if any, that can be used to find matches with a direct lookup (i.e.
`protected Comparator<CompositeMessageCondition>` `getMappingComparator(Message<?> message)` Return a comparator for sorting matching mappings.
`protected CompositeMessageCondition` `getMappingForMethod(Method method, Class<?> handlerType)` Obtain the mapping for the given method, if any.
`protected CompositeMessageCondition` `getMatchingMapping(CompositeMessageCondition mapping, Message<?> message)` Check if a mapping matches the current message and return a possibly new mapping with conditions relevant to the current request.
`org.springframework.util.RouteMatcher` `getRouteMatcher()` Return the `RouteMatcher` used to map messages to handlers.
`org.springframework.validation.Validator` `getValidator()` Return the configured Validator instance.
`protected reactor.core.publisher.Mono<Void>` `handleMatch(CompositeMessageCondition mapping, HandlerMethod handlerMethod, Message<?> message)`
`protected List<? extends HandlerMethodArgumentResolver>` `initArgumentResolvers()` Return the list of argument resolvers to use.
`protected List<? extends HandlerMethodReturnValueHandler>` `initReturnValueHandlers()` Return the list of return value handlers to use.
`protected org.springframework.util.RouteMatcher` `obtainRouteMatcher()` Obtain the `RouteMatcher` for actual use.
`protected String[]` `processDestinations(String[] destinations)` Resolve placeholders in the given destinations.
`void` `setConversionService(org.springframework.core.convert.ConversionService conversionService)` Configure a `ConversionService` to use for type conversion of String based values, e.g.
`void` `setDecoders(List<? extends org.springframework.core.codec.Decoder<?>> decoders)` Configure the decoders to use for incoming payloads.
`void` `setEmbeddedValueResolver(org.springframework.util.StringValueResolver resolver)`
`void` `setRouteMatcher(org.springframework.util.RouteMatcher routeMatcher)` Set the `RouteMatcher` to use for mapping messages to handlers based on the route patterns they're configured with.
`void` `setValidator(org.springframework.validation.Validator validator)` Set the Validator instance used for validating `@Payload` arguments.

### Methods inherited from class org.springframework.messaging.handler.invocation.reactive.AbstractMethodMessageHandler

`detectHandlerMethods, extendMapping, getApplicationContext, getArgumentResolverConfigurer, getArgumentResolvers, getBeanName, getDestinationLookup, getHandlerMethods, getHandlerPredicate, getReactiveAdapterRegistry, getReturnValueHandlerConfigurer, handleMessage, handleNoMatch, registerExceptionHandlerAdvice, registerHandlerMethod, setApplicationContext, setArgumentResolverConfigurer, setBeanName, setHandlerPredicate, setHandlers, setReactiveAdapterRegistry, setReturnValueHandlerConfigurer`

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

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

### Constructor Detail

#### MessageMappingMessageHandler

    public MessageMappingMessageHandler()

### Method Detail

#### setDecoders

    public void setDecoders(List<? extends org.springframework.core.codec.Decoder<?>> decoders)

Configure the decoders to use for incoming payloads.

#### getDecoders

    public List<? extends org.springframework.core.codec.Decoder<?>> getDecoders()

Return the configured decoders.

#### setValidator

    public void setValidator(@Nullable
                             org.springframework.validation.Validator validator)

Set the Validator instance used for validating `@Payload` arguments.

See Also:
  `Validated`, `PayloadMethodArgumentResolver`

#### getValidator

    @Nullable
    public org.springframework.validation.Validator getValidator()

Return the configured Validator instance.

#### setRouteMatcher

    public void setRouteMatcher(@Nullable
                                org.springframework.util.RouteMatcher routeMatcher)

Set the `RouteMatcher` to use for mapping messages to handlers based on the route patterns they're configured with.

By default, `SimpleRouteMatcher` is used, backed by `AntPathMatcher` with "." as separator. For greater efficiency consider using the `PathPatternRouteMatcher` from `spring-web` instead.

#### getRouteMatcher

    @Nullable
    public org.springframework.util.RouteMatcher getRouteMatcher()

Return the `RouteMatcher` used to map messages to handlers. May be `null` before the component is initialized.

#### obtainRouteMatcher

    protected org.springframework.util.RouteMatcher obtainRouteMatcher()

Obtain the `RouteMatcher` for actual use.

Returns:
  the RouteMatcher (never `null`)
Throws:
  `IllegalStateException` - in case of no RouteMatcher set
Since:
  5.0

#### setConversionService

    public void setConversionService(org.springframework.core.convert.ConversionService conversionService)

Configure a `ConversionService` to use for type conversion of String based values, e.g. in destination variables or headers.

By default `DefaultFormattingConversionService` is used.

Parameters:
  `conversionService` - the conversion service to use

#### getConversionService

    public org.springframework.core.convert.ConversionService getConversionService()

Return the configured ConversionService.

#### setEmbeddedValueResolver

    public void setEmbeddedValueResolver(org.springframework.util.StringValueResolver resolver)

Specified by:
  `setEmbeddedValueResolver` in interface `org.springframework.context.EmbeddedValueResolverAware`

#### afterPropertiesSet

    public void afterPropertiesSet()

Specified by:
  `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
Overrides:
  `afterPropertiesSet` in class `AbstractMethodMessageHandler<CompositeMessageCondition>`

#### initArgumentResolvers

    protected List<? extends HandlerMethodArgumentResolver> initArgumentResolvers()

Description copied from class: `AbstractMethodMessageHandler`
Return the list of argument resolvers to use.

Subclasses should also take into account custom argument types configured via `AbstractMethodMessageHandler.setArgumentResolverConfigurer(org.springframework.messaging.handler.invocation.reactive.ArgumentResolverConfigurer)`.

Specified by:
  `initArgumentResolvers` in class `AbstractMethodMessageHandler<CompositeMessageCondition>`

#### initReturnValueHandlers

    protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers()

Description copied from class: `AbstractMethodMessageHandler`
Return the list of return value handlers to use.

Subclasses should also take into account custom return value types configured via `AbstractMethodMessageHandler.setReturnValueHandlerConfigurer(org.springframework.messaging.handler.invocation.reactive.ReturnValueHandlerConfigurer)`.

Specified by:
  `initReturnValueHandlers` in class `AbstractMethodMessageHandler<CompositeMessageCondition>`

#### getMappingForMethod

    protected CompositeMessageCondition getMappingForMethod(Method method,
                                                            Class<?> handlerType)

Description copied from class: `AbstractMethodMessageHandler`
Obtain the mapping for the given method, if any.

Specified by:
  `getMappingForMethod` in class `AbstractMethodMessageHandler<CompositeMessageCondition>`
Parameters:
  `method` - the method to check
  `handlerType` - the handler type, possibly a sub-type of the method's declaring class
Returns:
  the mapping, or `null` if the method is not mapped

#### getCondition

    @Nullable
    protected CompositeMessageCondition getCondition(AnnotatedElement element)

Determine the mapping condition for the given annotated element.

Parameters:
  `element` - the element to check
Returns:
  the condition, or `null`

#### processDestinations

    protected String[] processDestinations(String[] destinations)

Resolve placeholders in the given destinations.

Parameters:
  `destinations` - the destinations
Returns:
  new array with the processed destinations or the same array

#### getDirectLookupMappings

    protected Set<String> getDirectLookupMappings(CompositeMessageCondition mapping)

Description copied from class: `AbstractMethodMessageHandler`
Return String-based destinations for the given mapping, if any, that can be used to find matches with a direct lookup (i.e. non-patterns).

Note: This is completely optional. The mapping metadata for a subclass may support neither direct lookups, nor String based destinations.

Specified by:
  `getDirectLookupMappings` in class `AbstractMethodMessageHandler<CompositeMessageCondition>`

#### getDestination

    protected org.springframework.util.RouteMatcher.Route getDestination(Message<?> message)

Description copied from class: `AbstractMethodMessageHandler`
Extract the destination from the given message.

Specified by:
  `getDestination` in class `AbstractMethodMessageHandler<CompositeMessageCondition>`
See Also:
  `AbstractMethodMessageHandler.getDirectLookupMappings(Object)`

#### getMatchingMapping

    protected CompositeMessageCondition getMatchingMapping(CompositeMessageCondition mapping,
                                                           Message<?> message)

Description copied from class: `AbstractMethodMessageHandler`
Check if a mapping matches the current message and return a possibly new mapping with conditions relevant to the current request.

Specified by:
  `getMatchingMapping` in class `AbstractMethodMessageHandler<CompositeMessageCondition>`
Parameters:
  `mapping` - the mapping to get a match for
  `message` - the message being handled
Returns:
  the match or `null` if there is no match

#### getMappingComparator

    protected Comparator<CompositeMessageCondition> getMappingComparator(Message<?> message)

Description copied from class: `AbstractMethodMessageHandler`
Return a comparator for sorting matching mappings. The returned comparator should sort 'better' matches higher.

Specified by:
  `getMappingComparator` in class `AbstractMethodMessageHandler<CompositeMessageCondition>`
Parameters:
  `message` - the current Message
Returns:
  the comparator, never `null`

#### createExceptionMethodResolverFor

    protected AbstractExceptionHandlerMethodResolver createExceptionMethodResolverFor(Class<?> beanType)

Description copied from class: `AbstractMethodMessageHandler`
Create a concrete instance of `AbstractExceptionHandlerMethodResolver` that finds exception handling methods based on some criteria, e.g. based on the presence of `@MessageExceptionHandler`.

Specified by:
  `createExceptionMethodResolverFor` in class `AbstractMethodMessageHandler<CompositeMessageCondition>`
Parameters:
  `beanType` - the class in which an exception occurred during handling
Returns:
  the resolver to use

#### handleMatch

    protected reactor.core.publisher.Mono<Void> handleMatch(CompositeMessageCondition mapping,
                                                            HandlerMethod handlerMethod,
                                                            Message<?> message)

Overrides:
  `handleMatch` in class `AbstractMethodMessageHandler<CompositeMessageCondition>`