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;
}
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");
}
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());
}
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");
}
Aggregations