use of org.springframework.integration.endpoint.MethodInvokingMessageSource in project spring-integration by spring-projects.
the class MethodInvokingMessageSourceTests method testHeaderExpressions.
@Test
public void testHeaderExpressions() {
Map<String, Expression> headerExpressions = new HashMap<String, Expression>();
headerExpressions.put("foo", new LiteralExpression("abc"));
headerExpressions.put("bar", new SpelExpressionParser().parseExpression("new Integer(123)"));
MethodInvokingMessageSource source = new MethodInvokingMessageSource();
source.setBeanFactory(mock(BeanFactory.class));
source.setObject(new TestBean());
source.setMethodName("validMethod");
source.setHeaderExpressions(headerExpressions);
Message<?> result = source.receive();
assertNotNull(result);
assertNotNull(result.getPayload());
assertEquals("valid", result.getPayload());
assertEquals("abc", result.getHeaders().get("foo"));
assertEquals(123, result.getHeaders().get("bar"));
}
use of org.springframework.integration.endpoint.MethodInvokingMessageSource in project spring-integration by spring-projects.
the class MethodInvokingMessageSourceTests method testValidMethod.
@Test
public void testValidMethod() {
MethodInvokingMessageSource source = new MethodInvokingMessageSource();
source.setBeanFactory(mock(BeanFactory.class));
source.setObject(new TestBean());
source.setMethodName("validMethod");
Message<?> result = source.receive();
assertNotNull(result);
assertNotNull(result.getPayload());
assertEquals("valid", result.getPayload());
}
use of org.springframework.integration.endpoint.MethodInvokingMessageSource in project spring-integration by spring-projects.
the class InboundChannelAdapterAnnotationPostProcessor method createMessageSource.
private MessageSource<?> createMessageSource(Object bean, String beanName, Method method) {
MessageSource<?> messageSource = null;
if (AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
Object target = this.resolveTargetBeanFromMethodWithBeanAnnotation(method);
Assert.isTrue(target instanceof MessageSource || target instanceof Supplier, "The '" + this.annotationType + "' on @Bean method " + "level is allowed only for: " + MessageSource.class.getName() + " or " + Supplier.class.getName() + " beans");
if (target instanceof MessageSource<?>) {
messageSource = (MessageSource<?>) target;
} else {
method = ReflectionUtils.findMethod(Supplier.class, "get");
bean = target;
}
}
if (messageSource == null) {
MethodInvokingMessageSource methodInvokingMessageSource = new MethodInvokingMessageSource();
methodInvokingMessageSource.setObject(bean);
methodInvokingMessageSource.setMethod(method);
String messageSourceBeanName = this.generateHandlerBeanName(beanName, method);
this.beanFactory.registerSingleton(messageSourceBeanName, methodInvokingMessageSource);
messageSource = (MessageSource<?>) this.beanFactory.initializeBean(methodInvokingMessageSource, messageSourceBeanName);
}
return messageSource;
}
Aggregations