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:
    Aware, InitializingBean, ApplicationContextAware, Lifecycle, Phased, SmartLifecycle, MessageHandler

      public class SimpAnnotationMethodMessageHandler
      extends AbstractMethodMessageHandler<SimpMessageMappingInfo>
      implements 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

- - ### Field Summary

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

      `logger`

  - ### 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
    Modifier and Type | Method and Description
    --- | ---
    `protected AbstractExceptionHandlerMethodResolver` | `createExceptionHandlerMethodResolverFor(Class<?> beanType)`
    `ConversionService` | `getConversionService()` 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 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`.
    `PathMatcher` | `getPathMatcher()` Return the PathMatcher implementation to use for matching destinations
    `int` | `getPhase()` Return the phase value of this object.
    `Validator` | `getValidator()` 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.
    `boolean` | `isAutoStartup()` Return whether this Lifecycle component should be started automatically by the container when the ApplicationContext is refreshed.
    `protected boolean` | `isHandler(Class<?> beanType)` Whether the given bean type should be introspected for messaging handling methods.
    `boolean` | `isRunning()` Check whether this component is currently running.
    `void` | `setConversionService(ConversionService conversionService)` Configure a `ConversionService` to use when resolving method arguments, for example message header values.
    `void` | `setMessageConverter(MessageConverter converter)` Configure a `MessageConverter` to use to convert the payload of a message from serialize form with a specific MIME type to an Object matching the target method parameter.
    `void` | `setPathMatcher(PathMatcher pathMatcher)` Set the PathMatcher implementation to use for matching destinations against configured destination patterns.
    `void` | `setValidator(Validator validator)` Set the Validator instance used for validating @Payload arguments
    `void` | `start()` Start this component.
    `void` | `stop()` Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.
    `void` | `stop(Runnable callback)` Indicates that a Lifecycle component must stop if it is currently running.

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

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

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

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

- - ### 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

    - #### setMessageConverter

          public void setMessageConverter(MessageConverter converter)

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

    - #### getMessageConverter

          public MessageConverter getMessageConverter()

      Return the configured `MessageConverter`.

    - #### setConversionService

          public void setConversionService(ConversionService conversionService)

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

      By default an instance of `DefaultFormattingConversionService` is used.

    - #### getConversionService

          public ConversionService getConversionService()

      The configured `ConversionService`.

    - #### setPathMatcher

          public void setPathMatcher(PathMatcher pathMatcher)

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

      By default AntPathMatcher is used

    - #### getPathMatcher

          public PathMatcher getPathMatcher()

      Return the PathMatcher implementation to use for matching destinations

    - #### getValidator

          public Validator getValidator()

      The configured Validator instance

    - #### setValidator

          public void setValidator(Validator validator)

      Set the Validator instance used for validating @Payload arguments
      See Also:
        `Validated`, `PayloadArgumentResolver`

    - #### isAutoStartup

          public boolean isAutoStartup()

      Description copied from interface: `SmartLifecycle`
      Return whether this Lifecycle component should be started automatically by the container when the ApplicationContext is refreshed. A value of "false" indicates that the component is intended to be started manually.
      Specified by:
        `isAutoStartup` in interface `SmartLifecycle`

    - #### getPhase

          public int getPhase()

      Description copied from interface: `Phased`
      Return the phase value of this object.
      Specified by:
        `getPhase` in interface `Phased`

    - #### isRunning

          public final boolean isRunning()

      Description copied from interface: `Lifecycle`
      Check whether this component is currently running.

      In the case of a container, this will return `true` only if all components that apply are currently running.

      Specified by:
        `isRunning` in interface `Lifecycle`
      Returns:
        whether the component is currently running

    - #### start

          public final void start()

      Description copied from interface: `Lifecycle`
      Start this component. Should not throw an exception if the component is already running.

      In the case of a container, this will propagate the start signal to all components that apply.

      Specified by:
        `start` in interface `Lifecycle`

    - #### stop

          public final void stop()

      Description copied from interface: `Lifecycle`
      Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementing `SmartLifecycle` and its `stop(Runnable)` variant in cases where asynchronous stop behavior is necessary.

      Should not throw an exception if the component isn't started yet.

      In the case of a container, this will propagate the stop signal to all components that apply.

      Specified by:
        `stop` in interface `Lifecycle`
      See Also:
        `SmartLifecycle.stop(Runnable)`

    - #### stop

          public final void stop(Runnable callback)

      Description copied from interface: `SmartLifecycle`
      Indicates that a Lifecycle component must stop if it is currently running.

      The provided callback is used by the `LifecycleProcessor` to support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after the SmartLifecycle component does indeed stop.

      The `LifecycleProcessor` will call only this variant of the `stop` method; i.e. `Lifecycle.stop()` will not be called for `SmartLifecycle` implementations unless explicitly delegated to within this method.

      Specified by:
        `stop` in interface `SmartLifecycle`

    - #### 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)`.

      Sub-classes should also take into account custom argument types configured via `AbstractMethodMessageHandler.setCustomArgumentResolvers(java.util.List)`.

      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)`.

      Sub-classes should also take into account custom return value types configured via `AbstractMethodMessageHandler.setCustomReturnValueHandlers(java.util.List)`.

      Specified by:
        `initReturnValueHandlers` 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

          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

    - #### 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

          protected String getDestination(Message<?> message)

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

    - #### getMatchingMapping

          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>`