Top Description Fields Constructors Methods
org.springframework.messaging.simp.annotation.support

public Class SimpAnnotationMethodMessageHandler

extends AbstractMethodMessageHandler<SimpMessageMappingInfo>
implements EmbeddedValueResolverAware, SmartLifecycle
Class Inheritance
All Implemented Interfaces
org.springframework.context.SmartLifecycle, org.springframework.context.Phased, org.springframework.context.Lifecycle, org.springframework.context.EmbeddedValueResolverAware, org.springframework.beans.factory.Aware
Imports
java.lang.reflect.Method, java.util.ArrayList, .Collection, .Comparator, .LinkedHashSet, .List, .Map, .Set, org.apache.commons.logging.Log, org.springframework.beans.factory.config.ConfigurableBeanFactory, org.springframework.context.ApplicationContext, .ConfigurableApplicationContext, .EmbeddedValueResolverAware, .SmartLifecycle, org.springframework.core.annotation.AnnotatedElementUtils, org.springframework.core.convert.ConversionService, org.springframework.format.support.DefaultFormattingConversionService, org.springframework.lang.Nullable, org.springframework.messaging.Message, .MessageChannel, .SubscribableChannel, org.springframework.messaging.converter.ByteArrayMessageConverter, .CompositeMessageConverter, .MessageConverter, .StringMessageConverter, org.springframework.messaging.core.AbstractMessageSendingTemplate, org.springframework.messaging.handler.DestinationPatternsMessageCondition, .HandlerMethod, org.springframework.messaging.handler.annotation.MessageMapping, org.springframework.messaging.handler.annotation.support.AnnotationExceptionHandlerMethodResolver, .DestinationVariableMethodArgumentResolver, .HeaderMethodArgumentResolver, .HeadersMethodArgumentResolver, .MessageMethodArgumentResolver, .PayloadMethodArgumentResolver, org.springframework.messaging.handler.invocation.AbstractExceptionHandlerMethodResolver, .AbstractMethodMessageHandler, .CompletableFutureReturnValueHandler, .HandlerMethodArgumentResolver, .HandlerMethodReturnValueHandler, .HandlerMethodReturnValueHandlerComposite, .ReactiveReturnValueHandler, org.springframework.messaging.simp.SimpAttributesContextHolder, .SimpLogging, .SimpMessageHeaderAccessor, .SimpMessageMappingInfo, .SimpMessageSendingOperations, .SimpMessageTypeMessageCondition, .SimpMessagingTemplate, org.springframework.messaging.simp.annotation.SubscribeMapping, org.springframework.messaging.support.MessageHeaderAccessor, .MessageHeaderInitializer, org.springframework.stereotype.Controller, org.springframework.util.AntPathMatcher, .Assert, .ClassUtils, .CollectionUtils, .PathMatcher, .StringValueResolver, org.springframework.validation.Validator

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

Supports Ant-style path patterns with template variables.

Authors
Rossen Stoyanchev, Brian Clozel, Juergen Hoeller
Since
4.0

Field Summary

Modifier and TypeField and Description
private final SimpMessageSendingOperations
private final SubscribableChannel
private final SimpMessageSendingOperations
private ConversionService
private MessageHeaderInitializer
private final Object
private MessageConverter
private PathMatcher
private Integer
private static final boolean
private volatile boolean
private boolean
private Validator
private StringValueResolver
Inherited from org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler:
logger

Constructor Summary

AccessConstructor and Description
public
SimpAnnotationMethodMessageHandler(SubscribableChannel
the channel for receiving messages from clients (e.g. WebSocket clients)
clientInboundChannel
,
MessageChannel
the channel for messages to clients (e.g. WebSocket clients)
clientOutboundChannel
,
SimpMessageSendingOperations
a messaging template to send application messages to the broker
brokerTemplate
)

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

Method Summary

Modifier and TypeMethod and Description
private static Collection<String>
protected AbstractExceptionHandlerMethodResolver
private SimpMessageMappingInfo
private SimpMessageMappingInfo
public ConversionService
getConversionService()

Return the configured ConversionService.

protected String
protected Set<String>
getDirectLookupDestinations(SimpMessageMappingInfo mapping)

Implements abstract org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getDirectLookupDestinations.

Return destinations contained in the mapping that are not patterns and are therefore suitable for direct lookups.

protected Log
public MessageHeaderInitializer
getHeaderInitializer()

Return the configured header initializer.

protected String
getLookupDestination(String destination)

Overrides org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getLookupDestination.

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(final Message<?>
the current Message
message
)

Implements abstract org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getMappingComparator.

Return a comparator for sorting matching mappings.

protected SimpMessageMappingInfo
getMappingForMethod(Method
the method to provide a mapping for
method
,
Class<?>
the handler type, possibly a subtype of the method's declaring class
handlerType
)

Implements abstract org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getMappingForMethod.

Provide the mapping for a handler method.

protected SimpMessageMappingInfo
getMatchingMapping(SimpMessageMappingInfo
the mapping to get a match for
mapping
,
Message<?>
the message being handled
message
)

Implements abstract org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getMatchingMapping.

Check if a mapping matches the current message and return a possibly new mapping with conditions relevant to the current request.

public MessageConverter
getMessageConverter()

Return the configured MessageConverter.

public PathMatcher
getPathMatcher()

Return the PathMatcher implementation to use for matching destinations.

public int
getPhase()

Overrides default org.springframework.context.SmartLifecycle.getPhase.

Return the phase that this lifecycle object is supposed to run in.

The default implementation returns DEFAULT_PHASE in order to let stop() callbacks execute before regular Lifecycle implementations.

protected Log
public Validator
getValidator()

Return the configured Validator instance.

protected void
protected List<HandlerMethodArgumentResolver>
protected List<? extends HandlerMethodReturnValueHandler>
protected boolean
isHandler(Class<?> beanType)

Implements abstract org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.isHandler.

Whether the given bean type should be introspected for messaging handling methods.

public final boolean
isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Check whether this component is currently running.

protected String[]

Returns:

a new array with updated destinations
resolveEmbeddedValuesInDestinations
(String[] destinations)

Resolve placeholder values in the given array of destinations.

public void
setConversionService(ConversionService conversionService)

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

public void
setDestinationPrefixes(Collection<String> prefixes)

Overrides org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.setDestinationPrefixes.

When this property is configured only messages to destinations matching one of the configured prefixes are eligible for handling.

public void
setEmbeddedValueResolver(StringValueResolver resolver)

Implements org.springframework.context.EmbeddedValueResolverAware.setEmbeddedValueResolver.

Set the StringValueResolver to use for resolving embedded definition values.

public void
setHeaderInitializer(MessageHeaderInitializer headerInitializer)

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

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.

public void
setPathMatcher(PathMatcher pathMatcher)

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

public void
setPhase(int phase)

Set the phase that this handler should run in.

By default, this is SmartLifecycle#DEFAULT_PHASE.

public void
setValidator(Validator validator)

Set the Validator instance used for validating @Payload arguments.

public final void
start()

Implements org.springframework.context.Lifecycle.start.

Start this component.

public final void
stop()

Implements org.springframework.context.Lifecycle.stop.

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.

public final void
stop(Runnable callback)

Overrides default org.springframework.context.SmartLifecycle.stop.

Indicates that a Lifecycle component must stop if it is currently running.

Inherited from org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler:
afterPropertiesSetcreateHandlerMethoddetectHandlerMethodsgetApplicationContextgetArgumentResolversgetCustomArgumentResolversgetCustomReturnValueHandlersgetDestinationPrefixesgetExceptionHandlerMethodgetHandlerMethodsgetReturnValueHandlershandleMessagehandleMessageInternalhandleNoMatchprocessHandlerMethodExceptionregisterExceptionHandlerAdviceregisterHandlerMethodsetApplicationContextsetArgumentResolverssetCustomArgumentResolverssetCustomReturnValueHandlerssetReturnValueHandlerstoString

Field Detail

brokerTemplateback to summary
private final SimpMessageSendingOperations brokerTemplate
clientInboundChannelback to summary
private final SubscribableChannel clientInboundChannel
clientMessagingTemplateback to summary
private final SimpMessageSendingOperations clientMessagingTemplate
conversionServiceback to summary
private ConversionService conversionService
headerInitializerback to summary
private MessageHeaderInitializer headerInitializer
Annotations
@Nullable
lifecycleMonitorback to summary
private final Object lifecycleMonitor
messageConverterback to summary
private MessageConverter messageConverter
pathMatcherback to summary
private PathMatcher pathMatcher
phaseback to summary
private Integer phase
Annotations
@Nullable
reactorPresentback to summary
private static final boolean reactorPresent
runningback to summary
private volatile boolean running
slashPathSeparatorback to summary
private boolean slashPathSeparator
validatorback to summary
private Validator validator
Annotations
@Nullable
valueResolverback to summary
private StringValueResolver valueResolver
Annotations
@Nullable

Constructor Detail

SimpAnnotationMethodMessageHandlerback to summary
public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate)

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

Parameters
clientInboundChannel:SubscribableChannel

the channel for receiving messages from clients (e.g. WebSocket clients)

clientOutboundChannel:MessageChannel

the channel for messages to clients (e.g. WebSocket clients)

brokerTemplate:SimpMessageSendingOperations

a messaging template to send application messages to the broker

Method Detail

appendSlashesback to summary
private static Collection<String> appendSlashes(Collection<String> prefixes)
Annotations
@Nullable
createExceptionHandlerMethodResolverForback to summary
protected AbstractExceptionHandlerMethodResolver createExceptionHandlerMethodResolverFor(Class<?> beanType)

Implements abstract org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.createExceptionHandlerMethodResolverFor.

Annotations
@Override
createMessageMappingConditionback to summary
private SimpMessageMappingInfo createMessageMappingCondition(String[] destinations)
createSubscribeMappingConditionback to summary
private SimpMessageMappingInfo createSubscribeMappingCondition(String[] destinations)
getConversionServiceback to summary
public ConversionService getConversionService()

Return the configured ConversionService.

getDestinationback to summary
protected String getDestination(Message<?> message)

Implements abstract org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getDestination.

Annotations
@Override
@Nullable
getDirectLookupDestinationsback to summary
protected Set<String> getDirectLookupDestinations(SimpMessageMappingInfo mapping)

Implements abstract org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getDirectLookupDestinations.

Doc from org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getDirectLookupDestinations.

Return destinations contained in the mapping that are not patterns and are therefore suitable for direct lookups.

Annotations
@Override
getHandlerMethodLoggerback to summary
protected Log getHandlerMethodLogger()

Overrides org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getHandlerMethodLogger.

Doc from org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getHandlerMethodLogger.

Return a logger to set on InvocableHandlerMethod.

Annotations
@Override
getHeaderInitializerback to summary
public MessageHeaderInitializer getHeaderInitializer()

Return the configured header initializer.

Annotations
@Nullable
getLookupDestinationback to summary
protected String getLookupDestination(String destination)

Overrides org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getLookupDestination.

Doc from org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getLookupDestination.

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.

Annotations
@Override
getMappingComparatorback to summary
protected Comparator<SimpMessageMappingInfo> getMappingComparator(final Message<?> message)

Implements abstract org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getMappingComparator.

Doc from org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getMappingComparator.

Return a comparator for sorting matching mappings. The returned comparator should sort 'better' matches higher.

Parameters
message:Message<?>

the current Message

Returns:Comparator<SimpMessageMappingInfo>

the comparator, never null

Annotations
@Override
getMappingForMethodback to summary
protected SimpMessageMappingInfo getMappingForMethod(Method method, Class<?> handlerType)

Implements abstract org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getMappingForMethod.

Doc from org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getMappingForMethod.

Provide the mapping for a handler method.

Parameters
method:Method

the method to provide a mapping for

handlerType:Class<?>

the handler type, possibly a subtype of the method's declaring class

Returns:SimpMessageMappingInfo

the mapping, or null if the method is not mapped

Annotations
@Override
@Nullable
getMatchingMappingback to summary
protected SimpMessageMappingInfo getMatchingMapping(SimpMessageMappingInfo mapping, Message<?> message)

Implements abstract org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getMatchingMapping.

Doc from org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getMatchingMapping.

Check if a mapping matches the current message and return a possibly new mapping with conditions relevant to the current request.

Parameters
mapping:SimpMessageMappingInfo

the mapping to get a match for

message:Message<?>

the message being handled

Returns:SimpMessageMappingInfo

the match or null if there is no match

Annotations
@Override
@Nullable
getMessageConverterback to summary
public MessageConverter getMessageConverter()

Return the configured MessageConverter.

getPathMatcherback to summary
public PathMatcher getPathMatcher()

Return the PathMatcher implementation to use for matching destinations.

getPhaseback to summary
public int getPhase()

Overrides default org.springframework.context.SmartLifecycle.getPhase.

Doc from org.springframework.context.SmartLifecycle.getPhase.

Return the phase that this lifecycle object is supposed to run in.

The default implementation returns DEFAULT_PHASE in order to let stop() callbacks execute before regular Lifecycle implementations.

Annotations
@Override
getReturnValueHandlerLoggerback to summary
protected Log getReturnValueHandlerLogger()

Overrides org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getReturnValueHandlerLogger.

Doc from org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.getReturnValueHandlerLogger.

Return a logger to set on HandlerMethodReturnValueHandlerComposite.

Annotations
@Override
getValidatorback to summary
public Validator getValidator()

Return the configured Validator instance.

Annotations
@Nullable
handleMatchback to summary
protected void handleMatch(SimpMessageMappingInfo mapping, HandlerMethod handlerMethod, String lookupDestination, Message<?> message)

Overrides org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMatch.

Annotations
@Override
initArgumentResolversback to summary
protected List<HandlerMethodArgumentResolver> initArgumentResolvers()

Implements abstract org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.initArgumentResolvers.

Doc from org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.initArgumentResolvers.

Return the list of argument resolvers to use. Invoked only if the resolvers have not already been set via setArgumentResolvers.

Subclasses should also take into account custom argument types configured via setCustomArgumentResolvers.

Annotations
@Override
initReturnValueHandlersback to summary
protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers()

Implements abstract org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.initReturnValueHandlers.

Doc from org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.initReturnValueHandlers.

Return the list of return value handlers to use. Invoked only if the return value handlers have not already been set via setReturnValueHandlers.

Subclasses should also take into account custom return value types configured via setCustomReturnValueHandlers.

Annotations
@Override
@SuppressWarnings:deprecation
isHandlerback to summary
protected boolean isHandler(Class<?> beanType)

Implements abstract org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.isHandler.

Doc from org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.isHandler.

Whether the given bean type should be introspected for messaging handling methods.

Annotations
@Override
isRunningback to summary
public final boolean isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Doc from org.springframework.context.Lifecycle.isRunning.

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.

Returns:boolean

whether the component is currently running

Annotations
@Override
resolveEmbeddedValuesInDestinationsback to summary
protected String[] resolveEmbeddedValuesInDestinations(String[] destinations)

Resolve placeholder values in the given array of destinations.

Returns:String[]

a new array with updated destinations

Since
4.2
setConversionServiceback to summary
public void setConversionService(ConversionService conversionService)

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

By default, DefaultFormattingConversionService is used.

setDestinationPrefixesback to summary
public void setDestinationPrefixes(Collection<String> prefixes)

Overrides org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.setDestinationPrefixes.

Doc from org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.setDestinationPrefixes.

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.

Annotations
@Override
setEmbeddedValueResolverback to summary
public void setEmbeddedValueResolver(StringValueResolver resolver)

Implements org.springframework.context.EmbeddedValueResolverAware.setEmbeddedValueResolver.

Doc from org.springframework.context.EmbeddedValueResolverAware.setEmbeddedValueResolver.

Set the StringValueResolver to use for resolving embedded definition values.

Annotations
@Override
setHeaderInitializerback to summary
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer)

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

By default, this property is not set.

setMessageConverterback to summary
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
setPathMatcherback to summary
public void setPathMatcher(PathMatcher pathMatcher)

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

By default, AntPathMatcher is used.

setPhaseback to summary
public void setPhase(int phase)

Set the phase that this handler should run in.

By default, this is SmartLifecycle#DEFAULT_PHASE.

Since
6.1.4
setValidatorback to summary
public void setValidator(Validator validator)

Set the Validator instance used for validating @Payload arguments.

See Also
org.springframework.validation.annotation.Validated, PayloadMethodArgumentResolver
startback to summary
public final void start()

Implements org.springframework.context.Lifecycle.start.

Doc from org.springframework.context.Lifecycle.start.

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.

Annotations
@Override
stopback to summary
public final void stop()

Implements org.springframework.context.Lifecycle.stop.

Doc from org.springframework.context.Lifecycle.stop.

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 when asynchronous stop behavior is necessary.

Note that this stop notification is not guaranteed to come before destruction: On regular shutdown, Lifecycle beans will first receive a stop notification before the general destruction callbacks are being propagated; however, on hot refresh during a context's lifetime or on aborted refresh attempts, a given bean's destroy method will be called without any consideration of stop signals upfront.

Should not throw an exception if the component is not running (not started yet).

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

Annotations
@Override
stopback to summary
public final void stop(Runnable callback)

Overrides default org.springframework.context.SmartLifecycle.stop.

Doc from org.springframework.context.SmartLifecycle.stop.

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 the implementation of this method.

The default implementation delegates to stop() and immediately triggers the given callback in the calling thread. Note that there is no synchronization between the two, so custom implementations may at least want to put the same steps within their common lifecycle monitor (if any).

Annotations
@Override