Example usage for org.springframework.messaging.handler.invocation HandlerMethodReturnValueHandler supportsReturnType

List of usage examples for org.springframework.messaging.handler.invocation HandlerMethodReturnValueHandler supportsReturnType

Introduction

In this page you can find the example usage for org.springframework.messaging.handler.invocation HandlerMethodReturnValueHandler supportsReturnType.

Prototype

boolean supportsReturnType(MethodParameter returnType);

Source Link

Document

Whether the given MethodParameter method return type is supported by this handler.

Usage

From source file:org.springframework.cloud.aws.messaging.listener.QueueMessageHandlerTest.java

@Test
public void receiveMessage_withCustomReturnValueHandlers_shouldCallThemBeforeTheDefaultOnes() throws Exception {
    // Arrange//  w w  w. ja  v a2s  .c o m
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.registerSingleton("incomingMessageHandler", IncomingMessageHandler.class);

    HandlerMethodReturnValueHandler handlerMethodReturnValueHandler = mock(
            HandlerMethodReturnValueHandler.class);
    when(handlerMethodReturnValueHandler.supportsReturnType(any(MethodParameter.class))).thenReturn(true);
    MutablePropertyValues properties = new MutablePropertyValues(Collections
            .singletonList(new PropertyValue("customReturnValueHandlers", handlerMethodReturnValueHandler)));
    applicationContext.registerSingleton("queueMessageHandler", QueueMessageHandler.class, properties);
    applicationContext.refresh();

    QueueMessageHandler queueMessageHandler = applicationContext.getBean(QueueMessageHandler.class);

    // Act
    queueMessageHandler.handleMessage(MessageBuilder.withPayload("Hello from a sender")
            .setHeader(QueueMessageHandler.Headers.LOGICAL_RESOURCE_ID_MESSAGE_HEADER_KEY, "receiveAndReply")
            .build());

    // Assert
    verify(handlerMethodReturnValueHandler, times(1)).handleReturnValue(any(Object.class),
            any(MethodParameter.class), any(Message.class));

}

From source file:org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandlerComposite.java

@Nullable
private HandlerMethodReturnValueHandler getReturnValueHandler(MethodParameter returnType) {
    for (HandlerMethodReturnValueHandler handler : this.returnValueHandlers) {
        if (handler.supportsReturnType(returnType)) {
            return handler;
        }//from  ww w  .  j a va 2  s  . c o  m
    }
    return null;
}