public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler<SimpMessageMappingInfo> implements EmbeddedValueResolverAware, SmartLifecycle
@MessageMapping
and @SubscribeMapping
annotated methods.
Supports Ant-style path patterns with template variables.
logger
Constructor and Description |
---|
SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel,
MessageChannel clientOutboundChannel,
SimpMessageSendingOperations brokerTemplate)
Create an instance of SimpAnnotationMethodMessageHandler with the given
message channels and broker messaging template.
|
Modifier and Type | Method and Description |
---|---|
protected AbstractExceptionHandlerMethodResolver |
createExceptionHandlerMethodResolverFor(Class<?> beanType) |
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.
|
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 . |
PathMatcher |
getPathMatcher()
Return the PathMatcher implementation to use for matching destinations.
|
int |
getPhase()
Return the phase value of this object.
|
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.
|
boolean |
isAutoStartup()
Returns
true if this Lifecycle component should get
started automatically by the container at the time that the containing
ApplicationContext gets 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.
|
protected String[] |
resolveEmbeddedValuesInDestinations(String[] destinations)
Resolve placeholder values in the given array of destinations.
|
void |
setConversionService(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(StringValueResolver resolver)
Set the StringValueResolver to use for resolving embedded definition values.
|
void |
setHeaderInitializer(MessageHeaderInitializer headerInitializer)
Configure a
MessageHeaderInitializer to pass on to
HandlerMethodReturnValueHandler s
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(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.
|
afterPropertiesSet, createHandlerMethod, detectHandlerMethods, getApplicationContext, getArgumentResolvers, getCustomArgumentResolvers, getCustomReturnValueHandlers, getDestinationPrefixes, getExceptionHandlerMethod, getHandlerMethods, getReturnValueHandlers, handleMessage, handleMessageInternal, handleNoMatch, processHandlerMethodException, registerExceptionHandlerAdvice, registerHandlerMethod, setApplicationContext, setArgumentResolvers, setCustomArgumentResolvers, setCustomReturnValueHandlers, setReturnValueHandlers, toString
public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate)
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 brokerpublic void setDestinationPrefixes(@Nullable Collection<String> prefixes)
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
.
setDestinationPrefixes
in class AbstractMethodMessageHandler<SimpMessageMappingInfo>
public void setMessageConverter(MessageConverter converter)
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.CompositeMessageConverter
public MessageConverter getMessageConverter()
MessageConverter
.public void setConversionService(ConversionService conversionService)
ConversionService
to use when resolving method arguments,
for example message header values.
By default, DefaultFormattingConversionService
is used.
public ConversionService getConversionService()
ConversionService
.public void setPathMatcher(PathMatcher pathMatcher)
By default, AntPathMatcher
is used.
public PathMatcher getPathMatcher()
public void setValidator(@Nullable Validator validator)
@Payload
arguments.Validated
,
PayloadArgumentResolver
public void setEmbeddedValueResolver(StringValueResolver resolver)
EmbeddedValueResolverAware
setEmbeddedValueResolver
in interface EmbeddedValueResolverAware
public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer)
MessageHeaderInitializer
to pass on to
HandlerMethodReturnValueHandler
s
that send messages from controller return values.
By default, this property is not set.
@Nullable public MessageHeaderInitializer getHeaderInitializer()
public boolean isAutoStartup()
SmartLifecycle
true
if this Lifecycle
component should get
started automatically by the container at the time that the containing
ApplicationContext
gets refreshed.
A value of false
indicates that the component is intended to
be started through an explicit Lifecycle.start()
call instead, analogous
to a plain Lifecycle
implementation.
isAutoStartup
in interface SmartLifecycle
Lifecycle.start()
,
Phased.getPhase()
,
LifecycleProcessor.onRefresh()
,
ConfigurableApplicationContext.refresh()
public int getPhase()
Phased
public final void start()
Lifecycle
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.
start
in interface Lifecycle
SmartLifecycle.isAutoStartup()
public final void stop()
Lifecycle
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.
stop
in interface Lifecycle
SmartLifecycle.stop(Runnable)
,
DisposableBean.destroy()
public final void stop(Runnable callback)
SmartLifecycle
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.
stop
in interface SmartLifecycle
Lifecycle.stop()
,
Phased.getPhase()
public final boolean isRunning()
Lifecycle
In the case of a container, this will return true
only if all
components that apply are currently running.
protected List<HandlerMethodArgumentResolver> initArgumentResolvers()
AbstractMethodMessageHandler
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>)
.
initArgumentResolvers
in class AbstractMethodMessageHandler<SimpMessageMappingInfo>
protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers()
AbstractMethodMessageHandler
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>)
.
initReturnValueHandlers
in class AbstractMethodMessageHandler<SimpMessageMappingInfo>
protected boolean isHandler(Class<?> beanType)
AbstractMethodMessageHandler
isHandler
in class AbstractMethodMessageHandler<SimpMessageMappingInfo>
@Nullable protected SimpMessageMappingInfo getMappingForMethod(Method method, Class<?> handlerType)
AbstractMethodMessageHandler
getMappingForMethod
in class AbstractMethodMessageHandler<SimpMessageMappingInfo>
method
- the method to provide a mapping forhandlerType
- the handler type, possibly a sub-type of the method's declaring classnull
if the method is not mappedprotected String[] resolveEmbeddedValuesInDestinations(String[] destinations)
protected Set<String> getDirectLookupDestinations(SimpMessageMappingInfo mapping)
AbstractMethodMessageHandler
getDirectLookupDestinations
in class AbstractMethodMessageHandler<SimpMessageMappingInfo>
@Nullable protected String getDestination(Message<?> message)
getDestination
in class AbstractMethodMessageHandler<SimpMessageMappingInfo>
protected String getLookupDestination(@Nullable String destination)
AbstractMethodMessageHandler
If there are no matching prefixes, return null
.
If there are no destination prefixes, return the destination as is.
getLookupDestination
in class AbstractMethodMessageHandler<SimpMessageMappingInfo>
@Nullable protected SimpMessageMappingInfo getMatchingMapping(SimpMessageMappingInfo mapping, Message<?> message)
AbstractMethodMessageHandler
getMatchingMapping
in class AbstractMethodMessageHandler<SimpMessageMappingInfo>
mapping
- the mapping to get a match formessage
- the message being handlednull
if there is no matchprotected Comparator<SimpMessageMappingInfo> getMappingComparator(Message<?> message)
AbstractMethodMessageHandler
getMappingComparator
in class AbstractMethodMessageHandler<SimpMessageMappingInfo>
message
- the current Messagenull
protected void handleMatch(SimpMessageMappingInfo mapping, HandlerMethod handlerMethod, String lookupDestination, Message<?> message)
handleMatch
in class AbstractMethodMessageHandler<SimpMessageMappingInfo>
protected AbstractExceptionHandlerMethodResolver createExceptionHandlerMethodResolverFor(Class<?> beanType)
createExceptionHandlerMethodResolverFor
in class AbstractMethodMessageHandler<SimpMessageMappingInfo>