public class MessageMappingMessageHandler extends AbstractMethodMessageHandler<CompositeMessageCondition> implements EmbeddedValueResolverAware
AbstractMethodMessageHandler for reactive, non-blocking
handling of messages via @MessageMapping methods.
By default such methods are detected in @Controller Spring beans but
that can be changed via AbstractMethodMessageHandler.setHandlerPredicate(Predicate).
Payloads for incoming messages are decoded through the configured
setDecoders(List) decoders, with the help of
PayloadMethodArgumentResolver.
There is no default handling for return values but
AbstractMethodMessageHandler.setReturnValueHandlerConfigurer(org.springframework.messaging.handler.invocation.reactive.ReturnValueHandlerConfigurer) can be used to configure custom
return value handlers. Sub-classes may also override
initReturnValueHandlers() to set up default return value handlers.
AbstractEncoderMethodReturnValueHandlerlogger| Constructor and Description |
|---|
MessageMappingMessageHandler() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet()
Invoked by the containing
BeanFactory after it has set all bean properties
and satisfied BeanFactoryAware, ApplicationContextAware etc. |
protected AbstractExceptionHandlerMethodResolver |
createExceptionMethodResolverFor(Class<?> beanType)
Create a concrete instance of
AbstractExceptionHandlerMethodResolver
that finds exception handling methods based on some criteria, e.g. |
protected CompositeMessageCondition |
getCondition(AnnotatedElement element)
Determine the mapping condition for the given annotated element.
|
ConversionService |
getConversionService()
Return the configured ConversionService.
|
List<? extends Decoder<?>> |
getDecoders()
Return the configured decoders.
|
protected RouteMatcher.Route |
getDestination(Message<?> message)
Extract the destination from the given message.
|
protected Set<String> |
getDirectLookupMappings(CompositeMessageCondition mapping)
Return String-based destinations for the given mapping, if any, that can
be used to find matches with a direct lookup (i.e.
|
protected Comparator<CompositeMessageCondition> |
getMappingComparator(Message<?> message)
Return a comparator for sorting matching mappings.
|
protected CompositeMessageCondition |
getMappingForMethod(Method method,
Class<?> handlerType)
Obtain the mapping for the given method, if any.
|
protected CompositeMessageCondition |
getMatchingMapping(CompositeMessageCondition mapping,
Message<?> message)
Check if a mapping matches the current message and return a possibly
new mapping with conditions relevant to the current request.
|
RouteMatcher |
getRouteMatcher()
Return the
RouteMatcher used to map messages to handlers. |
Validator |
getValidator()
Return the configured Validator instance.
|
protected reactor.core.publisher.Mono<Void> |
handleMatch(CompositeMessageCondition mapping,
HandlerMethod handlerMethod,
Message<?> message) |
protected List<? extends HandlerMethodArgumentResolver> |
initArgumentResolvers()
Return the list of argument resolvers to use.
|
protected List<? extends HandlerMethodReturnValueHandler> |
initReturnValueHandlers()
Return the list of return value handlers to use.
|
protected RouteMatcher |
obtainRouteMatcher()
Obtain the
RouteMatcher for actual use. |
protected String[] |
processDestinations(String[] destinations)
Resolve placeholders in the given destinations.
|
void |
registerMessagingAdvice(MessagingAdviceBean bean)
Use this method to register a
MessagingAdviceBean that may contain
globally applicable
@MessageExceptionHandler
methods. |
void |
setConversionService(ConversionService conversionService)
Configure a
ConversionService to use for type conversion of
String based values, e.g. |
void |
setDecoders(List<? extends Decoder<?>> decoders)
Configure the decoders to use for incoming payloads.
|
void |
setEmbeddedValueResolver(StringValueResolver resolver)
Set the StringValueResolver to use for resolving embedded definition values.
|
void |
setRouteMatcher(RouteMatcher routeMatcher)
Set the
RouteMatcher to use for mapping messages to handlers
based on the route patterns they're configured with. |
void |
setValidator(Validator validator)
Set the Validator instance used for validating
@Payload arguments. |
detectHandlerMethods, extendMapping, getApplicationContext, getArgumentResolverConfigurer, getArgumentResolvers, getBeanName, getDestinationLookup, getHandlerMethods, getHandlerPredicate, getReactiveAdapterRegistry, getReturnValueHandlerConfigurer, handleMessage, handleNoMatch, registerExceptionHandlerAdvice, registerHandlerMethod, setApplicationContext, setArgumentResolverConfigurer, setBeanName, setHandlerPredicate, setHandlers, setReactiveAdapterRegistry, setReturnValueHandlerConfigurerpublic void setDecoders(List<? extends Decoder<?>> decoders)
public void setValidator(@Nullable Validator validator)
@Payload arguments.Validated,
PayloadMethodArgumentResolverpublic void setRouteMatcher(@Nullable RouteMatcher routeMatcher)
RouteMatcher to use for mapping messages to handlers
based on the route patterns they're configured with.
By default, SimpleRouteMatcher is used, backed by
AntPathMatcher with "." as separator. For greater
efficiency consider using the PathPatternRouteMatcher from
spring-web instead.
@Nullable public RouteMatcher getRouteMatcher()
RouteMatcher used to map messages to handlers.
May be null before the component is initialized.protected RouteMatcher obtainRouteMatcher()
RouteMatcher for actual use.null)IllegalStateException - in case of no RouteMatcher setpublic void setConversionService(ConversionService conversionService)
ConversionService to use for type conversion of
String based values, e.g. in destination variables or headers.
By default DefaultFormattingConversionService is used.
conversionService - the conversion service to usepublic ConversionService getConversionService()
public void setEmbeddedValueResolver(StringValueResolver resolver)
EmbeddedValueResolverAwaresetEmbeddedValueResolver in interface EmbeddedValueResolverAwarepublic void registerMessagingAdvice(MessagingAdviceBean bean)
MessagingAdviceBean that may contain
globally applicable
@MessageExceptionHandler
methods.
Note: spring-messaging does not depend on spring-web and therefore it
is not possible to explicitly support the registration of a
@ControllerAdvice bean. You can use the following adapter code
to register @ControllerAdvice beans here:
ControllerAdviceBean.findAnnotatedBeans(context).forEach(bean ->
messageHandler.registerMessagingAdvice(new ControllerAdviceWrapper(bean));
public class ControllerAdviceWrapper implements MessagingAdviceBean {
private final ControllerAdviceBean delegate;
// delegate all methods
}
bean - the bean to check for @MessageExceptionHandler methodspublic void afterPropertiesSet()
InitializingBeanBeanFactory after it has set all bean properties
and satisfied BeanFactoryAware, ApplicationContextAware etc.
This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
afterPropertiesSet in interface InitializingBeanafterPropertiesSet in class AbstractMethodMessageHandler<CompositeMessageCondition>protected List<? extends HandlerMethodArgumentResolver> initArgumentResolvers()
AbstractMethodMessageHandlerSubclasses should also take into account custom argument types configured via
AbstractMethodMessageHandler.setArgumentResolverConfigurer(org.springframework.messaging.handler.invocation.reactive.ArgumentResolverConfigurer).
initArgumentResolvers in class AbstractMethodMessageHandler<CompositeMessageCondition>protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers()
AbstractMethodMessageHandlerSubclasses should also take into account custom return value types configured
via AbstractMethodMessageHandler.setReturnValueHandlerConfigurer(org.springframework.messaging.handler.invocation.reactive.ReturnValueHandlerConfigurer).
initReturnValueHandlers in class AbstractMethodMessageHandler<CompositeMessageCondition>protected CompositeMessageCondition getMappingForMethod(Method method, Class<?> handlerType)
AbstractMethodMessageHandlergetMappingForMethod in class AbstractMethodMessageHandler<CompositeMessageCondition>method - the method to checkhandlerType - the handler type, possibly a sub-type of the method's declaring classnull if the method is not mapped@Nullable protected CompositeMessageCondition getCondition(AnnotatedElement element)
element - the element to checknullprotected String[] processDestinations(String[] destinations)
destinations - the destinationsprotected Set<String> getDirectLookupMappings(CompositeMessageCondition mapping)
AbstractMethodMessageHandlerNote: This is completely optional. The mapping metadata for a subclass may support neither direct lookups, nor String based destinations.
getDirectLookupMappings in class AbstractMethodMessageHandler<CompositeMessageCondition>protected RouteMatcher.Route getDestination(Message<?> message)
AbstractMethodMessageHandlergetDestination in class AbstractMethodMessageHandler<CompositeMessageCondition>AbstractMethodMessageHandler.getDirectLookupMappings(Object)protected CompositeMessageCondition getMatchingMapping(CompositeMessageCondition mapping, Message<?> message)
AbstractMethodMessageHandlergetMatchingMapping in class AbstractMethodMessageHandler<CompositeMessageCondition>mapping - the mapping to get a match formessage - the message being handlednull if there is no matchprotected Comparator<CompositeMessageCondition> getMappingComparator(Message<?> message)
AbstractMethodMessageHandlergetMappingComparator in class AbstractMethodMessageHandler<CompositeMessageCondition>message - the current Messagenullprotected AbstractExceptionHandlerMethodResolver createExceptionMethodResolverFor(Class<?> beanType)
AbstractMethodMessageHandlerAbstractExceptionHandlerMethodResolver
that finds exception handling methods based on some criteria, e.g. based
on the presence of @MessageExceptionHandler.createExceptionMethodResolverFor in class AbstractMethodMessageHandler<CompositeMessageCondition>beanType - the class in which an exception occurred during handlingprotected reactor.core.publisher.Mono<Void> handleMatch(CompositeMessageCondition mapping, HandlerMethod handlerMethod, Message<?> message)
handleMatch in class AbstractMethodMessageHandler<CompositeMessageCondition>