INT-701 Added support for the 'auto-startup' attribute on the 'imap-idle-channel-adapter' element.
This commit is contained in:
@@ -22,8 +22,6 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.mail.ImapIdleChannelAdapter;
|
||||
import org.springframework.integration.mail.ImapMailReceiver;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -35,8 +33,11 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class ImapIdleChannelAdapterParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return ImapIdleChannelAdapter.class;
|
||||
private static final String BASE_PACKAGE = "org.springframework.integration.mail";
|
||||
|
||||
|
||||
protected String getBeanClassName(Element element) {
|
||||
return BASE_PACKAGE + ".ImapIdleChannelAdapter";
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateId() {
|
||||
@@ -56,12 +57,17 @@ public class ImapIdleChannelAdapterParser extends AbstractSingleBeanDefinitionPa
|
||||
if (StringUtils.hasText(taskExecutorRef)) {
|
||||
builder.addPropertyReference("taskExecutor", taskExecutorRef);
|
||||
}
|
||||
String autoStartup = element.getAttribute("auto-startup");
|
||||
if (StringUtils.hasText(autoStartup)) {
|
||||
builder.addPropertyValue("autoStartup", autoStartup);
|
||||
}
|
||||
}
|
||||
|
||||
private String parseImapMailReceiver(Element element, ParserContext parserContext) {
|
||||
String uri = element.getAttribute("store-uri");
|
||||
Assert.hasText(uri, "the 'store-uri' attribute is required");
|
||||
BeanDefinitionBuilder receiverBuilder = BeanDefinitionBuilder.genericBeanDefinition(ImapMailReceiver.class);
|
||||
BeanDefinitionBuilder receiverBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
BASE_PACKAGE + ".ImapMailReceiver");
|
||||
receiverBuilder.addConstructorArgValue(uri);
|
||||
String propertiesRef = element.getAttribute("java-mail-properties");
|
||||
if (StringUtils.hasText(propertiesRef)) {
|
||||
|
||||
@@ -130,7 +130,14 @@
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="should-delete-messages" type="xsd:string"/>
|
||||
<xsd:attribute name="should-delete-messages" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specify whether mail messages should be deleted after retrieval. The default is TRUE.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="auto-startup" type="xsd:string"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:mail="http://www.springframework.org/schema/integration/mail"
|
||||
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/util
|
||||
http://www.springframework.org/schema/util/spring-util-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="channel"/>
|
||||
|
||||
<mail:imap-idle-channel-adapter id="simpleAdapter"
|
||||
store-uri="imap:foo"
|
||||
channel="channel"
|
||||
auto-startup="false"/>
|
||||
|
||||
<mail:imap-idle-channel-adapter id="customAdapter"
|
||||
store-uri="imap:foo"
|
||||
channel="channel"
|
||||
auto-startup="false"
|
||||
java-mail-properties="props"
|
||||
should-delete-messages="false"
|
||||
task-executor="executor"/>
|
||||
|
||||
<util:properties id="props">
|
||||
<prop key="foo">bar</prop>
|
||||
</util:properties>
|
||||
|
||||
<integration:thread-pool-task-executor id="executor" max-size="5"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2002-2009 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.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.URLName;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.mail.ImapIdleChannelAdapter;
|
||||
import org.springframework.integration.mail.ImapMailReceiver;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class ImapIdleChannelAdapterParserTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
|
||||
@Test
|
||||
public void simpleAdapter() {
|
||||
Object adapter = context.getBean("simpleAdapter");
|
||||
assertEquals(ImapIdleChannelAdapter.class, adapter.getClass());
|
||||
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
|
||||
Object channel = context.getBean("channel");
|
||||
assertSame(channel, adapterAccessor.getPropertyValue("outputChannel"));
|
||||
assertNull(adapterAccessor.getPropertyValue("taskExecutor"));
|
||||
assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup"));
|
||||
Object receiver = adapterAccessor.getPropertyValue("mailReceiver");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
DirectFieldAccessor receiverAccessor = new DirectFieldAccessor(receiver);
|
||||
Object url = receiverAccessor.getPropertyValue("url");
|
||||
assertEquals(new URLName("imap:foo"), url);
|
||||
Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
|
||||
assertEquals(0, properties.size());
|
||||
assertEquals(Boolean.TRUE, receiverAccessor.getPropertyValue("shouldDeleteMessages"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customAdapter() {
|
||||
Object adapter = context.getBean("customAdapter");
|
||||
assertEquals(ImapIdleChannelAdapter.class, adapter.getClass());
|
||||
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
|
||||
Object channel = context.getBean("channel");
|
||||
Object executor = context.getBean("executor");
|
||||
assertSame(channel, adapterAccessor.getPropertyValue("outputChannel"));
|
||||
assertSame(executor, adapterAccessor.getPropertyValue("taskExecutor"));
|
||||
assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup"));
|
||||
Object receiver = adapterAccessor.getPropertyValue("mailReceiver");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
DirectFieldAccessor receiverAccessor = new DirectFieldAccessor(receiver);
|
||||
Object url = receiverAccessor.getPropertyValue("url");
|
||||
assertEquals(new URLName("imap:foo"), url);
|
||||
Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
|
||||
assertEquals("bar", properties.getProperty("foo"));
|
||||
assertEquals(Boolean.FALSE, receiverAccessor.getPropertyValue("shouldDeleteMessages"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:mail="http://www.springframework.org/schema/integration/mail"
|
||||
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/util
|
||||
http://www.springframework.org/schema/util/spring-util-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="channel"/>
|
||||
|
||||
<mail:inbound-channel-adapter id="imapAdapter"
|
||||
store-uri="imap:foo" java-mail-properties="props" channel="channel" auto-startup="false"/>
|
||||
|
||||
<mail:inbound-channel-adapter id="pop3Adapter"
|
||||
store-uri="pop3:bar" java-mail-properties="props" channel="channel" auto-startup="false"/>
|
||||
|
||||
<util:properties id="props">
|
||||
<prop key="foo">bar</prop>
|
||||
</util:properties>
|
||||
|
||||
<integration:poller default="true">
|
||||
<integration:interval-trigger interval="60" time-unit="SECONDS"/>
|
||||
</integration:poller>
|
||||
|
||||
</beans>
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -16,20 +16,73 @@
|
||||
|
||||
package org.springframework.integration.mail.config;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.URLName;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
import org.springframework.integration.mail.ImapMailReceiver;
|
||||
import org.springframework.integration.mail.MailReceivingMessageSource;
|
||||
import org.springframework.integration.mail.Pop3MailReceiver;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Jonas Partner
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class PollingMailSourceParserTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
|
||||
@Test
|
||||
public void testPop3(){
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("pollingMailSourceParserTests.xml", PollingMailSourceParserTests.class);
|
||||
context.getBean("pollingPop3");
|
||||
public void imapAdapter() {
|
||||
Object adapter = context.getBean("imapAdapter");
|
||||
assertEquals(SourcePollingChannelAdapter.class, adapter.getClass());
|
||||
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
|
||||
assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup"));
|
||||
Object channel = context.getBean("channel");
|
||||
assertEquals(channel, adapterAccessor.getPropertyValue("outputChannel"));
|
||||
Object source = adapterAccessor.getPropertyValue("source");
|
||||
assertEquals(MailReceivingMessageSource.class, source.getClass());
|
||||
Object receiver = new DirectFieldAccessor(source).getPropertyValue("mailReceiver");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
DirectFieldAccessor receiverAccessor = new DirectFieldAccessor(receiver);
|
||||
Object url = receiverAccessor.getPropertyValue("url");
|
||||
assertEquals(new URLName("imap:foo"), url);
|
||||
Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
|
||||
assertEquals("bar", properties.getProperty("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pop3Adapter() {
|
||||
Object adapter = context.getBean("pop3Adapter");
|
||||
assertEquals(SourcePollingChannelAdapter.class, adapter.getClass());
|
||||
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
|
||||
assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup"));
|
||||
Object channel = context.getBean("channel");
|
||||
assertEquals(channel, adapterAccessor.getPropertyValue("outputChannel"));
|
||||
Object source = adapterAccessor.getPropertyValue("source");
|
||||
assertEquals(MailReceivingMessageSource.class, source.getClass());
|
||||
Object receiver = new DirectFieldAccessor(source).getPropertyValue("mailReceiver");
|
||||
assertEquals(Pop3MailReceiver.class, receiver.getClass());
|
||||
DirectFieldAccessor receiverAccessor = new DirectFieldAccessor(receiver);
|
||||
Object url = receiverAccessor.getPropertyValue("url");
|
||||
assertEquals(new URLName("pop3:bar"), url);
|
||||
Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
|
||||
assertEquals("bar", properties.getProperty("foo"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<?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">
|
||||
|
||||
<inbound-channel-adapter id="pollingPop3" store-uri="pop3://mailtest:mailtest@ubuntuservervm/INBOX" auto-startup="false">
|
||||
<integration:poller>
|
||||
<integration:interval-trigger interval="5000"/>
|
||||
</integration:poller>
|
||||
</inbound-channel-adapter>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user