Class AbstractMethodMessageHandler<T>
- Type Parameters:
- T- the type of the Object that contains information mapping a- HandlerMethodto incoming messages
- All Implemented Interfaces:
- Aware,- InitializingBean,- ApplicationContextAware,- MessageHandler
- Direct Known Subclasses:
- SimpAnnotationMethodMessageHandler
Also supports discovering and invoking exception handling methods to process exceptions raised during message handling.
- Since:
- 4.0
- Author:
- Rossen Stoyanchev, Juergen Hoeller
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.protected abstract AbstractExceptionHandlerMethodResolvercreateExceptionHandlerMethodResolverFor(Class<?> beanType) protected HandlerMethodcreateHandlerMethod(Object handler, Method method) Create a HandlerMethod instance from an Object handler that is either a handler instance or a String-based bean name.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.Return the complete list of argument resolvers.Return the configured custom argument resolvers, if any.Return the configured custom return value handlers, if any.protected abstract StringgetDestination(Message<?> message) Return the configured destination prefixes, if any.getDirectLookupDestinations(T mapping) Return destinations contained in the mapping that are not patterns and are therefore suitable for direct lookups.protected InvocableHandlerMethodgetExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) Find an@MessageExceptionHandlermethod for the given exception.protected LogReturn a logger to set onInvocableHandlerMethod.Return a map with all handler methods and their mappings.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 abstract Comparator<T>getMappingComparator(Message<?> message) Return a comparator for sorting matching mappings.protected abstract TgetMappingForMethod(Method method, Class<?> handlerType) Provide the mapping for a handler method.protected abstract TgetMatchingMapping(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.protected LogReturn a logger to set onHandlerMethodReturnValueHandlerComposite.Return the complete list of return value handlers.protected voidhandleMatch(T mapping, HandlerMethod handlerMethod, String lookupDestination, Message<?> message) voidhandleMessage(Message<?> message) Handle the given message.protected voidhandleMessageInternal(Message<?> message, String lookupDestination) protected voidhandleNoMatch(Set<T> ts, String lookupDestination, Message<?> message) 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 abstract booleanWhether the given bean type should be introspected for messaging handling methods.protected voidprocessHandlerMethodException(HandlerMethod handlerMethod, Exception exception, Message<?> message) protected voidregisterExceptionHandlerAdvice(MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) Subclasses can invoke this method to populate the MessagingAdviceBean cache (e.g.protected voidregisterHandlerMethod(Object handler, Method method, T mapping) Register a handler method and its unique mapping.voidsetApplicationContext(ApplicationContext applicationContext) Set the ApplicationContext that this object runs in.voidsetArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) Configure the complete list of supported argument types, effectively overriding the ones configured by default.voidsetCustomArgumentResolvers(List<HandlerMethodArgumentResolver> customArgumentResolvers) Sets the list of customHandlerMethodArgumentResolvers that will be used after resolvers for supported argument type.voidsetCustomReturnValueHandlers(List<HandlerMethodReturnValueHandler> customReturnValueHandlers) Set the list of customHandlerMethodReturnValueHandlers that will be used after return value handlers for known types.voidsetDestinationPrefixes(Collection<String> prefixes) When this property is configured only messages to destinations matching one of the configured prefixes are eligible for handling.voidsetReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) Configure the complete list of supported return value types, effectively overriding the ones configured by default.toString()
- 
Field Details- 
logger
 
- 
- 
Constructor Details- 
AbstractMethodMessageHandlerpublic AbstractMethodMessageHandler()
 
- 
- 
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. 
- 
getDestinationPrefixesReturn the configured destination prefixes, if any.
- 
setCustomArgumentResolverspublic void setCustomArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> customArgumentResolvers) Sets the list of customHandlerMethodArgumentResolvers that will be used after resolvers for supported argument type.
- 
getCustomArgumentResolversReturn the configured custom argument resolvers, if any.
- 
setCustomReturnValueHandlerspublic void setCustomReturnValueHandlers(@Nullable List<HandlerMethodReturnValueHandler> customReturnValueHandlers) Set the list of customHandlerMethodReturnValueHandlers that will be used after return value handlers for known types.
- 
getCustomReturnValueHandlersReturn the configured custom return value handlers, if any.
- 
setArgumentResolversConfigure the complete list of supported argument types, effectively overriding the ones configured by default. This is an advanced option; for most use cases it should be sufficient to usesetCustomArgumentResolvers(java.util.List<org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver>).
- 
getArgumentResolversReturn the complete list of argument resolvers.
- 
setReturnValueHandlerspublic void setReturnValueHandlers(@Nullable List<HandlerMethodReturnValueHandler> returnValueHandlers) Configure the complete list of supported return value types, effectively overriding the ones configured by default. This is an advanced option; for most use cases it should be sufficient to usesetCustomReturnValueHandlers(java.util.List<org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler>).
- 
getReturnValueHandlersReturn the complete list of return value handlers.
- 
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
- 
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. Invoked only if the resolvers have not already been set viasetArgumentResolvers(java.util.List<org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver>).Subclasses should also take into account custom argument types configured via setCustomArgumentResolvers(java.util.List<org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver>).
- 
initReturnValueHandlersReturn the list of return value handlers to use. Invoked only if the return value handlers have not already been set viasetReturnValueHandlers(java.util.List<org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler>).Subclasses should also take into account custom return value types configured via setCustomReturnValueHandlers(java.util.List<org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler>).
- 
isHandlerWhether the given bean type should be introspected for messaging handling methods.
- 
detectHandlerMethodsDetect if the given handler has any methods that can handle messages and if so register it with the extracted mapping information.- Parameters:
- handler- the handler to check, either an instance of a Spring bean name
 
- 
getMappingForMethodProvide the mapping for a handler method.- 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
 
- 
registerHandlerMethodRegister a handler method and its unique mapping.- 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
 
- 
createHandlerMethodCreate a HandlerMethod instance from an Object handler that is either a handler instance or a String-based bean name.
- 
getDirectLookupDestinationsReturn destinations contained in the mapping that are not patterns and are therefore suitable for direct lookups.
- 
getReturnValueHandlerLoggerReturn a logger to set onHandlerMethodReturnValueHandlerComposite.- Since:
- 5.1
 
- 
getHandlerMethodLoggerReturn a logger to set onInvocableHandlerMethod.- Since:
- 5.1
 
- 
registerExceptionHandlerAdviceprotected void registerExceptionHandlerAdvice(MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) Subclasses can invoke this method to populate the MessagingAdviceBean cache (e.g. to support "global"@MessageExceptionHandler).- Since:
- 4.2
 
- 
getHandlerMethodsReturn a map with all handler methods and their mappings.
- 
handleMessageDescription copied from interface:MessageHandlerHandle the given message.- Specified by:
- handleMessagein interface- MessageHandler
- Parameters:
- message- the message to be handled
- Throws:
- MessagingException- if the handler failed to process the message
 
- 
getDestination
- 
getLookupDestinationCheck 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. 
- 
handleMessageInternal
- 
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
 
- 
handleNoMatch
- 
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
 
- 
handleMatchprotected void handleMatch(T mapping, HandlerMethod handlerMethod, String lookupDestination, Message<?> message) 
- 
processHandlerMethodExceptionprotected void processHandlerMethodException(HandlerMethod handlerMethod, Exception exception, Message<?> message) 
- 
getExceptionHandlerMethod@Nullable protected InvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) Find an@MessageExceptionHandlermethod for the given exception. The default implementation searches methods in the class hierarchy of the HandlerMethod first and if not found, it continues searching for additional@MessageExceptionHandlermethods among the configured MessagingAdviceBean, if any.- Parameters:
- handlerMethod- the method where the exception was raised
- exception- the raised exception
- Returns:
- a method to handle the exception, or null
- Since:
- 4.2
 
- 
createExceptionHandlerMethodResolverForprotected abstract AbstractExceptionHandlerMethodResolver createExceptionHandlerMethodResolverFor(Class<?> beanType) 
- 
toString
 
-