use of org.springframework.integration.transformer.MethodInvokingTransformer in project spring-integration by spring-projects.
the class HeaderAnnotationTransformerTests method headerAnnotationWithPrefixedHeader.
// INT-1082
@Test
public void headerAnnotationWithPrefixedHeader() {
Object target = new TestTransformer();
MethodInvokingTransformer transformer = new MethodInvokingTransformer(target, "appendCorrelationId");
MessageTransformingHandler handler = new MessageTransformingHandler(transformer);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
QueueChannel outputChannel = new QueueChannel();
handler.setOutputChannel(outputChannel);
handler.handleMessage(MessageBuilder.withPayload("test").setCorrelationId("abc").build());
Message<?> result = outputChannel.receive(0);
assertNotNull(result);
assertEquals("testabc", result.getPayload());
assertEquals("abc", new IntegrationMessageHeaderAccessor(result).getCorrelationId());
}
use of org.springframework.integration.transformer.MethodInvokingTransformer in project spring-integration by spring-projects.
the class HeaderAnnotationTransformerTests method headerAnnotationWithUnprefixedHeader.
@Test
public void headerAnnotationWithUnprefixedHeader() {
Object target = new TestTransformer();
MethodInvokingTransformer transformer = new MethodInvokingTransformer(target, "appendFoo");
MessageTransformingHandler handler = new MessageTransformingHandler(transformer);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
QueueChannel outputChannel = new QueueChannel();
handler.setOutputChannel(outputChannel);
handler.handleMessage(MessageBuilder.withPayload("test").setHeader("foo", "bar").build());
Message<?> result = outputChannel.receive(0);
assertNotNull(result);
assertEquals("testbar", result.getPayload());
assertEquals("bar", result.getHeaders().get("foo"));
}
use of org.springframework.integration.transformer.MethodInvokingTransformer in project spring-integration by spring-projects.
the class HeaderAnnotationTransformerTests method headerAnnotationWithUnprefixedHeaderAndRelativeExpression.
@Test
public void headerAnnotationWithUnprefixedHeaderAndRelativeExpression() {
Object target = new TestTransformer();
MethodInvokingTransformer transformer = new MethodInvokingTransformer(target, "evalFoo");
MessageTransformingHandler handler = new MessageTransformingHandler(transformer);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
QueueChannel outputChannel = new QueueChannel();
handler.setOutputChannel(outputChannel);
handler.handleMessage(MessageBuilder.withPayload("test").setHeader("foo", "bar").build());
Message<?> result = outputChannel.receive(0);
assertNotNull(result);
assertEquals("BAR", result.getPayload());
assertEquals("bar", result.getHeaders().get("foo"));
}
use of org.springframework.integration.transformer.MethodInvokingTransformer in project spring-integration by spring-projects.
the class TransformerFactoryBean method createMethodInvokingHandler.
@Override
protected MessageHandler createMethodInvokingHandler(Object targetObject, String targetMethodName) {
Assert.notNull(targetObject, "targetObject must not be null");
Transformer transformer = null;
if (targetObject instanceof Transformer) {
transformer = (Transformer) targetObject;
} else {
this.checkForIllegalTarget(targetObject, targetMethodName);
if (StringUtils.hasText(targetMethodName)) {
transformer = new MethodInvokingTransformer(targetObject, targetMethodName);
} else {
transformer = new MethodInvokingTransformer(targetObject);
}
}
return this.createHandler(transformer);
}
use of org.springframework.integration.transformer.MethodInvokingTransformer in project spring-integration by spring-projects.
the class IntegrationFlowDefinition method transform.
/**
* Populate the {@link MessageTransformingHandler} instance for the
* {@link org.springframework.integration.handler.MessageProcessor} from provided {@link MessageProcessorSpec}.
* In addition accept options for the integration endpoint using {@link GenericEndpointSpec}.
* <pre class="code">
* {@code
* .transform(Scripts.script("classpath:myScript.py").variable("foo", bar()),
* e -> e.autoStartup(false))
* }
* </pre>
* @param messageProcessorSpec the {@link MessageProcessorSpec} to use.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
* @return the current {@link IntegrationFlowDefinition}.
* @see MethodInvokingTransformer
*/
public B transform(MessageProcessorSpec<?> messageProcessorSpec, Consumer<GenericEndpointSpec<MessageTransformingHandler>> endpointConfigurer) {
Assert.notNull(messageProcessorSpec, "'messageProcessorSpec' must not be null");
MessageProcessor<?> processor = messageProcessorSpec.get();
return addComponent(processor).transform(new MethodInvokingTransformer(processor), endpointConfigurer);
}
Aggregations