org.springframework.messaging.simp.annotation.support

## Class SimpAnnotationMethodMessageHandler

- java.lang.Object
- - org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler<SimpMessageMappingInfo>
  - - org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler

All Implemented Interfaces:
  org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.context.EmbeddedValueResolverAware, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, MessageHandler

    public class SimpAnnotationMethodMessageHandler
    extends AbstractMethodMessageHandler<SimpMessageMappingInfo>
    implements org.springframework.context.EmbeddedValueResolverAware, org.springframework.context.SmartLifecycle

A handler for messages delegating to `@MessageMapping` and `@SubscribeMapping` annotated methods.

Supports Ant-style path patterns with template variables.

Since:
  4.0
Author:
  Rossen Stoyanchev, Brian Clozel, Juergen Hoeller

### Field Summary

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

`logger`

### Fields inherited from interface org.springframework.context.SmartLifecycle

`DEFAULT_PHASE`

### Constructor Summary

Constructors
Constructor and Description
`SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate)` Create an instance of SimpAnnotationMethodMessageHandler with the given message channels and broker messaging template.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected AbstractExceptionHandlerMethodResolver` `createExceptionHandlerMethodResolverFor(Class<?> beanType)`
`org.springframework.core.convert.ConversionService` `getConversionService()` Return the configured `ConversionService`.
`protected String` `getDestination(Message<?> message)`
`protected Set<String>` `getDirectLookupDestinations(SimpMessageMappingInfo mapping)` Return destinations contained in the mapping that are not patterns and are therefore suitable for direct lookups.
`protected Log` `getHandlerMethodLogger()` Return a logger to set on `InvocableHandlerMethod`.
`MessageHeaderInitializer` `getHeaderInitializer()` Return the configured header initializer.
`protected String` `getLookupDestination(String destination)` Check whether the given destination (of an incoming message) matches to one of the configured destination prefixes and if so return the remaining portion of the destination after the matched prefix.
`protected Comparator<SimpMessageMappingInfo>` `getMappingComparator(Message<?> message)` Return a comparator for sorting matching mappings.
`protected SimpMessageMappingInfo` `getMappingForMethod(Method method, Class<?> handlerType)` Provide the mapping for a handler method.
`protected SimpMessageMappingInfo` `getMatchingMapping(SimpMessageMappingInfo mapping, Message<?> message)` Check if a mapping matches the current message and return a possibly new mapping with conditions relevant to the current request.
`MessageConverter` `getMessageConverter()` Return the configured `MessageConverter`.
`org.springframework.util.PathMatcher` `getPathMatcher()` Return the PathMatcher implementation to use for matching destinations.
`protected Log` `getReturnValueHandlerLogger()` Return a logger to set on `HandlerMethodReturnValueHandlerComposite`.
`org.springframework.validation.Validator` `getValidator()` Return the configured Validator instance.
`protected void` `handleMatch(SimpMessageMappingInfo mapping, HandlerMethod handlerMethod, String lookupDestination, Message<?> message)`
`protected List<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 boolean` `isHandler(Class<?> beanType)` Whether the given bean type should be introspected for messaging handling methods.
`boolean` `isRunning()`
`protected String[]` `resolveEmbeddedValuesInDestinations(String[] destinations)` Resolve placeholder values in the given array of destinations.
`void` `setConversionService(org.springframework.core.convert.ConversionService conversionService)` Configure a `ConversionService` to use when resolving method arguments, for example message header values.
`void` `setDestinationPrefixes(Collection<String> prefixes)` When this property is configured only messages to destinations matching one of the configured prefixes are eligible for handling.
`void` `setEmbeddedValueResolver(org.springframework.util.StringValueResolver resolver)`
`void` `setHeaderInitializer(MessageHeaderInitializer headerInitializer)` Configure a `MessageHeaderInitializer` to pass on to `HandlerMethodReturnValueHandlers` that send messages from controller return values.
`void` `setMessageConverter(MessageConverter converter)` Configure a `MessageConverter` to use to convert the payload of a message from its serialized form with a specific MIME type to an Object matching the target method parameter.
`void` `setPathMatcher(org.springframework.util.PathMatcher pathMatcher)` Set the PathMatcher implementation to use for matching destinations against configured destination patterns.
`void` `setValidator(org.springframework.validation.Validator validator)` Set the Validator instance used for validating `@Payload` arguments.
`void` `start()`
`void` `stop()`
`void` `stop(Runnable callback)`

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

`afterPropertiesSet, createHandlerMethod, detectHandlerMethods, getApplicationContext, getArgumentResolvers, getCustomArgumentResolvers, getCustomReturnValueHandlers, getDestinationPrefixes, getExceptionHandlerMethod, getHandlerMethods, getReturnValueHandlers, handleMessage, handleMessageInternal, handleNoMatch, processHandlerMethodException, registerExceptionHandlerAdvice, registerHandlerMethod, setApplicationContext, setArgumentResolvers, setCustomArgumentResolvers, setCustomReturnValueHandlers, setReturnValueHandlers, toString`

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

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

### Methods inherited from interface org.springframework.context.SmartLifecycle

`getPhase, isAutoStartup`

### Constructor Detail

#### SimpAnnotationMethodMessageHandler

    public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel,
                                              MessageChannel clientOutboundChannel,
                                              SimpMessageSendingOperations brokerTemplate)

Create an instance of SimpAnnotationMethodMessageHandler with the given message channels and broker messaging template.

Parameters:
  `clientInboundChannel` - the channel for receiving messages from clients (e.g. WebSocket clients)
  `clientOutboundChannel` - the channel for messages to clients (e.g. WebSocket clients)
  `brokerTemplate` - a messaging template to send application messages to the broker

### Method Detail

#### setDestinationPrefixes

    public void setDestinationPrefixes(@Nullable
                                       Collection<String> prefixes)

When this property is configured only messages to destinations matching one of the configured prefixes are eligible for handling. When there is a match the prefix is removed and only the remaining part of the destination is used for method-mapping purposes.

By default, no prefixes are configured in which case all messages are eligible for handling.

Destination prefixes are expected to be slash-separated Strings and therefore a slash is automatically appended where missing to ensure a proper prefix-based match (i.e. matching complete segments).

Note however that the remaining portion of a destination after the prefix may use a different separator (e.g. commonly "." in messaging) depending on the configured `PathMatcher`.

Overrides:
  `setDestinationPrefixes` in class `AbstractMethodMessageHandler<SimpMessageMappingInfo>`

#### setMessageConverter

    public void setMessageConverter(MessageConverter converter)

Configure a `MessageConverter` to use to convert the payload of a message from its serialized form with a specific MIME type to an Object matching the target method parameter. The converter is also used when sending a message to the message broker.

See Also:
  `CompositeMessageConverter`

#### getMessageConverter

    public MessageConverter getMessageConverter()

Return the configured `MessageConverter`.

#### setConversionService

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

Configure a `ConversionService` to use when resolving method arguments, for example message header values.

By default, `DefaultFormattingConversionService` is used.

#### getConversionService

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

Return the configured `ConversionService`.

#### setPathMatcher

    public void setPathMatcher(org.springframework.util.PathMatcher pathMatcher)

Set the PathMatcher implementation to use for matching destinations against configured destination patterns.

By default, `AntPathMatcher` is used.

#### getPathMatcher

    public org.springframework.util.PathMatcher getPathMatcher()

Return the PathMatcher implementation to use for matching destinations.

#### getValidator

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

Return the configured Validator instance.

#### setValidator

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

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

See Also:
  `Validated`, `PayloadMethodArgumentResolver`

#### setEmbeddedValueResolver

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

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

#### setHeaderInitializer

    public void setHeaderInitializer(@Nullable
                                     MessageHeaderInitializer headerInitializer)

Configure a `MessageHeaderInitializer` to pass on to `HandlerMethodReturnValueHandlers` that send messages from controller return values.

By default, this property is not set.

#### getHeaderInitializer

    @Nullable
    public MessageHeaderInitializer getHeaderInitializer()

Return the configured header initializer.

#### start

    public final void start()

Specified by:
  `start` in interface `org.springframework.context.Lifecycle`

#### stop

    public final void stop()

Specified by:
  `stop` in interface `org.springframework.context.Lifecycle`

#### stop

    public final void stop(Runnable callback)

Specified by:
  `stop` in interface `org.springframework.context.SmartLifecycle`

#### isRunning

    public final boolean isRunning()

Specified by:
  `isRunning` in interface `org.springframework.context.Lifecycle`

#### initArgumentResolvers

    protected List<HandlerMethodArgumentResolver> initArgumentResolvers()

Description copied from class: `AbstractMethodMessageHandler`
Return the list of argument resolvers to use. Invoked only if the resolvers have not already been set via `AbstractMethodMessageHandler.setArgumentResolvers(java.util.List<org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver>)`.

Subclasses should also take into account custom argument types configured via `AbstractMethodMessageHandler.setCustomArgumentResolvers(java.util.List<org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver>)`.

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

#### initReturnValueHandlers

    protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers()

Description copied from class: `AbstractMethodMessageHandler`
Return the list of return value handlers to use. Invoked only if the return value handlers have not already been set via `AbstractMethodMessageHandler.setReturnValueHandlers(java.util.List<org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler>)`.

Subclasses should also take into account custom return value types configured via `AbstractMethodMessageHandler.setCustomReturnValueHandlers(java.util.List<org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler>)`.

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

#### getReturnValueHandlerLogger

    protected Log getReturnValueHandlerLogger()

Description copied from class: `AbstractMethodMessageHandler`
Return a logger to set on `HandlerMethodReturnValueHandlerComposite`.

Overrides:
  `getReturnValueHandlerLogger` in class `AbstractMethodMessageHandler<SimpMessageMappingInfo>`

#### getHandlerMethodLogger

    protected Log getHandlerMethodLogger()

Description copied from class: `AbstractMethodMessageHandler`
Return a logger to set on `InvocableHandlerMethod`.

Overrides:
  `getHandlerMethodLogger` in class `AbstractMethodMessageHandler<SimpMessageMappingInfo>`

#### isHandler

    protected boolean isHandler(Class<?> beanType)

Description copied from class: `AbstractMethodMessageHandler`
Whether the given bean type should be introspected for messaging handling methods.

Specified by:
  `isHandler` in class `AbstractMethodMessageHandler<SimpMessageMappingInfo>`

#### getMappingForMethod

    @Nullable
    protected SimpMessageMappingInfo getMappingForMethod(Method method,
                                                                   Class<?> handlerType)

Description copied from class: `AbstractMethodMessageHandler`
Provide the mapping for a handler method.

Specified by:
  `getMappingForMethod` in class `AbstractMethodMessageHandler<SimpMessageMappingInfo>`
Parameters:
  `method` - the method to provide a mapping for
  `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

#### resolveEmbeddedValuesInDestinations

    protected String[] resolveEmbeddedValuesInDestinations(String[] destinations)

Resolve placeholder values in the given array of destinations.

Returns:
  a new array with updated destinations
Since:
  4.2

#### getDirectLookupDestinations

    protected Set<String> getDirectLookupDestinations(SimpMessageMappingInfo mapping)

Description copied from class: `AbstractMethodMessageHandler`
Return destinations contained in the mapping that are not patterns and are therefore suitable for direct lookups.

Specified by:
  `getDirectLookupDestinations` in class `AbstractMethodMessageHandler<SimpMessageMappingInfo>`

#### getDestination

    @Nullable
    protected String getDestination(Message<?> message)

Specified by:
  `getDestination` in class `AbstractMethodMessageHandler<SimpMessageMappingInfo>`

#### getLookupDestination

    protected String getLookupDestination(@Nullable
                                          String destination)

Description copied from class: `AbstractMethodMessageHandler`
Check whether the given destination (of an incoming message) matches to one of the configured destination prefixes and if so return the remaining portion of the destination after the matched prefix.

If there are no matching prefixes, return `null`.

If there are no destination prefixes, return the destination as is.

Overrides:
  `getLookupDestination` in class `AbstractMethodMessageHandler<SimpMessageMappingInfo>`

#### getMatchingMapping

    @Nullable
    protected SimpMessageMappingInfo getMatchingMapping(SimpMessageMappingInfo 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<SimpMessageMappingInfo>`
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<SimpMessageMappingInfo> 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<SimpMessageMappingInfo>`
Parameters:
  `message` - the current Message
Returns:
  the comparator, never `null`

#### handleMatch

    protected void handleMatch(SimpMessageMappingInfo mapping,
                               HandlerMethod handlerMethod,
                               String lookupDestination,
                               Message<?> message)

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

#### createExceptionHandlerMethodResolverFor

    protected AbstractExceptionHandlerMethodResolver createExceptionHandlerMethodResolverFor(Class<?> beanType)

Specified by:
  `createExceptionHandlerMethodResolverFor` in class `AbstractMethodMessageHandler<SimpMessageMappingInfo>`