T
- the type of the Object that contains information mapping
a HandlerMethod
to incoming messagespublic abstract class AbstractMethodMessageHandler<T> extends Object implements MessageHandler, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean
Also supports discovering and invoking exception handling methods to process exceptions raised during message handling.
Modifier and Type | Field and Description |
---|---|
protected Log |
logger |
static String |
LOOKUP_DESTINATION_HEADER |
Constructor and Description |
---|
AbstractMethodMessageHandler() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
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.
|
org.springframework.context.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)
Handles the message if possible.
|
protected void |
handleMessageInternal(Message<?> message,
String lookupDestination) |
protected abstract 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(org.springframework.context.ApplicationContext applicationContext) |
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 static final String LOOKUP_DESTINATION_HEADER
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(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
org.springframework.beans.BeansException
public org.springframework.context.ApplicationContext getApplicationContext()
public void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.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
MessageRejectedException
e.g.
in case of a Selective Consumer. When a consumer tries to handle a
message, but fails to do so, a MessageHandlingException
is
thrown. In the last case it is recommended to treat the message as tainted
and go into an error scenario.
When the handling results in a failure of another message being sent
(e.g. a "reply" message), that failure will trigger a
MessageDeliveryException
.
handleMessage
in interface MessageHandler
message
- the message to be handled
reply related to the handling of the messageMessagingException
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)