Class 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
@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
loggerFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionSimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate) Create an instance of SimpAnnotationMethodMessageHandler with the given message channels and broker messaging template. -
Method Summary
Modifier and TypeMethodDescriptionprotected AbstractExceptionHandlerMethodResolvercreateExceptionHandlerMethodResolverFor(Class<?> beanType) org.springframework.core.convert.ConversionServiceReturn the configuredConversionService.protected StringgetDestination(Message<?> message) Return destinations contained in the mapping that are not patterns and are therefore suitable for direct lookups.protected org.apache.commons.logging.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.org.springframework.util.PathMatcherReturn the PathMatcher implementation to use for matching destinations.protected org.apache.commons.logging.LogReturn a logger to set onHandlerMethodReturnValueHandlerComposite.org.springframework.validation.ValidatorReturn 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 booleanprotected String[]resolveEmbeddedValuesInDestinations(String[] destinations) Resolve placeholder values in the given array of destinations.voidsetConversionService(org.springframework.core.convert.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(org.springframework.util.StringValueResolver resolver) 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(org.springframework.util.PathMatcher pathMatcher) Set the PathMatcher implementation to use for matching destinations against configured destination patterns.voidsetValidator(org.springframework.validation.Validator validator) Set the Validator instance used for validating@Payloadarguments.final voidstart()final voidstop()final voidMethods 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, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
getPhase, isAutoStartup
-
Constructor Details
-
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 Details
-
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.- Overrides:
setDestinationPrefixesin classAbstractMethodMessageHandler<SimpMessageMappingInfo>
-
setMessageConverter
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. The converter is also used when sending a message to the message broker.- See Also:
-
getMessageConverter
Return the configuredMessageConverter. -
setConversionService
public void setConversionService(org.springframework.core.convert.ConversionService conversionService) Configure aConversionServiceto use when resolving method arguments, for example message header values.By default,
DefaultFormattingConversionServiceis used. -
getConversionService
public org.springframework.core.convert.ConversionService getConversionService()Return the configuredConversionService. -
setPathMatcher
public void setPathMatcher(org.springframework.util.PathMatcher pathMatcher) Set the PathMatcher implementation to use for matching destinations against configured destination patterns.By default,
AntPathMatcheris 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@Payloadarguments.- See Also:
-
ValidatedPayloadMethodArgumentResolver
-
setEmbeddedValueResolver
public void setEmbeddedValueResolver(org.springframework.util.StringValueResolver resolver) - Specified by:
setEmbeddedValueResolverin interfaceorg.springframework.context.EmbeddedValueResolverAware
-
setHeaderInitializer
Configure aMessageHeaderInitializerto pass on toHandlerMethodReturnValueHandlersthat send messages from controller return values.By default, this property is not set.
-
getHeaderInitializer
Return the configured header initializer. -
start
public final void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public final void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
stop
- Specified by:
stopin interfaceorg.springframework.context.SmartLifecycle
-
isRunning
public final boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
initArgumentResolvers
Description 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 classAbstractMethodMessageHandler<SimpMessageMappingInfo>
-
initReturnValueHandlers
Description 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 classAbstractMethodMessageHandler<SimpMessageMappingInfo>
-
getReturnValueHandlerLogger
protected org.apache.commons.logging.Log getReturnValueHandlerLogger()Description copied from class:AbstractMethodMessageHandlerReturn a logger to set onHandlerMethodReturnValueHandlerComposite.- Overrides:
getReturnValueHandlerLoggerin classAbstractMethodMessageHandler<SimpMessageMappingInfo>
-
getHandlerMethodLogger
protected org.apache.commons.logging.Log getHandlerMethodLogger()Description copied from class:AbstractMethodMessageHandlerReturn a logger to set onInvocableHandlerMethod.- Overrides:
getHandlerMethodLoggerin classAbstractMethodMessageHandler<SimpMessageMappingInfo>
-
isHandler
Description copied from class:AbstractMethodMessageHandlerWhether the given bean type should be introspected for messaging handling methods.- Specified by:
isHandlerin classAbstractMethodMessageHandler<SimpMessageMappingInfo>
-
getMappingForMethod
Description copied from class:AbstractMethodMessageHandlerProvide the mapping for a handler method.- Specified by:
getMappingForMethodin classAbstractMethodMessageHandler<SimpMessageMappingInfo>- Parameters:
method- the method to provide a mapping forhandlerType- the handler type, possibly a subtype of the method's declaring class- Returns:
- the mapping, or
nullif the method is not mapped
-
resolveEmbeddedValuesInDestinations
Resolve placeholder values in the given array of destinations.- Returns:
- a new array with updated destinations
- Since:
- 4.2
-
getDirectLookupDestinations
Description copied from class:AbstractMethodMessageHandlerReturn destinations contained in the mapping that are not patterns and are therefore suitable for direct lookups.- Specified by:
getDirectLookupDestinationsin classAbstractMethodMessageHandler<SimpMessageMappingInfo>
-
getDestination
- Specified by:
getDestinationin classAbstractMethodMessageHandler<SimpMessageMappingInfo>
-
getLookupDestination
Description 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 classAbstractMethodMessageHandler<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 classAbstractMethodMessageHandler<SimpMessageMappingInfo>- Parameters:
mapping- the mapping to get a match formessage- the message being handled- Returns:
- the match or
nullif there is no match
-
getMappingComparator
Description copied from class:AbstractMethodMessageHandlerReturn a comparator for sorting matching mappings. The returned comparator should sort 'better' matches higher.- Specified by:
getMappingComparatorin classAbstractMethodMessageHandler<SimpMessageMappingInfo>- Parameters:
message- the current Message- Returns:
- the comparator, never
null
-
handleMatch
protected void handleMatch(SimpMessageMappingInfo mapping, HandlerMethod handlerMethod, String lookupDestination, Message<?> message) - Overrides:
handleMatchin classAbstractMethodMessageHandler<SimpMessageMappingInfo>
-
createExceptionHandlerMethodResolverFor
protected AbstractExceptionHandlerMethodResolver createExceptionHandlerMethodResolverFor(Class<?> beanType) - Specified by:
createExceptionHandlerMethodResolverForin classAbstractMethodMessageHandler<SimpMessageMappingInfo>
-