Search in sources :

Example 1 with MessageTransformingHandler

use of org.springframework.integration.transformer.MessageTransformingHandler 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());
}
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)

Example 2 with MessageTransformingHandler

use of org.springframework.integration.transformer.MessageTransformingHandler 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"));
}
Also used : 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)

Example 3 with MessageTransformingHandler

use of org.springframework.integration.transformer.MessageTransformingHandler 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"));
}
Also used : 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)

Example 4 with MessageTransformingHandler

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

the class TransformerFactoryBean method createExpressionEvaluatingHandler.

@Override
protected MessageHandler createExpressionEvaluatingHandler(Expression expression) {
    Transformer transformer = new ExpressionEvaluatingTransformer(expression);
    MessageTransformingHandler handler = this.createHandler(transformer);
    handler.setPrimaryExpression(expression);
    return handler;
}
Also used : ExpressionEvaluatingTransformer(org.springframework.integration.transformer.ExpressionEvaluatingTransformer) MessageTransformingHandler(org.springframework.integration.transformer.MessageTransformingHandler) ExpressionEvaluatingTransformer(org.springframework.integration.transformer.ExpressionEvaluatingTransformer) MethodInvokingTransformer(org.springframework.integration.transformer.MethodInvokingTransformer) Transformer(org.springframework.integration.transformer.Transformer)

Example 5 with MessageTransformingHandler

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

the class TransformerFactoryBean method createHandler.

protected MessageTransformingHandler createHandler(Transformer transformer) {
    MessageTransformingHandler handler = new MessageTransformingHandler(transformer);
    this.postProcessReplyProducer(handler);
    return handler;
}
Also used : MessageTransformingHandler(org.springframework.integration.transformer.MessageTransformingHandler)

Aggregations

MessageTransformingHandler (org.springframework.integration.transformer.MessageTransformingHandler)13 Test (org.junit.Test)8 MethodInvokingTransformer (org.springframework.integration.transformer.MethodInvokingTransformer)8 BeanFactory (org.springframework.beans.factory.BeanFactory)5 QueueChannel (org.springframework.integration.channel.QueueChannel)5 Transformer (org.springframework.integration.transformer.Transformer)4 Bean (org.springframework.context.annotation.Bean)2 Transformer (org.springframework.integration.annotation.Transformer)2 Channel (com.rabbitmq.client.Channel)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 CoreMatchers.instanceOf (org.hamcrest.CoreMatchers.instanceOf)1 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertNotEquals (org.junit.Assert.assertNotEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1