Search in sources :

Example 6 with InvocableHandlerMethod

use of org.springframework.messaging.handler.invocation.InvocableHandlerMethod in project spring-framework by spring-projects.

the class MethodJmsListenerEndpoint method createMessageListener.

@Override
protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) {
    Assert.state(this.messageHandlerMethodFactory != null, "Could not create message listener - MessageHandlerMethodFactory not set");
    MessagingMessageListenerAdapter messageListener = createMessageListenerInstance();
    InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod());
    messageListener.setHandlerMethod(invocableHandlerMethod);
    String responseDestination = getDefaultResponseDestination();
    if (StringUtils.hasText(responseDestination)) {
        if (container.isReplyPubSubDomain()) {
            messageListener.setDefaultResponseTopicName(responseDestination);
        } else {
            messageListener.setDefaultResponseQueueName(responseDestination);
        }
    }
    MessageConverter messageConverter = container.getMessageConverter();
    if (messageConverter != null) {
        messageListener.setMessageConverter(messageConverter);
    }
    DestinationResolver destinationResolver = container.getDestinationResolver();
    if (destinationResolver != null) {
        messageListener.setDestinationResolver(destinationResolver);
    }
    return messageListener;
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) InvocableHandlerMethod(org.springframework.messaging.handler.invocation.InvocableHandlerMethod) MessageConverter(org.springframework.jms.support.converter.MessageConverter)

Example 7 with InvocableHandlerMethod

use of org.springframework.messaging.handler.invocation.InvocableHandlerMethod in project spring-framework by spring-projects.

the class DefaultMessageHandlerMethodFactoryTests method customArgumentResolver.

@Test
public void customArgumentResolver() throws Exception {
    DefaultMessageHandlerMethodFactory instance = createInstance();
    List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>();
    customResolvers.add(new CustomHandlerMethodArgumentResolver());
    instance.setCustomArgumentResolvers(customResolvers);
    instance.afterPropertiesSet();
    InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "customArgumentResolver", Locale.class);
    invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build());
    assertMethodInvocation(sample, "customArgumentResolver");
}
Also used : InvocableHandlerMethod(org.springframework.messaging.handler.invocation.InvocableHandlerMethod) ArrayList(java.util.ArrayList) HandlerMethodArgumentResolver(org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver) Test(org.junit.Test)

Example 8 with InvocableHandlerMethod

use of org.springframework.messaging.handler.invocation.InvocableHandlerMethod in project spring-framework by spring-projects.

the class DefaultMessageHandlerMethodFactoryTests method customValidation.

@Test
public void customValidation() throws Exception {
    DefaultMessageHandlerMethodFactory instance = createInstance();
    instance.setValidator(new Validator() {

        @Override
        public boolean supports(Class<?> clazz) {
            return String.class.isAssignableFrom(clazz);
        }

        @Override
        public void validate(Object target, Errors errors) {
            String value = (String) target;
            if ("failure".equals(value)) {
                errors.reject("not a valid value");
            }
        }
    });
    instance.afterPropertiesSet();
    InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "payloadValidation", String.class);
    thrown.expect(MethodArgumentNotValidException.class);
    invocableHandlerMethod.invoke(MessageBuilder.withPayload("failure").build());
}
Also used : Errors(org.springframework.validation.Errors) InvocableHandlerMethod(org.springframework.messaging.handler.invocation.InvocableHandlerMethod) Validator(org.springframework.validation.Validator) Test(org.junit.Test)

Example 9 with InvocableHandlerMethod

use of org.springframework.messaging.handler.invocation.InvocableHandlerMethod in project spring-framework by spring-projects.

the class DefaultMessageHandlerMethodFactoryTests method noValidationByDefault.

@Test
public void noValidationByDefault() throws Exception {
    DefaultMessageHandlerMethodFactory instance = createInstance();
    instance.afterPropertiesSet();
    InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "payloadValidation", String.class);
    invocableHandlerMethod.invoke(MessageBuilder.withPayload("failure").build());
    assertMethodInvocation(sample, "payloadValidation");
}
Also used : InvocableHandlerMethod(org.springframework.messaging.handler.invocation.InvocableHandlerMethod) Test(org.junit.Test)

Aggregations

InvocableHandlerMethod (org.springframework.messaging.handler.invocation.InvocableHandlerMethod)9 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)2 GenericConversionService (org.springframework.core.convert.support.GenericConversionService)2 HandlerMethodArgumentResolver (org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver)2 MessagingMessageListenerAdapter (org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter)1 MessageConverter (org.springframework.jms.support.converter.MessageConverter)1 DestinationResolver (org.springframework.jms.support.destination.DestinationResolver)1 ByteArrayMessageConverter (org.springframework.messaging.converter.ByteArrayMessageConverter)1 MessageConverter (org.springframework.messaging.converter.MessageConverter)1 Errors (org.springframework.validation.Errors)1 Validator (org.springframework.validation.Validator)1