public class AnnotationMethodMessageHandler extends java.lang.Object implements MessageHandler, ApplicationContextAware, InitializingBean
Modifier and Type | Class and Description |
---|---|
private static class |
AnnotationMethodMessageHandler.MappingInfo |
private static interface |
AnnotationMethodMessageHandler.MappingInfoCreator<A extends java.lang.annotation.Annotation> |
private static class |
AnnotationMethodMessageHandler.MessageMappingInfoCreator |
private static class |
AnnotationMethodMessageHandler.SubscribeMappingInfoCreator |
private static class |
AnnotationMethodMessageHandler.UnsubscribeMappingInfoCreator |
Modifier and Type | Field and Description |
---|---|
private ApplicationContext |
applicationContext |
private HandlerMethodArgumentResolverComposite |
argumentResolvers |
private java.util.List<java.lang.String> |
destinationPrefixes |
private SimpMessageSendingOperations |
dispatchMessagingTemplate |
private java.util.Map<java.lang.Class<?>,ExceptionHandlerMethodResolver> |
exceptionHandlerCache |
private static Log |
logger |
private MessageConverter<?> |
messageConverter |
private java.util.Map<AnnotationMethodMessageHandler.MappingInfo,HandlerMethod> |
messageMethods |
private HandlerMethodReturnValueHandlerComposite |
returnValueHandlers |
private java.util.Map<AnnotationMethodMessageHandler.MappingInfo,HandlerMethod> |
subscribeMethods |
private java.util.Map<AnnotationMethodMessageHandler.MappingInfo,HandlerMethod> |
unsubscribeMethods |
private SimpMessageSendingOperations |
webSocketSessionMessagingTemplate |
Constructor and Description |
---|
AnnotationMethodMessageHandler(SimpMessageSendingOperations dispatchMessagingTemplate,
MessageChannel webSocketSessionChannel) |
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).
|
private boolean |
checkDestinationPrefix(java.lang.String destination) |
protected HandlerMethod |
createHandlerMethod(java.lang.Object handler,
java.lang.reflect.Method method) |
protected void |
detectHandlerMethods(java.lang.Object handler) |
java.util.List<java.lang.String> |
getDestinationPrefixes() |
protected HandlerMethod |
getHandlerMethod(java.lang.String destination,
java.util.Map<AnnotationMethodMessageHandler.MappingInfo,HandlerMethod> handlerMethods) |
MessageConverter<?> |
getMessageConverter() |
void |
handleMessage(Message<?> message)
Handles the message if possible.
|
private void |
handleMessageInternal(Message<?> message,
java.util.Map<AnnotationMethodMessageHandler.MappingInfo,HandlerMethod> handlerMethods) |
protected void |
initHandlerMethods() |
private <A extends java.lang.annotation.Annotation> |
initHandlerMethods(java.lang.Object handler,
java.lang.Class<?> handlerType,
java.lang.Class<A> annotationType,
AnnotationMethodMessageHandler.MappingInfoCreator<A> mappingInfoCreator,
java.util.Map<AnnotationMethodMessageHandler.MappingInfo,HandlerMethod> handlerMethods) |
private void |
invokeExceptionHandler(Message<?> message,
HandlerMethod handlerMethod,
java.lang.Exception ex) |
protected boolean |
isHandler(java.lang.Class<?> beanType) |
void |
setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext that this object runs in.
|
void |
setDestinationPrefixes(java.util.List<java.lang.String> destinationPrefixes) |
void |
setMessageConverter(MessageConverter<?> converter) |
private static final Log logger
private final SimpMessageSendingOperations dispatchMessagingTemplate
private final SimpMessageSendingOperations webSocketSessionMessagingTemplate
private java.util.List<java.lang.String> destinationPrefixes
private MessageConverter<?> messageConverter
private ApplicationContext applicationContext
private java.util.Map<AnnotationMethodMessageHandler.MappingInfo,HandlerMethod> messageMethods
private java.util.Map<AnnotationMethodMessageHandler.MappingInfo,HandlerMethod> subscribeMethods
private java.util.Map<AnnotationMethodMessageHandler.MappingInfo,HandlerMethod> unsubscribeMethods
private final java.util.Map<java.lang.Class<?>,ExceptionHandlerMethodResolver> exceptionHandlerCache
private HandlerMethodArgumentResolverComposite argumentResolvers
private HandlerMethodReturnValueHandlerComposite returnValueHandlers
public AnnotationMethodMessageHandler(SimpMessageSendingOperations dispatchMessagingTemplate, MessageChannel webSocketSessionChannel)
dispatchMessagingTemplate
- a messaging template to dispatch messages to for
further processing, e.g. the use of an ReplyTo
annotation on a
message handling method, causes a new (broadcast) message to be sent.webSocketSessionChannel
- the channel to send messages to WebSocket sessions
on this application server. This is used primarily for processing the return
values from SubscribeEvent
-annotated methods.public void setDestinationPrefixes(java.util.List<java.lang.String> destinationPrefixes)
public java.util.List<java.lang.String> getDestinationPrefixes()
public void setMessageConverter(MessageConverter<?> converter)
public MessageConverter<?> getMessageConverter()
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 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 void initHandlerMethods()
protected boolean isHandler(java.lang.Class<?> beanType)
protected void detectHandlerMethods(java.lang.Object handler)
private <A extends java.lang.annotation.Annotation> void initHandlerMethods(java.lang.Object handler, java.lang.Class<?> handlerType, java.lang.Class<A> annotationType, AnnotationMethodMessageHandler.MappingInfoCreator<A> mappingInfoCreator, java.util.Map<AnnotationMethodMessageHandler.MappingInfo,HandlerMethod> handlerMethods)
protected HandlerMethod createHandlerMethod(java.lang.Object handler, java.lang.reflect.Method method)
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
private void handleMessageInternal(Message<?> message, java.util.Map<AnnotationMethodMessageHandler.MappingInfo,HandlerMethod> handlerMethods)
private boolean checkDestinationPrefix(java.lang.String destination)
private void invokeExceptionHandler(Message<?> message, HandlerMethod handlerMethod, java.lang.Exception ex)
protected HandlerMethod getHandlerMethod(java.lang.String destination, java.util.Map<AnnotationMethodMessageHandler.MappingInfo,HandlerMethod> handlerMethods)