Search in sources :

Example 6 with MethodInvokingTransformer

use of org.springframework.integration.transformer.MethodInvokingTransformer in project spring-integration-samples by spring-projects.

the class DBoot method transform.

@Transformer(inputChannel = "foo")
@Bean
public MessageHandler transform() {
    MessageTransformingHandler transformingHandler = new MessageTransformingHandler(new MethodInvokingTransformer(helpers(), "duplicate"));
    transformingHandler.setOutputChannel(bar());
    return transformingHandler;
}
Also used : MessageTransformingHandler(org.springframework.integration.transformer.MessageTransformingHandler) MethodInvokingTransformer(org.springframework.integration.transformer.MethodInvokingTransformer) MethodInvokingTransformer(org.springframework.integration.transformer.MethodInvokingTransformer) Transformer(org.springframework.integration.annotation.Transformer) Bean(org.springframework.context.annotation.Bean)

Example 7 with MethodInvokingTransformer

use of org.springframework.integration.transformer.MethodInvokingTransformer 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;
}
Also used : MessageTransformingHandler(org.springframework.integration.transformer.MessageTransformingHandler) MethodInvokingTransformer(org.springframework.integration.transformer.MethodInvokingTransformer) Transformer(org.springframework.integration.annotation.Transformer) MessageHandler(org.springframework.messaging.MessageHandler) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) MethodInvokingTransformer(org.springframework.integration.transformer.MethodInvokingTransformer) Bean(org.springframework.context.annotation.Bean)

Example 8 with MethodInvokingTransformer

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 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);
}
Also used : LambdaMessageProcessor(org.springframework.integration.handler.LambdaMessageProcessor) MessageTransformingHandler(org.springframework.integration.transformer.MessageTransformingHandler) Transformer(org.springframework.integration.transformer.Transformer) MethodInvokingTransformer(org.springframework.integration.transformer.MethodInvokingTransformer) ClaimCheckOutTransformer(org.springframework.integration.transformer.ClaimCheckOutTransformer) GenericTransformer(org.springframework.integration.transformer.GenericTransformer) ExpressionEvaluatingTransformer(org.springframework.integration.transformer.ExpressionEvaluatingTransformer) ClaimCheckInTransformer(org.springframework.integration.transformer.ClaimCheckInTransformer) MethodInvokingTransformer(org.springframework.integration.transformer.MethodInvokingTransformer)

Example 9 with MethodInvokingTransformer

use of org.springframework.integration.transformer.MethodInvokingTransformer 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());
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MessageTransformingHandler(org.springframework.integration.transformer.MessageTransformingHandler) QueueChannel(org.springframework.integration.channel.QueueChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) MethodInvokingTransformer(org.springframework.integration.transformer.MethodInvokingTransformer) Test(org.junit.Test)

Aggregations

MethodInvokingTransformer (org.springframework.integration.transformer.MethodInvokingTransformer)9 MessageTransformingHandler (org.springframework.integration.transformer.MessageTransformingHandler)7 Test (org.junit.Test)4 BeanFactory (org.springframework.beans.factory.BeanFactory)4 QueueChannel (org.springframework.integration.channel.QueueChannel)4 Bean (org.springframework.context.annotation.Bean)2 IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)2 Transformer (org.springframework.integration.annotation.Transformer)2 ExpressionEvaluatingTransformer (org.springframework.integration.transformer.ExpressionEvaluatingTransformer)2 Transformer (org.springframework.integration.transformer.Transformer)2 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)1 LambdaMessageProcessor (org.springframework.integration.handler.LambdaMessageProcessor)1 ClaimCheckInTransformer (org.springframework.integration.transformer.ClaimCheckInTransformer)1 ClaimCheckOutTransformer (org.springframework.integration.transformer.ClaimCheckOutTransformer)1 GenericTransformer (org.springframework.integration.transformer.GenericTransformer)1 MessageHandler (org.springframework.messaging.MessageHandler)1