Class SimpAnnotationMethodMessageHandler
- All Implemented Interfaces:
- Aware,- InitializingBean,- ApplicationContextAware,- EmbeddedValueResolverAware,- Lifecycle,- Phased,- SmartLifecycle,- MessageHandler
- Direct Known Subclasses:
- WebSocketAnnotationMethodMessageHandler
@MessageMapping
 and @SubscribeMapping annotated methods.
 Supports Ant-style path patterns with template variables.
- Since:
- 4.0
- Author:
- Rossen Stoyanchev, Brian Clozel, Juergen Hoeller
- 
Field SummaryFields inherited from class org.springframework.messaging.handler.invocation.AbstractMethodMessageHandlerloggerFields inherited from interface org.springframework.context.SmartLifecycleDEFAULT_PHASE
- 
Constructor SummaryConstructorsConstructorDescriptionSimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate) Create an instance of SimpAnnotationMethodMessageHandler with the given message channels and broker messaging template.
- 
Method SummaryModifier and TypeMethodDescriptionprotected AbstractExceptionHandlerMethodResolvercreateExceptionHandlerMethodResolverFor(Class<?> beanType) Return the configuredConversionService.protected StringgetDestination(Message<?> message) Return destinations contained in the mapping that are not patterns and are therefore suitable for direct lookups.protected LogReturn a logger to set onInvocableHandlerMethod.Return the configured header initializer.protected StringgetLookupDestination(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 SimpMessageMappingInfogetMappingForMethod(Method method, Class<?> handlerType) Provide the mapping for a handler method.protected SimpMessageMappingInfogetMatchingMapping(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.Return the configuredMessageConverter.Return the PathMatcher implementation to use for matching destinations.intgetPhase()Return the phase that this lifecycle object is supposed to run in.protected LogReturn a logger to set onHandlerMethodReturnValueHandlerComposite.Return the configured Validator instance.protected voidhandleMatch(SimpMessageMappingInfo mapping, HandlerMethod handlerMethod, String lookupDestination, Message<?> message) protected List<HandlerMethodArgumentResolver>Return the list of argument resolvers to use.protected List<? extends HandlerMethodReturnValueHandler>Return the list of return value handlers to use.protected booleanWhether the given bean type should be introspected for messaging handling methods.final booleanCheck whether this component is currently running.protected String[]resolveEmbeddedValuesInDestinations(String[] destinations) Resolve placeholder values in the given array of destinations.voidsetConversionService(ConversionService conversionService) Configure aConversionServiceto use when resolving method arguments, for example message header values.voidsetDestinationPrefixes(Collection<String> prefixes) When this property is configured only messages to destinations matching one of the configured prefixes are eligible for handling.voidsetEmbeddedValueResolver(StringValueResolver resolver) Set the StringValueResolver to use for resolving embedded definition values.voidsetHeaderInitializer(MessageHeaderInitializer headerInitializer) Configure aMessageHeaderInitializerto pass on toHandlerMethodReturnValueHandlersthat send messages from controller return values.voidsetMessageConverter(MessageConverter converter) Configure aMessageConverterto 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.voidsetPathMatcher(PathMatcher pathMatcher) Set the PathMatcher implementation to use for matching destinations against configured destination patterns.voidsetPhase(int phase) Set the phase that this handler should run in.voidsetValidator(Validator validator) Set the Validator instance used for validating@Payloadarguments.final voidstart()Start this component.final voidstop()Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.final voidIndicates that a Lifecycle component must stop if it is currently running.Methods inherited from class org.springframework.messaging.handler.invocation.AbstractMethodMessageHandlerafterPropertiesSet, createHandlerMethod, detectHandlerMethods, getApplicationContext, getArgumentResolvers, getCustomArgumentResolvers, getCustomReturnValueHandlers, getDestinationPrefixes, getExceptionHandlerMethod, getHandlerMethods, getReturnValueHandlers, handleMessage, handleMessageInternal, handleNoMatch, processHandlerMethodException, registerExceptionHandlerAdvice, registerHandlerMethod, setApplicationContext, setArgumentResolvers, setCustomArgumentResolvers, setCustomReturnValueHandlers, setReturnValueHandlers, toStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycleisAutoStartup
- 
Constructor Details- 
SimpAnnotationMethodMessageHandlerpublic 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 Details- 
setDestinationPrefixesWhen 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:
- setDestinationPrefixesin class- AbstractMethodMessageHandler<SimpMessageMappingInfo>
 
- 
setMessageConverterConfigure aMessageConverterto 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:
 
- 
getMessageConverterReturn the configuredMessageConverter.
- 
setConversionServiceConfigure aConversionServiceto use when resolving method arguments, for example message header values.By default, DefaultFormattingConversionServiceis used.
- 
getConversionServiceReturn the configuredConversionService.
- 
setPathMatcherSet the PathMatcher implementation to use for matching destinations against configured destination patterns.By default, AntPathMatcheris used.
- 
getPathMatcherReturn the PathMatcher implementation to use for matching destinations.
- 
getValidatorReturn the configured Validator instance.
- 
setValidatorSet the Validator instance used for validating@Payloadarguments.- See Also:
 
- 
setEmbeddedValueResolverDescription copied from interface:EmbeddedValueResolverAwareSet the StringValueResolver to use for resolving embedded definition values.- Specified by:
- setEmbeddedValueResolverin interface- EmbeddedValueResolverAware
 
- 
setHeaderInitializerConfigure aMessageHeaderInitializerto pass on toHandlerMethodReturnValueHandlersthat send messages from controller return values.By default, this property is not set. 
- 
getHeaderInitializerReturn the configured header initializer.
- 
setPhasepublic void setPhase(int phase) Set the phase that this handler should run in.By default, this is SmartLifecycle.DEFAULT_PHASE.- Since:
- 6.1.4
 
- 
getPhasepublic int getPhase()Description copied from interface:SmartLifecycleReturn the phase that this lifecycle object is supposed to run in.The default implementation returns SmartLifecycle.DEFAULT_PHASEin order to letstop()callbacks execute before regularLifecycleimplementations.- Specified by:
- getPhasein interface- Phased
- Specified by:
- getPhasein interface- SmartLifecycle
- See Also:
 
- 
startpublic final void start()Description copied from interface:LifecycleStart 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. 
- 
stoppublic final void stop()Description copied from interface:LifecycleStop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycleand itsstop(Runnable)variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown, Lifecyclebeans 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. 
- 
stopDescription copied from interface:SmartLifecycleIndicates that a Lifecycle component must stop if it is currently running.The provided callback is used by the LifecycleProcessorto support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after theSmartLifecyclecomponent does indeed stop.The LifecycleProcessorwill call only this variant of thestopmethod; i.e.Lifecycle.stop()will not be called forSmartLifecycleimplementations unless explicitly delegated to within the implementation of this method.The default implementation delegates to Lifecycle.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).- Specified by:
- stopin interface- SmartLifecycle
- See Also:
 
- 
isRunningpublic final boolean isRunning()Description copied from interface:LifecycleCheck whether this component is currently running.In the case of a container, this will return trueonly if all components that apply are currently running.
- 
initArgumentResolversDescription copied from class:AbstractMethodMessageHandlerReturn the list of argument resolvers to use. Invoked only if the resolvers have not already been set viaAbstractMethodMessageHandler.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:
- initArgumentResolversin class- AbstractMethodMessageHandler<SimpMessageMappingInfo>
 
- 
initReturnValueHandlersDescription copied from class:AbstractMethodMessageHandlerReturn the list of return value handlers to use. Invoked only if the return value handlers have not already been set viaAbstractMethodMessageHandler.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:
- initReturnValueHandlersin class- AbstractMethodMessageHandler<SimpMessageMappingInfo>
 
- 
getReturnValueHandlerLoggerDescription copied from class:AbstractMethodMessageHandlerReturn a logger to set onHandlerMethodReturnValueHandlerComposite.- Overrides:
- getReturnValueHandlerLoggerin class- AbstractMethodMessageHandler<SimpMessageMappingInfo>
 
- 
getHandlerMethodLoggerDescription copied from class:AbstractMethodMessageHandlerReturn a logger to set onInvocableHandlerMethod.- Overrides:
- getHandlerMethodLoggerin class- AbstractMethodMessageHandler<SimpMessageMappingInfo>
 
- 
isHandlerDescription copied from class:AbstractMethodMessageHandlerWhether the given bean type should be introspected for messaging handling methods.- Specified by:
- isHandlerin class- AbstractMethodMessageHandler<SimpMessageMappingInfo>
 
- 
getMappingForMethodDescription copied from class:AbstractMethodMessageHandlerProvide the mapping for a handler method.- Specified by:
- getMappingForMethodin class- AbstractMethodMessageHandler<SimpMessageMappingInfo>
- Parameters:
- method- the method to provide a mapping for
- handlerType- the handler type, possibly a subtype of the method's declaring class
- Returns:
- the mapping, or nullif the method is not mapped
 
- 
resolveEmbeddedValuesInDestinationsResolve placeholder values in the given array of destinations.- Returns:
- a new array with updated destinations
- Since:
- 4.2
 
- 
getDirectLookupDestinationsDescription copied from class:AbstractMethodMessageHandlerReturn destinations contained in the mapping that are not patterns and are therefore suitable for direct lookups.- Specified by:
- getDirectLookupDestinationsin class- AbstractMethodMessageHandler<SimpMessageMappingInfo>
 
- 
getDestination- Specified by:
- getDestinationin class- AbstractMethodMessageHandler<SimpMessageMappingInfo>
 
- 
getLookupDestinationDescription copied from class:AbstractMethodMessageHandlerCheck 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:
- getLookupDestinationin class- AbstractMethodMessageHandler<SimpMessageMappingInfo>
 
- 
getMatchingMapping@Nullable protected SimpMessageMappingInfo getMatchingMapping(SimpMessageMappingInfo mapping, Message<?> message) Description copied from class:AbstractMethodMessageHandlerCheck if a mapping matches the current message and return a possibly new mapping with conditions relevant to the current request.- Specified by:
- getMatchingMappingin class- AbstractMethodMessageHandler<SimpMessageMappingInfo>
- Parameters:
- mapping- the mapping to get a match for
- message- the message being handled
- Returns:
- the match or nullif there is no match
 
- 
getMappingComparatorDescription copied from class:AbstractMethodMessageHandlerReturn a comparator for sorting matching mappings. The returned comparator should sort 'better' matches higher.- Specified by:
- getMappingComparatorin class- AbstractMethodMessageHandler<SimpMessageMappingInfo>
- Parameters:
- message- the current Message
- Returns:
- the comparator, never null
 
- 
handleMatchprotected void handleMatch(SimpMessageMappingInfo mapping, HandlerMethod handlerMethod, String lookupDestination, Message<?> message) - Overrides:
- handleMatchin class- AbstractMethodMessageHandler<SimpMessageMappingInfo>
 
- 
createExceptionHandlerMethodResolverForprotected AbstractExceptionHandlerMethodResolver createExceptionHandlerMethodResolverFor(Class<?> beanType) - Specified by:
- createExceptionHandlerMethodResolverForin class- AbstractMethodMessageHandler<SimpMessageMappingInfo>
 
 
-