INT-1184 added bean resolution support for expression based transformers
This commit is contained in:
@@ -43,6 +43,9 @@ public abstract class AbstractMessageProcessingTransformer implements Transforme
|
||||
|
||||
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
if (this.messageProcessor instanceof BeanFactoryAware) {
|
||||
((BeanFactoryAware) this.messageProcessor).setBeanFactory(beanFactory);
|
||||
}
|
||||
ConversionService conversionService = IntegrationContextUtils.getConversionService(beanFactory);
|
||||
if (conversionService != null && this.messageProcessor instanceof AbstractMessageProcessor) {
|
||||
((AbstractMessageProcessor) this.messageProcessor).setConversionService(conversionService);
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<channel id="input"/>
|
||||
|
||||
<channel id="output">
|
||||
<queue/>
|
||||
</channel>
|
||||
|
||||
<transformer input-channel="input" expression="payload.foo + headers.bar" output-channel="output"/>
|
||||
<transformer input-channel="simpleInput" expression="payload.foo + headers.bar" output-channel="output"/>
|
||||
|
||||
<transformer input-channel="beanResolvingInput" expression="@testBean.foo + payload.toUpperCase()" output-channel="output"/>
|
||||
|
||||
<beans:bean id="testBean" class="org.springframework.integration.transformer.SpelTransformerIntegrationTests$TestBean"/>
|
||||
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,22 +37,32 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class SpelTransformerIntegrationTests {
|
||||
|
||||
@Autowired @Qualifier("input")
|
||||
private MessageChannel input;
|
||||
@Autowired
|
||||
private MessageChannel simpleInput;
|
||||
|
||||
@Autowired
|
||||
private MessageChannel beanResolvingInput;
|
||||
|
||||
@Autowired @Qualifier("output")
|
||||
private PollableChannel output;
|
||||
|
||||
|
||||
@Test
|
||||
public void transform() {
|
||||
Message<?> message = MessageBuilder.withPayload(new TestBean())
|
||||
.setHeader("bar", 123).build();
|
||||
this.input.send(message);
|
||||
public void simple() {
|
||||
Message<?> message = MessageBuilder.withPayload(new TestBean()).setHeader("bar", 123).build();
|
||||
this.simpleInput.send(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertEquals("test123", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanResolving() {
|
||||
Message<?> message = MessageBuilder.withPayload("foo").build();
|
||||
this.beanResolvingInput.send(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertEquals("testFOO", result.getPayload());
|
||||
}
|
||||
|
||||
|
||||
static class TestBean {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user