T
- the type of the Object that contains information mapping a
HandlerMethod
to incoming messagespublic abstract class AbstractMethodMessageHandler<T> extends Object implements MessageHandler, ApplicationContextAware, InitializingBean
Also supports discovering and invoking exception handling methods to process exceptions raised during message handling.
Constructor and Description |
---|
AbstractMethodMessageHandler() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied
(and satisfied BeanFactoryAware and ApplicationContextAware).
|
protected abstract AbstractExceptionHandlerMethodResolver |
createExceptionHandlerMethodResolverFor(Class<?> beanType) |
protected HandlerMethod |
createHandlerMethod(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 void |
detectHandlerMethods(Object handler)
Detect if the given handler has any methods that can handle messages and if
so register it with the extracted mapping information.
|
ApplicationContext |
getApplicationContext() |
List<HandlerMethodArgumentResolver> |
getArgumentResolvers() |
List<HandlerMethodArgumentResolver> |
getCustomArgumentResolvers() |
List<HandlerMethodReturnValueHandler> |
getCustomReturnValueHandlers() |
protected abstract String |
getDestination(Message<?> message) |
Collection<String> |
getDestinationPrefixes() |
protected abstract Set<String> |
getDirectLookupDestinations(T mapping)
Return destinations contained in the mapping that are not patterns and are
therefore suitable for direct lookups.
|
Map<T,HandlerMethod> |
getHandlerMethods()
Return a map with all handler methods and their mappings.
|
protected String |
getLookupDestination(String destination)
Find if the given destination matches any of the configured allowed destination
prefixes and if a match is found return the destination with the prefix removed.
|
protected abstract Comparator<T> |
getMappingComparator(Message<?> message)
Return a comparator for sorting matching mappings.
|
protected abstract T |
getMappingForMethod(Method method,
Class<?> handlerType)
Provide the mapping for a handler method.
|
protected abstract T |
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.
|
List<HandlerMethodReturnValueHandler> |
getReturnValueHandlers() |
protected void |
handleMatch(T mapping,
HandlerMethod handlerMethod,
String lookupDestination,
Message<?> message) |
void |
handleMessage(Message<?> message)
Handle the given message.
|
protected void |
handleMessageInternal(Message<?> message,
String lookupDestination) |
protected void |
handleNoMatch(Set<T> ts,
String lookupDestination,
Message<?> message) |
protected abstract List<? extends HandlerMethodArgumentResolver> |
initArgumentResolvers()
Return the list of argument resolvers to use.
|
protected abstract List<? extends HandlerMethodReturnValueHandler> |
initReturnValueHandlers()
Return the list of return value handlers to use.
|
protected abstract boolean |
isHandler(Class<?> beanType)
Whether the given bean type should be introspected for messaging handling methods.
|
protected void |
processHandlerMethodException(HandlerMethod handlerMethod,
Exception ex,
Message<?> message) |
protected void |
registerHandlerMethod(Object handler,
Method method,
T mapping)
Register a handler method and its unique mapping.
|
void |
setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext that this object runs in.
|
void |
setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)
Configure the complete list of supported argument types effectively overriding
the ones configured by default.
|
void |
setCustomArgumentResolvers(List<HandlerMethodArgumentResolver> customArgumentResolvers)
Sets the list of custom
HandlerMethodArgumentResolver s that will be used
after resolvers for supported argument type. |
void |
setCustomReturnValueHandlers(List<HandlerMethodReturnValueHandler> customReturnValueHandlers)
Set the list of custom
HandlerMethodReturnValueHandler s that will be used
after return value handlers for known types. |
void |
setDestinationPrefixes(Collection<String> prefixes)
Configure one or more prefixes to match to the destinations of handled messages.
|
void |
setReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)
Configure the complete list of supported return value types effectively overriding
the ones configured by default.
|
protected final Log logger
public void setDestinationPrefixes(Collection<String> prefixes)
By default the list of prefixes is empty in which case all destinations match.
public Collection<String> getDestinationPrefixes()
public void setCustomArgumentResolvers(List<HandlerMethodArgumentResolver> customArgumentResolvers)
HandlerMethodArgumentResolver
s that will be used
after resolvers for supported argument type.customArgumentResolvers
- the list of resolvers; never null
.public List<HandlerMethodArgumentResolver> getCustomArgumentResolvers()
public void setCustomReturnValueHandlers(List<HandlerMethodReturnValueHandler> customReturnValueHandlers)
HandlerMethodReturnValueHandler
s that will be used
after return value handlers for known types.customReturnValueHandlers
- the list of custom return value handlers, never null
.public List<HandlerMethodReturnValueHandler> getCustomReturnValueHandlers()
public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)
setCustomArgumentResolvers(java.util.List)
.public List<HandlerMethodArgumentResolver> getArgumentResolvers()
public void setReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)
setCustomReturnValueHandlers(java.util.List)
public List<HandlerMethodReturnValueHandler> getReturnValueHandlers()
public Map<T,HandlerMethod> getHandlerMethods()
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
ApplicationContextAware
Invoked after population of normal bean properties but before an init callback such
as InitializingBean.afterPropertiesSet()
or a custom init-method. Invoked after ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)
,
ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
and
MessageSourceAware
, if applicable.
setApplicationContext
in interface ApplicationContextAware
applicationContext
- the ApplicationContext object to be used by this objectApplicationContextException
- in case of context initialization errorsBeansException
- if thrown by application context methodsBeanInitializationException
public ApplicationContext getApplicationContext()
public void afterPropertiesSet()
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
protected abstract List<? extends HandlerMethodArgumentResolver> initArgumentResolvers()
setArgumentResolvers(java.util.List)
.
Sub-classes should also take into account custom argument types configured via
setCustomArgumentResolvers(java.util.List)
.
protected abstract List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers()
setReturnValueHandlers(java.util.List)
.
Sub-classes should also take into account custom return value types configured
via setCustomReturnValueHandlers(java.util.List)
.
protected abstract boolean isHandler(Class<?> beanType)
protected final void detectHandlerMethods(Object handler)
handler
- the handler to check, either an instance of a Spring bean nameprotected abstract T getMappingForMethod(Method method, Class<?> handlerType)
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 void registerHandlerMethod(Object handler, Method method, T mapping)
handler
- the bean name of the handler or the handler instancemethod
- the method to registermapping
- the mapping conditions associated with the handler methodIllegalStateException
- if another method was already registered
under the same mappingprotected HandlerMethod createHandlerMethod(Object handler, Method method)
protected abstract Set<String> getDirectLookupDestinations(T mapping)
public void handleMessage(Message<?> message) throws MessagingException
MessageHandler
handleMessage
in interface MessageHandler
message
- the message to be handledMessagingException
protected String getLookupDestination(String destination)
If no destination prefixes are configured, the destination is returned as is.
null
if the destination does not matchprotected void handleMessageInternal(Message<?> message, String lookupDestination)
protected abstract T getMatchingMapping(T mapping, Message<?> message)
mapping
- the mapping to get a match formessage
- the message being handlednull
if there is no matchprotected abstract Comparator<T> getMappingComparator(Message<?> message)
message
- the current Messagenull
protected void handleMatch(T mapping, HandlerMethod handlerMethod, String lookupDestination, Message<?> message)
protected void processHandlerMethodException(HandlerMethod handlerMethod, Exception ex, Message<?> message)
protected abstract AbstractExceptionHandlerMethodResolver createExceptionHandlerMethodResolverFor(Class<?> beanType)