use of org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler in project spring-framework by spring-projects.
the class AbstractMessageBrokerConfiguration method simpAnnotationMethodMessageHandler.
@Bean
public SimpAnnotationMethodMessageHandler simpAnnotationMethodMessageHandler() {
SimpAnnotationMethodMessageHandler handler = createAnnotationMethodMessageHandler();
handler.setDestinationPrefixes(getBrokerRegistry().getApplicationDestinationPrefixes());
handler.setMessageConverter(brokerMessageConverter());
handler.setValidator(simpValidator());
List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
addArgumentResolvers(argumentResolvers);
handler.setCustomArgumentResolvers(argumentResolvers);
List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<>();
addReturnValueHandlers(returnValueHandlers);
handler.setCustomReturnValueHandlers(returnValueHandlers);
PathMatcher pathMatcher = getBrokerRegistry().getPathMatcher();
if (pathMatcher != null) {
handler.setPathMatcher(pathMatcher);
}
return handler;
}
use of org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler in project spring-framework by spring-projects.
the class SimpAnnotationMethodMessageHandler method initReturnValueHandlers.
@Override
protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers() {
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>();
// Single-purpose return value types
handlers.add(new ListenableFutureReturnValueHandler());
handlers.add(new CompletableFutureReturnValueHandler());
if (reactorPresent) {
handlers.add(new ReactiveReturnValueHandler());
}
// Annotation-based return value types
SendToMethodReturnValueHandler sendToHandler = new SendToMethodReturnValueHandler(this.brokerTemplate, true);
sendToHandler.setHeaderInitializer(this.headerInitializer);
handlers.add(sendToHandler);
SubscriptionMethodReturnValueHandler subscriptionHandler = new SubscriptionMethodReturnValueHandler(this.clientMessagingTemplate);
subscriptionHandler.setHeaderInitializer(this.headerInitializer);
handlers.add(subscriptionHandler);
// Custom return value types
handlers.addAll(getCustomReturnValueHandlers());
// Catch-all
sendToHandler = new SendToMethodReturnValueHandler(this.brokerTemplate, false);
sendToHandler.setHeaderInitializer(this.headerInitializer);
handlers.add(sendToHandler);
return handlers;
}
use of org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler in project spring-framework by spring-projects.
the class AbstractMessageBrokerConfiguration method simpAnnotationMethodMessageHandler.
@Bean
public SimpAnnotationMethodMessageHandler simpAnnotationMethodMessageHandler(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, SimpMessagingTemplate brokerMessagingTemplate, CompositeMessageConverter brokerMessageConverter) {
SimpAnnotationMethodMessageHandler handler = createAnnotationMethodMessageHandler(clientInboundChannel, clientOutboundChannel, brokerMessagingTemplate);
MessageBrokerRegistry brokerRegistry = getBrokerRegistry(clientInboundChannel, clientOutboundChannel);
handler.setDestinationPrefixes(brokerRegistry.getApplicationDestinationPrefixes());
handler.setMessageConverter(brokerMessageConverter);
handler.setValidator(simpValidator());
List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
addArgumentResolvers(argumentResolvers);
handler.setCustomArgumentResolvers(argumentResolvers);
List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<>();
addReturnValueHandlers(returnValueHandlers);
handler.setCustomReturnValueHandlers(returnValueHandlers);
PathMatcher pathMatcher = brokerRegistry.getPathMatcher();
if (pathMatcher != null) {
handler.setPathMatcher(pathMatcher);
}
return handler;
}
use of org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler in project spring-framework by spring-projects.
the class MessageBrokerConfigurationTests method customArgumentAndReturnValueTypes.
@Test
public void customArgumentAndReturnValueTypes() {
ApplicationContext context = loadConfig(CustomConfig.class);
SimpAnnotationMethodMessageHandler handler = context.getBean(SimpAnnotationMethodMessageHandler.class);
List<HandlerMethodArgumentResolver> customResolvers = handler.getCustomArgumentResolvers();
assertThat(customResolvers.size()).isEqualTo(1);
assertThat(handler.getArgumentResolvers().contains(customResolvers.get(0))).isTrue();
List<HandlerMethodReturnValueHandler> customHandlers = handler.getCustomReturnValueHandlers();
assertThat(customHandlers.size()).isEqualTo(1);
assertThat(handler.getReturnValueHandlers().contains(customHandlers.get(0))).isTrue();
}
use of org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler in project spring-framework by spring-projects.
the class TestValidator method customArgumentAndReturnValueTypes.
@Test
public void customArgumentAndReturnValueTypes() {
loadBeanDefinitions("websocket-config-broker-custom-argument-and-return-value-types.xml");
SimpAnnotationMethodMessageHandler handler = this.appContext.getBean(SimpAnnotationMethodMessageHandler.class);
List<HandlerMethodArgumentResolver> customResolvers = handler.getCustomArgumentResolvers();
assertThat(customResolvers.size()).isEqualTo(2);
assertThat(handler.getArgumentResolvers().contains(customResolvers.get(0))).isTrue();
assertThat(handler.getArgumentResolvers().contains(customResolvers.get(1))).isTrue();
List<HandlerMethodReturnValueHandler> customHandlers = handler.getCustomReturnValueHandlers();
assertThat(customHandlers.size()).isEqualTo(2);
assertThat(handler.getReturnValueHandlers().contains(customHandlers.get(0))).isTrue();
assertThat(handler.getReturnValueHandlers().contains(customHandlers.get(1))).isTrue();
}
Aggregations