Mail transformers may now be used within a 'chain' (INT-498).
This commit is contained in:
@@ -108,8 +108,8 @@
|
||||
|
||||
<xsd:complexType name="transformerType">
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="input-channel" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="output-channel" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="input-channel" type="xsd:string"/>
|
||||
<xsd:attribute name="output-channel" type="xsd:string"/>
|
||||
</xsd:complexType>
|
||||
|
||||
</xsd:schema>
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.mail.config;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class Exclaimer {
|
||||
|
||||
public String exclaim(String input) {
|
||||
return input.toUpperCase() + "!!!";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.mail.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.easymock.classextension.EasyMock;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MailToStringTransformerParserTests {
|
||||
|
||||
@Test
|
||||
public void topLevelTransformer() throws Exception {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"mailToStringTransformerParserTests.xml", this.getClass());
|
||||
MessageChannel input = new BeanFactoryChannelResolver(context).resolveChannelName("input");
|
||||
PollableChannel output = (PollableChannel) new BeanFactoryChannelResolver(context).resolveChannelName("output");
|
||||
MimeMessage mimeMessage = EasyMock.createNiceMock(MimeMessage.class);
|
||||
EasyMock.expect(mimeMessage.getContent()).andReturn("hello");
|
||||
EasyMock.replay(mimeMessage);
|
||||
input.send(new GenericMessage<javax.mail.Message>(mimeMessage));
|
||||
Message<?> result = output.receive(0);
|
||||
assertNotNull(result);
|
||||
assertEquals("hello", result.getPayload());
|
||||
EasyMock.verify(mimeMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transformerWithinChain() throws Exception {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"mailToStringTransformerWithinChain.xml", this.getClass());
|
||||
MessageChannel input = new BeanFactoryChannelResolver(context).resolveChannelName("input");
|
||||
PollableChannel output = (PollableChannel) new BeanFactoryChannelResolver(context).resolveChannelName("output");
|
||||
MimeMessage mimeMessage = EasyMock.createNiceMock(MimeMessage.class);
|
||||
EasyMock.expect(mimeMessage.getContent()).andReturn("foo");
|
||||
EasyMock.replay(mimeMessage);
|
||||
input.send(new GenericMessage<javax.mail.Message>(mimeMessage));
|
||||
Message<?> result = output.receive(0);
|
||||
assertNotNull(result);
|
||||
assertEquals("FOO!!!", result.getPayload());
|
||||
EasyMock.verify(mimeMessage);
|
||||
}
|
||||
|
||||
@Test(expected = BeanDefinitionStoreException.class)
|
||||
public void topLevelTransformerMissingInput() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("mailToStringTransformerWithoutInputChannel.xml", this.getClass());
|
||||
}
|
||||
catch (BeanDefinitionStoreException e) {
|
||||
assertTrue(e.getMessage().contains("input-channel"));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration/mail"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:integration="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
|
||||
http://www.springframework.org/schema/integration/mail
|
||||
http://www.springframework.org/schema/integration/mail/spring-integration-mail-1.0.xsd">
|
||||
|
||||
<integration:channel id="input"/>
|
||||
|
||||
<integration:channel id="output">
|
||||
<integration:queue capacity="1"/>
|
||||
</integration:channel>
|
||||
|
||||
<mail-to-string-transformer input-channel="input" output-channel="output"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration/mail"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:integration="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
|
||||
http://www.springframework.org/schema/integration/mail
|
||||
http://www.springframework.org/schema/integration/mail/spring-integration-mail-1.0.xsd">
|
||||
|
||||
<integration:channel id="input"/>
|
||||
|
||||
<integration:channel id="output">
|
||||
<integration:queue capacity="1"/>
|
||||
</integration:channel>
|
||||
|
||||
<integration:chain id="chain" input-channel="input" output-channel="output">
|
||||
<mail-to-string-transformer/>
|
||||
<integration:service-activator ref="exclaimer"/>
|
||||
</integration:chain>
|
||||
|
||||
<beans:bean id="exclaimer" class="org.springframework.integration.mail.config.Exclaimer"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration/mail"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:integration="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
|
||||
http://www.springframework.org/schema/integration/mail
|
||||
http://www.springframework.org/schema/integration/mail/spring-integration-mail-1.0.xsd">
|
||||
|
||||
<integration:channel id="output">
|
||||
<integration:queue capacity="1"/>
|
||||
</integration:channel>
|
||||
|
||||
<mail-to-string-transformer output-channel="output"/>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user