diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java index b28641a2a845..004d25ed1199 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java @@ -83,17 +83,25 @@ public abstract class AbstractMethodMessageHandler protected final Log logger = LogFactory.getLog(getClass()); - private final List customArgumentResolvers = new ArrayList(4); + private Collection destinationPrefixes = new ArrayList(); + + private final List customArgumentResolvers = + new ArrayList(4); + + private final List customReturnValueHandlers = + new ArrayList(4); - private final List customReturnValueHandlers = new ArrayList(4); + private final HandlerMethodArgumentResolverComposite argumentResolvers = + new HandlerMethodArgumentResolverComposite(); - private final HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite(); + private final HandlerMethodReturnValueHandlerComposite returnValueHandlers = + new HandlerMethodReturnValueHandlerComposite(); - private final HandlerMethodReturnValueHandlerComposite returnValueHandlers =new HandlerMethodReturnValueHandlerComposite(); + private ApplicationContext applicationContext; - private final Map handlerMethods = new LinkedHashMap(); + private final Map handlerMethods = new LinkedHashMap(64); - private final MultiValueMap destinationLookup = new LinkedMultiValueMap(); + private final MultiValueMap destinationLookup = new LinkedMultiValueMap(64); private final Map, AbstractExceptionHandlerMethodResolver> exceptionHandlerCache = new ConcurrentHashMap, AbstractExceptionHandlerMethodResolver>(64); @@ -101,16 +109,6 @@ public abstract class AbstractMethodMessageHandler private final Map exceptionHandlerAdviceCache = new LinkedHashMap(64); - private Collection destinationPrefixes = new ArrayList(); - - private ApplicationContext applicationContext; - - /** - * Return the configured destination prefixes. - */ - public Collection getDestinationPrefixes() { - return this.destinationPrefixes; - } /** * When this property is configured only messages to destinations matching @@ -131,16 +129,15 @@ public void setDestinationPrefixes(Collection prefixes) { } /** - * Return the configured custom argument resolvers, if any. + * Return the configured destination prefixes, if any. */ - public List getCustomArgumentResolvers() { - return this.customArgumentResolvers; + public Collection getDestinationPrefixes() { + return this.destinationPrefixes; } /** * Sets the list of custom {@code HandlerMethodArgumentResolver}s that will be used * after resolvers for supported argument type. - * @param customArgumentResolvers the list of resolvers; never {@code null}. */ public void setCustomArgumentResolvers(List customArgumentResolvers) { this.customArgumentResolvers.clear(); @@ -150,16 +147,15 @@ public void setCustomArgumentResolvers(List custo } /** - * Return the configured custom return value handlers, if any. + * Return the configured custom argument resolvers, if any. */ - public List getCustomReturnValueHandlers() { - return this.customReturnValueHandlers; + public List getCustomArgumentResolvers() { + return this.customArgumentResolvers; } /** * Set the list of custom {@code HandlerMethodReturnValueHandler}s that will be used * after return value handlers for known types. - * @param customReturnValueHandlers the list of custom return value handlers, never {@code null}. */ public void setCustomReturnValueHandlers(List customReturnValueHandlers) { this.customReturnValueHandlers.clear(); @@ -169,15 +165,15 @@ public void setCustomReturnValueHandlers(List c } /** - * Return the configured argument resolvers, if any. + * Return the configured custom return value handlers, if any. */ - public List getArgumentResolvers() { - return this.argumentResolvers.getResolvers(); + public List getCustomReturnValueHandlers() { + return this.customReturnValueHandlers; } /** - * Configure the complete list of supported argument types effectively overriding - * the ones configured by default. This is an advanced option. For most use cases + * Configure 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 use {@link #setCustomArgumentResolvers}. */ public void setArgumentResolvers(List argumentResolvers) { @@ -189,15 +185,15 @@ public void setArgumentResolvers(List argumentRes } /** - * Return the configured return value handlers, if any. + * Return the complete list of argument resolvers. */ - public List getReturnValueHandlers() { - return this.returnValueHandlers.getReturnValueHandlers(); + public List getArgumentResolvers() { + return this.argumentResolvers.getResolvers(); } /** - * 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 + * 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 use {@link #setCustomReturnValueHandlers}. */ public void setReturnValueHandlers(List returnValueHandlers) { @@ -208,8 +204,11 @@ public void setReturnValueHandlers(List returnV this.returnValueHandlers.addHandlers(returnValueHandlers); } - public ApplicationContext getApplicationContext() { - return this.applicationContext; + /** + * Return the complete list of return value handlers. + */ + public List getReturnValueHandlers() { + return this.returnValueHandlers.getReturnValueHandlers(); } @Override @@ -217,6 +216,11 @@ public void setApplicationContext(ApplicationContext applicationContext) { this.applicationContext = applicationContext; } + public ApplicationContext getApplicationContext() { + return this.applicationContext; + } + + @Override public void afterPropertiesSet() { if (this.argumentResolvers.getResolvers().isEmpty()) { @@ -359,7 +363,9 @@ protected HandlerMethod createHandlerMethod(Object handler, Method method) { * (e.g. to support "global" {@code @MessageExceptionHandler}). * @since 4.2 */ - protected void registerExceptionHandlerAdvice(MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) { + protected void registerExceptionHandlerAdvice( + MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) { + this.exceptionHandlerAdviceCache.put(bean, resolver); }