Class AbstractMethodMessageHandler<T>
- Type Parameters:
- T- the type of the Object that contains information mapping information
- All Implemented Interfaces:
- Aware,- BeanNameAware,- InitializingBean,- ApplicationContextAware,- ReactiveMessageHandler
- Direct Known Subclasses:
- MessageMappingMessageHandler
Also supports discovering and invoking exception handling methods to process exceptions raised during message handling.
- Since:
- 5.2
- Author:
- Rossen Stoyanchev
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.protected abstract AbstractExceptionHandlerMethodResolvercreateExceptionMethodResolverFor(Class<?> beanType) Create a concrete instance ofAbstractExceptionHandlerMethodResolverthat finds exception handling methods based on some criteria, for example, based on the presence of@MessageExceptionHandler.protected final voiddetectHandlerMethods(Object handler) Detect if the given handler has any methods that can handle messages and if so register it with the extracted mapping information.protected TextendMapping(T mapping, HandlerMethod handlerMethod) This method is invoked just before mappings are added.Return the configured custom resolvers for handler method arguments.protected HandlerMethodArgumentResolverCompositeReturn the argument resolvers initialized duringafterPropertiesSet().protected abstract @Nullable RouteMatcher.RoutegetDestination(Message<?> message) Extract the destination from the given message.Return a read-only multi-value map with a direct lookup of mappings, (for example, for non-pattern destinations).getDirectLookupMappings(T mapping) Return String-based destinations for the given mapping, if any, that can be used to find matches with a direct lookup (i.e.Return a read-only map with all handler methods and their mappings.Return theconfiguredhandler predicate.protected abstract Comparator<T>getMappingComparator(Message<?> message) Return a comparator for sorting matching mappings.getMappingForMethod(Method method, Class<?> handlerType) Obtain the mapping for the given method, if any.getMatchingMapping(T 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 configured registry for adapting reactive types.Return the configured return value handlers.protected reactor.core.publisher.Mono<Void>handleMatch(T mapping, HandlerMethod handlerMethod, Message<?> message) reactor.core.publisher.Mono<Void>handleMessage(Message<?> message) Handle the given message.protected voidhandleNoMatch(@Nullable RouteMatcher.Route destination, Message<?> message) Invoked when no matching handler is found.protected abstract List<? extends HandlerMethodArgumentResolver>Return the list of argument resolvers to use.protected abstract List<? extends HandlerMethodReturnValueHandler>Return the list of return value handlers to use.protected voidregisterExceptionHandlerAdvice(MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) Subclasses can invoke this method to populate the MessagingAdviceBean cache (for example, to support "global"@MessageExceptionHandler).final voidregisterHandlerMethod(Object handler, Method method, T mapping) Register a handler method and its unique mapping.voidsetApplicationContext(@Nullable ApplicationContext applicationContext) Set the ApplicationContext that this object runs in.voidConfigure custom resolvers for handler method arguments.voidsetBeanName(String name) Set the name of the bean in the bean factory that created this bean.voidsetHandlerPredicate(@Nullable Predicate<Class<?>> handlerPredicate) Configure a predicate for selecting which Spring beans to check for the presence of message handler methods.voidsetHandlers(List<Object> handlers) Manually configure the handlers to check for the presence of message handling methods, which also disables auto-detection via ahandlerPredicate.voidConfigure the registry for adapting various reactive types.voidConfigure custom return value handlers for handler methods.
- 
Field Details- 
loggerprotected final org.apache.commons.logging.Log logger
 
- 
- 
Constructor Details- 
AbstractMethodMessageHandlerpublic AbstractMethodMessageHandler()
 
- 
- 
Method Details- 
setHandlerPredicateConfigure a predicate for selecting which Spring beans to check for the presence of message handler methods.This is not set by default. However, subclasses may initialize it to some default strategy (for example, @Controllerclasses).- See Also:
 
- 
getHandlerPredicateReturn theconfiguredhandler predicate.
- 
setHandlersManually configure the handlers to check for the presence of message handling methods, which also disables auto-detection via ahandlerPredicate. If you do not want to disable auto-detection, then call this method first, and then set the handler predicate.- Parameters:
- handlers- the handlers to check
 
- 
setArgumentResolverConfigurerConfigure custom resolvers for handler method arguments.
- 
getArgumentResolverConfigurerReturn the configured custom resolvers for handler method arguments.
- 
setReturnValueHandlerConfigurerConfigure custom return value handlers for handler methods.
- 
getReturnValueHandlerConfigurerReturn the configured return value handlers.
- 
setReactiveAdapterRegistryConfigure the registry for adapting various reactive types.By default this is an instance of ReactiveAdapterRegistrywith default settings.
- 
getReactiveAdapterRegistryReturn the configured registry for adapting reactive types.
- 
setApplicationContextDescription copied from interface:ApplicationContextAwareSet the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.Invoked after population of normal bean properties but before an init callback such as InitializingBean.afterPropertiesSet()or a custom init-method. Invoked afterResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader),ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)andMessageSourceAware, if applicable.- Specified by:
- setApplicationContextin interface- ApplicationContextAware
- Parameters:
- applicationContext- the ApplicationContext object to be used by this object
- See Also:
 
- 
getApplicationContext
- 
setBeanNameDescription copied from interface:BeanNameAwareSet the name of the bean in the bean factory that created this bean.Invoked after population of normal bean properties but before an init callback such as InitializingBean.afterPropertiesSet()or a custom init-method.- Specified by:
- setBeanNamein interface- BeanNameAware
- Parameters:
- name- the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the- BeanFactoryUtils.originalBeanName(String)method to extract the original bean name (without suffix), if desired.
 
- 
getBeanName
- 
registerExceptionHandlerAdviceprotected void registerExceptionHandlerAdvice(MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) Subclasses can invoke this method to populate the MessagingAdviceBean cache (for example, to support "global"@MessageExceptionHandler).
- 
getHandlerMethodsReturn a read-only map with all handler methods and their mappings.
- 
getDestinationLookupReturn a read-only multi-value map with a direct lookup of mappings, (for example, for non-pattern destinations).
- 
getArgumentResolversReturn the argument resolvers initialized duringafterPropertiesSet(). Primarily for internal use in subclasses.- Since:
- 5.2.2
 
- 
afterPropertiesSetpublic void afterPropertiesSet()Description copied from interface:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. - Specified by:
- afterPropertiesSetin interface- InitializingBean
 
- 
initArgumentResolversReturn the list of argument resolvers to use.Subclasses should also take into account custom argument types configured via setArgumentResolverConfigurer(org.springframework.messaging.handler.invocation.reactive.ArgumentResolverConfigurer).
- 
initReturnValueHandlersReturn the list of return value handlers to use.Subclasses should also take into account custom return value types configured via setReturnValueHandlerConfigurer(org.springframework.messaging.handler.invocation.reactive.ReturnValueHandlerConfigurer).
- 
detectHandlerMethodsDetect if the given handler has any methods that can handle messages and if so register it with the extracted mapping information.Note: This method is protected and can be invoked by subclasses, but this should be done on startup only as documented in registerHandlerMethod(java.lang.Object, java.lang.reflect.Method, T).- Parameters:
- handler- the handler to check, either an instance of a Spring bean name
 
- 
getMappingForMethodObtain the mapping for the given method, if any.- Parameters:
- method- the method to check
- handlerType- the handler type, possibly a subtype of the method's declaring class
- Returns:
- the mapping, or nullif the method is not mapped
 
- 
registerHandlerMethodRegister a handler method and its unique mapping.Note: As of 5.3 this method is public (rather than protected) and can be used both at startup and at runtime. - Parameters:
- handler- the bean name of the handler or the handler instance
- method- the method to register
- mapping- the mapping conditions associated with the handler method
- Throws:
- IllegalStateException- if another method was already registered under the same mapping
 
- 
extendMappingThis method is invoked just before mappings are added. It allows subclasses to update the mapping with theHandlerMethodin mind. This can be useful when the method signature is used to refine the mapping, for example, based on the cardinality of input and output.By default this method returns the mapping that is passed in. - Parameters:
- mapping- the mapping to be added
- handlerMethod- the target handler for the mapping
- Returns:
- a new mapping or the same
- Since:
- 5.2.2
 
- 
getDirectLookupMappingsReturn String-based destinations for the given mapping, if any, that can be used to find matches with a direct lookup (i.e. non-patterns).Note: This is completely optional. The mapping metadata for a subclass may support neither direct lookups, nor String based destinations. 
- 
handleMessagepublic reactor.core.publisher.Mono<Void> handleMessage(Message<?> message) throws MessagingException Description copied from interface:ReactiveMessageHandlerHandle the given message.- Specified by:
- handleMessagein interface- ReactiveMessageHandler
- Parameters:
- message- the message to be handled
- Returns:
- a completion Monofor the result of the message handling
- Throws:
- MessagingException
 
- 
handleMatchprotected reactor.core.publisher.Mono<Void> handleMatch(T mapping, HandlerMethod handlerMethod, Message<?> message) 
- 
getDestinationExtract the destination from the given message.- See Also:
 
- 
getMatchingMappingCheck if a mapping matches the current message and return a possibly new mapping with conditions relevant to the current request.- Parameters:
- mapping- the mapping to get a match for
- message- the message being handled
- Returns:
- the match or nullif there is no match
 
- 
getMappingComparatorReturn a comparator for sorting matching mappings. The returned comparator should sort 'better' matches higher.- Parameters:
- message- the current Message
- Returns:
- the comparator, never null
 
- 
handleNoMatchInvoked when no matching handler is found.- Parameters:
- destination- the destination
- message- the message
 
- 
createExceptionMethodResolverForprotected abstract AbstractExceptionHandlerMethodResolver createExceptionMethodResolverFor(Class<?> beanType) Create a concrete instance ofAbstractExceptionHandlerMethodResolverthat finds exception handling methods based on some criteria, for example, based on the presence of@MessageExceptionHandler.- Parameters:
- beanType- the class in which an exception occurred during handling
- Returns:
- the resolver to use
 
 
-