INT-880 Added SpEL support to <header-enricher/> by including an "expression" attribute on the <header/> sub-element (to be used in place of either "value" or "ref").
This commit is contained in:
@@ -62,4 +62,12 @@
|
||||
<priority value="HIGH"/>
|
||||
</header-enricher>
|
||||
|
||||
<header-enricher input-channel="payloadExpressionInput">
|
||||
<header name="testHeader" expression="payload.name + 'bar'"/>
|
||||
</header-enricher>
|
||||
|
||||
<header-enricher input-channel="headerExpressionInput">
|
||||
<header name="testHeader2" expression="headers.testHeader1 + 'bar'"/>
|
||||
</header-enricher>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessagePriority;
|
||||
import org.springframework.integration.gateway.SimpleMessagingGateway;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.transformer.MessageTransformationException;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -115,4 +116,37 @@ public class HeaderEnricherTests {
|
||||
assertEquals(MessagePriority.HIGH, result.getHeaders().getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expressionUsingPayload() {
|
||||
SimpleMessagingGateway gateway = new SimpleMessagingGateway();
|
||||
gateway.setRequestChannel(context.getBean("payloadExpressionInput", MessageChannel.class));
|
||||
Message<?> result = gateway.sendAndReceiveMessage(new TestBean("foo"));
|
||||
assertNotNull(result);
|
||||
assertEquals("foobar", result.getHeaders().get("testHeader"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expressionUsingHeader() {
|
||||
SimpleMessagingGateway gateway = new SimpleMessagingGateway();
|
||||
gateway.setRequestChannel(context.getBean("headerExpressionInput", MessageChannel.class));
|
||||
Message<?> message = MessageBuilder.withPayload("test").setHeader("testHeader1", "foo").build();
|
||||
Message<?> result = gateway.sendAndReceiveMessage(message);
|
||||
assertNotNull(result);
|
||||
assertEquals("foobar", result.getHeaders().get("testHeader2"));
|
||||
}
|
||||
|
||||
|
||||
public static class TestBean {
|
||||
|
||||
private final String name;
|
||||
|
||||
TestBean(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user