use of org.springframework.integration.transformer.MessageTransformingHandler in project spring-integration by spring-projects.
the class TransformerAnnotationPostProcessor method createHandler.
@Override
protected MessageHandler createHandler(Object bean, Method method, List<Annotation> annotations) {
org.springframework.integration.transformer.Transformer transformer;
if (AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
Object target = this.resolveTargetBeanFromMethodWithBeanAnnotation(method);
transformer = this.extractTypeIfPossible(target, org.springframework.integration.transformer.Transformer.class);
if (transformer == null) {
if (this.extractTypeIfPossible(target, AbstractReplyProducingMessageHandler.class) != null) {
checkMessageHandlerAttributes(resolveTargetBeanName(method), annotations);
return (MessageHandler) target;
}
transformer = new MethodInvokingTransformer(target);
}
} else {
transformer = new MethodInvokingTransformer(bean, method);
}
MessageTransformingHandler handler = new MessageTransformingHandler(transformer);
this.setOutputChannelIfPresent(annotations, handler);
return handler;
}
use of org.springframework.integration.transformer.MessageTransformingHandler in project spring-integration by spring-projects.
the class IntegrationFlowDefinition method transform.
/**
* Populate the {@link MessageTransformingHandler} instance for the provided {@link GenericTransformer}
* for the specific {@code payloadType} to convert at runtime.
* In addition accept options for the integration endpoint using {@link GenericEndpointSpec}.
* @param payloadType the {@link Class} for expected payload type.
* @param genericTransformer the {@link GenericTransformer} to populate.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
* @param <P> the payload type - 'transform from'.
* @param <T> the target type - 'transform to'.
* @return the current {@link IntegrationFlowDefinition}.
* @see MethodInvokingTransformer
* @see LambdaMessageProcessor
* @see GenericEndpointSpec
*/
public <P, T> B transform(Class<P> payloadType, GenericTransformer<P, T> genericTransformer, Consumer<GenericEndpointSpec<MessageTransformingHandler>> endpointConfigurer) {
Assert.notNull(genericTransformer, "'genericTransformer' must not be null");
Transformer transformer = genericTransformer instanceof Transformer ? (Transformer) genericTransformer : (isLambda(genericTransformer) ? new MethodInvokingTransformer(new LambdaMessageProcessor(genericTransformer, payloadType)) : new MethodInvokingTransformer(genericTransformer));
return addComponent(transformer).handle(new MessageTransformingHandler(transformer), endpointConfigurer);
}
use of org.springframework.integration.transformer.MessageTransformingHandler in project spring-integration by spring-projects.
the class HeaderAnnotationTransformerTests method headerAnnotationWithPrefixedHeaderAndRelativeExpression.
// INT-1082
@Test
public void headerAnnotationWithPrefixedHeaderAndRelativeExpression() {
Object target = new TestTransformer();
MethodInvokingTransformer transformer = new MethodInvokingTransformer(target, "evalCorrelationId");
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("ABC", result.getPayload());
assertEquals("abc", new IntegrationMessageHeaderAccessor(result).getCorrelationId());
}
Aggregations