Search in sources :

Example 1 with HandlerMethodReturnValueHandler

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;
}
Also used : HandlerMethodReturnValueHandler(org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler) PathMatcher(org.springframework.util.PathMatcher) ArrayList(java.util.ArrayList) SimpAnnotationMethodMessageHandler(org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler) HandlerMethodArgumentResolver(org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver) Bean(org.springframework.context.annotation.Bean)

Example 2 with HandlerMethodReturnValueHandler

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;
}
Also used : HandlerMethodReturnValueHandler(org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler) ArrayList(java.util.ArrayList) ListenableFutureReturnValueHandler(org.springframework.messaging.handler.invocation.ListenableFutureReturnValueHandler) ReactiveReturnValueHandler(org.springframework.messaging.handler.invocation.ReactiveReturnValueHandler) CompletableFutureReturnValueHandler(org.springframework.messaging.handler.invocation.CompletableFutureReturnValueHandler)

Example 3 with HandlerMethodReturnValueHandler

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;
}
Also used : HandlerMethodReturnValueHandler(org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler) PathMatcher(org.springframework.util.PathMatcher) ArrayList(java.util.ArrayList) SimpAnnotationMethodMessageHandler(org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler) HandlerMethodArgumentResolver(org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver) Bean(org.springframework.context.annotation.Bean)

Example 4 with HandlerMethodReturnValueHandler

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();
}
Also used : HandlerMethodReturnValueHandler(org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) SimpAnnotationMethodMessageHandler(org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler) HandlerMethodArgumentResolver(org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver) Test(org.junit.jupiter.api.Test)

Example 5 with HandlerMethodReturnValueHandler

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();
}
Also used : HandlerMethodReturnValueHandler(org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler) SimpAnnotationMethodMessageHandler(org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler) HandlerMethodArgumentResolver(org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver) Test(org.junit.jupiter.api.Test)

Aggregations

HandlerMethodReturnValueHandler (org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler)5 HandlerMethodArgumentResolver (org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver)4 SimpAnnotationMethodMessageHandler (org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler)4 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)2 Bean (org.springframework.context.annotation.Bean)2 PathMatcher (org.springframework.util.PathMatcher)2 ApplicationContext (org.springframework.context.ApplicationContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)1 CompletableFutureReturnValueHandler (org.springframework.messaging.handler.invocation.CompletableFutureReturnValueHandler)1 ListenableFutureReturnValueHandler (org.springframework.messaging.handler.invocation.ListenableFutureReturnValueHandler)1 ReactiveReturnValueHandler (org.springframework.messaging.handler.invocation.ReactiveReturnValueHandler)1