Allow configuring custom argument types
The WebSocket messaging namespace now exposes configuration options for custom argument resolvers and return value handlers. Issue: SPR-12217
This commit is contained in:
@@ -71,9 +71,9 @@ public abstract class AbstractMethodMessageHandler<T>
|
||||
|
||||
private Collection<String> destinationPrefixes = new ArrayList<String>();
|
||||
|
||||
private List<HandlerMethodArgumentResolver> customArgumentResolvers = new ArrayList<HandlerMethodArgumentResolver>();
|
||||
private final List<HandlerMethodArgumentResolver> customArgumentResolvers = new ArrayList<HandlerMethodArgumentResolver>(4);
|
||||
|
||||
private List<HandlerMethodReturnValueHandler> customReturnValueHandlers = new ArrayList<HandlerMethodReturnValueHandler>();
|
||||
private final List<HandlerMethodReturnValueHandler> customReturnValueHandlers = new ArrayList<HandlerMethodReturnValueHandler>(4);
|
||||
|
||||
private HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite();
|
||||
|
||||
@@ -121,10 +121,15 @@ public abstract class AbstractMethodMessageHandler<T>
|
||||
* @param customArgumentResolvers the list of resolvers; never {@code null}.
|
||||
*/
|
||||
public void setCustomArgumentResolvers(List<HandlerMethodArgumentResolver> customArgumentResolvers) {
|
||||
Assert.notNull(customArgumentResolvers, "The 'customArgumentResolvers' cannot be null.");
|
||||
this.customArgumentResolvers = customArgumentResolvers;
|
||||
this.customArgumentResolvers.clear();
|
||||
if (customArgumentResolvers != null) {
|
||||
this.customArgumentResolvers.addAll(customArgumentResolvers);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured custom argument resolvers, if any.
|
||||
*/
|
||||
public List<HandlerMethodArgumentResolver> getCustomArgumentResolvers() {
|
||||
return this.customArgumentResolvers;
|
||||
}
|
||||
@@ -135,10 +140,15 @@ public abstract class AbstractMethodMessageHandler<T>
|
||||
* @param customReturnValueHandlers the list of custom return value handlers, never {@code null}.
|
||||
*/
|
||||
public void setCustomReturnValueHandlers(List<HandlerMethodReturnValueHandler> customReturnValueHandlers) {
|
||||
Assert.notNull(customReturnValueHandlers, "The 'customReturnValueHandlers' cannot be null.");
|
||||
this.customReturnValueHandlers = customReturnValueHandlers;
|
||||
this.customReturnValueHandlers.clear();
|
||||
if (customReturnValueHandlers != null) {
|
||||
this.customReturnValueHandlers.addAll(customReturnValueHandlers);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured custom return value handlers, if any.
|
||||
*/
|
||||
public List<HandlerMethodReturnValueHandler> getCustomReturnValueHandlers() {
|
||||
return this.customReturnValueHandlers;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.converter.*;
|
||||
import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
|
||||
import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||
import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
|
||||
import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler;
|
||||
@@ -40,6 +42,7 @@ import org.springframework.messaging.support.AbstractSubscribableChannel;
|
||||
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
import org.springframework.util.PathMatcher;
|
||||
import org.springframework.validation.Errors;
|
||||
@@ -213,6 +216,14 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
|
||||
handler.setMessageConverter(brokerMessageConverter());
|
||||
handler.setValidator(simpValidator());
|
||||
|
||||
List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<HandlerMethodArgumentResolver>();
|
||||
addArgumentResolvers(argumentResolvers);
|
||||
handler.setCustomArgumentResolvers(argumentResolvers);
|
||||
|
||||
List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<HandlerMethodReturnValueHandler>();
|
||||
addReturnValueHandlers(returnValueHandlers);
|
||||
handler.setCustomReturnValueHandlers(returnValueHandlers);
|
||||
|
||||
PathMatcher pathMatcher = this.getBrokerRegistry().getPathMatcher();
|
||||
if (pathMatcher != null) {
|
||||
handler.setPathMatcher(pathMatcher);
|
||||
@@ -220,6 +231,12 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
|
||||
return handler;
|
||||
}
|
||||
|
||||
protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
|
||||
}
|
||||
|
||||
protected void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AbstractBrokerMessageHandler simpleBrokerMessageHandler() {
|
||||
SimpleBrokerMessageHandler handler = getBrokerRegistry().getSimpleBroker(brokerChannel());
|
||||
|
||||
Reference in New Issue
Block a user