INT-982, INT-1158, INT-1159, INT-1160, INT-1161, INT-1162, INT-1163 inbound mail adapter updates
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.
|
||||
@@ -49,6 +49,8 @@ public abstract class AbstractMailReceiver implements MailReceiver, DisposableBe
|
||||
|
||||
private final URLName url;
|
||||
|
||||
private volatile String protocol;
|
||||
|
||||
private volatile int maxFetchSize = -1;
|
||||
|
||||
private volatile Session session;
|
||||
@@ -57,6 +59,8 @@ public abstract class AbstractMailReceiver implements MailReceiver, DisposableBe
|
||||
|
||||
private volatile Folder folder;
|
||||
|
||||
private volatile boolean shouldDeleteMessages = false;
|
||||
|
||||
private volatile Properties javaMailProperties = new Properties();
|
||||
|
||||
protected volatile boolean initialized;
|
||||
@@ -65,31 +69,90 @@ public abstract class AbstractMailReceiver implements MailReceiver, DisposableBe
|
||||
|
||||
private Authenticator javaMailAuthenticator;
|
||||
|
||||
|
||||
public AbstractMailReceiver() {
|
||||
this.url = null;
|
||||
}
|
||||
|
||||
public AbstractMailReceiver(URLName urlName) {
|
||||
Assert.notNull(urlName, "urlName must not be null");
|
||||
this.url = urlName;
|
||||
this.shouldDeleteMessages = urlName.getProtocol().startsWith("pop3");
|
||||
}
|
||||
|
||||
public AbstractMailReceiver(String url) {
|
||||
Assert.notNull(url, "url must not be null");
|
||||
this.url = new URLName(url);
|
||||
if (url != null) {
|
||||
this.url = new URLName(url);
|
||||
this.shouldDeleteMessages = this.url.getProtocol().startsWith("pop3");
|
||||
}
|
||||
else {
|
||||
this.url = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setProtocol(String protocol) {
|
||||
if (this.url != null) {
|
||||
Assert.isTrue(this.url.getProtocol().equals(protocol),
|
||||
"The 'protocol' does not match that provided by the Store URI.");
|
||||
}
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link Session}. Otherwise, the Session will be created by invocation of
|
||||
* {@link Session#getInstance(Properties)} or {@link Session#getInstance(Properties, Authenticator)}.
|
||||
*
|
||||
* @see #setJavaMailProperties(Properties)
|
||||
* @see #setJavaMailAuthenticator(Authenticator)
|
||||
*/
|
||||
public void setSession(Session session) {
|
||||
Assert.notNull(session, "Session must not be null");
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
/**
|
||||
* A new {@link Session} will be created with these properties (and the JavaMailAuthenticator if provided).
|
||||
* Use either this method or {@link #setSession}, but not both.
|
||||
*
|
||||
* @see #setJavaMailAuthenticator(Authenticator)
|
||||
* @see #setSession(Session)
|
||||
*/
|
||||
public void setJavaMailProperties(Properties javaMailProperties) {
|
||||
this.javaMailProperties = javaMailProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional, sets the Authenticator to be used to obtain a session
|
||||
* Optional, sets the Authenticator to be used to obtain a session. This will not be used if
|
||||
* {@link AbstractMailReceiver#setSession} has been used to configure the {@link Session} directly.
|
||||
*
|
||||
* @see #setSession(Session)
|
||||
*/
|
||||
public void setJavaMailAuthenticator(Authenticator javaMailAuthenticator) {
|
||||
this.javaMailAuthenticator = javaMailAuthenticator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the maximum number of Messages to fetch per call to {@link #receive()}.
|
||||
*/
|
||||
public void setMaxFetchSize(int maxFetchSize) {
|
||||
this.maxFetchSize = maxFetchSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify whether mail messages should be deleted after retrieval.
|
||||
*/
|
||||
public void setShouldDeleteMessages(boolean shouldDeleteMessages) {
|
||||
this.shouldDeleteMessages = shouldDeleteMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the mail messages should be deleted after being received.
|
||||
*/
|
||||
protected boolean shouldDeleteMessages() {
|
||||
return this.shouldDeleteMessages;
|
||||
}
|
||||
|
||||
protected Folder getFolder() {
|
||||
return this.folder;
|
||||
}
|
||||
@@ -99,18 +162,25 @@ public abstract class AbstractMailReceiver implements MailReceiver, DisposableBe
|
||||
*/
|
||||
protected abstract Message[] searchForNewMessages() throws MessagingException;
|
||||
|
||||
/**
|
||||
* Subclasses must implement this method to indicate whether the mail
|
||||
* messages should be deleted after being received.
|
||||
*/
|
||||
protected abstract boolean shouldDeleteMessages();
|
||||
|
||||
private void openSession() throws MessagingException {
|
||||
if (this.session == null) {
|
||||
this.session = Session.getInstance(this.javaMailProperties, this.javaMailAuthenticator);
|
||||
if (this.javaMailAuthenticator != null) {
|
||||
this.session = Session.getInstance(this.javaMailProperties, this.javaMailAuthenticator);
|
||||
}
|
||||
else {
|
||||
this.session = Session.getInstance(this.javaMailProperties);
|
||||
}
|
||||
}
|
||||
if (this.store == null) {
|
||||
this.store = this.session.getStore(this.url);
|
||||
if (this.url != null) {
|
||||
this.store = this.session.getStore(this.url);
|
||||
}
|
||||
else if (this.protocol != null) {
|
||||
this.store = this.session.getStore(this.protocol);
|
||||
}
|
||||
else {
|
||||
this.store = this.session.getStore();
|
||||
}
|
||||
}
|
||||
if (!this.store.isConnected()) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
||||
@@ -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.
|
||||
@@ -44,31 +44,26 @@ import com.sun.mail.imap.IMAPFolder;
|
||||
*/
|
||||
public class ImapMailReceiver extends AbstractMailReceiver {
|
||||
|
||||
private volatile boolean shouldDeleteMessages = true;
|
||||
|
||||
private final MessageCountListener messageCountListener = new SimpleMessageCountListener();
|
||||
|
||||
|
||||
public ImapMailReceiver() {
|
||||
super();
|
||||
this.setProtocol("imap");
|
||||
}
|
||||
|
||||
public ImapMailReceiver(String url) {
|
||||
super(url);
|
||||
Assert.isTrue(url.toLowerCase().startsWith("imap"),
|
||||
"URL must start with 'imap' for the IMAP Mail receiver.");
|
||||
if (url != null) {
|
||||
Assert.isTrue(url.toLowerCase().startsWith("imap"),
|
||||
"URL must start with 'imap' for the IMAP Mail receiver.");
|
||||
}
|
||||
else {
|
||||
this.setProtocol("imap");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Specify whether mail messages should be deleted after retrieval.
|
||||
* The default is <code>true</code>.
|
||||
*/
|
||||
public void setShouldDeleteMessages(boolean shouldDeleteMessages) {
|
||||
this.shouldDeleteMessages = shouldDeleteMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldDeleteMessages() {
|
||||
return this.shouldDeleteMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is unique to the IMAP receiver and only works if IMAP IDLE
|
||||
* is supported (see RFC 2177 for more detail).
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.
|
||||
@@ -32,9 +32,19 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class Pop3MailReceiver extends AbstractMailReceiver {
|
||||
|
||||
public Pop3MailReceiver() {
|
||||
super();
|
||||
this.setProtocol("pop3");
|
||||
}
|
||||
|
||||
public Pop3MailReceiver(String url) {
|
||||
super(url);
|
||||
Assert.isTrue(url.startsWith("pop3"), "url must start with 'pop3'");
|
||||
if (url != null) {
|
||||
Assert.isTrue(url.startsWith("pop3"), "url must start with 'pop3'");
|
||||
}
|
||||
else {
|
||||
this.setProtocol("pop3");
|
||||
}
|
||||
}
|
||||
|
||||
public Pop3MailReceiver(String host, String username, String password) {
|
||||
@@ -47,14 +57,6 @@ public class Pop3MailReceiver extends AbstractMailReceiver {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* POP3 is unable to detect new Messages, so this always returns true.
|
||||
*/
|
||||
@Override
|
||||
protected final boolean shouldDeleteMessages() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Message[] searchForNewMessages() throws MessagingException {
|
||||
int messageCount = this.getFolder().getMessageCount();
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <imap-idle-channel-adapter> element in the 'mail' namespace.
|
||||
@@ -58,12 +59,25 @@ public class ImapIdleChannelAdapterParser extends AbstractSingleBeanDefinitionPa
|
||||
}
|
||||
|
||||
private BeanDefinition parseImapMailReceiver(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder receiverBuilder = BeanDefinitionBuilder.genericBeanDefinition(BASE_PACKAGE + ".ImapMailReceiver");
|
||||
Object source = parserContext.extractSource(element);
|
||||
String uri = element.getAttribute("store-uri");
|
||||
Assert.hasText(uri, "the 'store-uri' attribute is required");
|
||||
BeanDefinitionBuilder receiverBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
BASE_PACKAGE + ".ImapMailReceiver");
|
||||
receiverBuilder.addConstructorArgValue(uri);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(receiverBuilder, element, "java-mail-properties");
|
||||
if (StringUtils.hasText(uri)) {
|
||||
receiverBuilder.addConstructorArgValue(uri);
|
||||
}
|
||||
String session = element.getAttribute("session");
|
||||
if (StringUtils.hasText(session)) {
|
||||
if (element.hasAttribute("java-mail-properties") || element.hasAttribute("authenticator")) {
|
||||
parserContext.getReaderContext().error("Neither 'java-mail-properties' nor 'authenticator' " +
|
||||
"references are allowed when a 'session' reference has been provided.", source);
|
||||
}
|
||||
receiverBuilder.addPropertyReference("session", session);
|
||||
}
|
||||
else {
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(receiverBuilder, element, "java-mail-properties");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(receiverBuilder, element, "authenticator", "javaMailAuthenticator");
|
||||
}
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(receiverBuilder, element, "max-fetch-size");
|
||||
receiverBuilder.addPropertyValue("shouldDeleteMessages", element.getAttribute("should-delete-messages"));
|
||||
return receiverBuilder.getBeanDefinition();
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -18,11 +18,12 @@ package org.springframework.integration.mail.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.AbstractPollingInboundChannelAdapterParser;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
|
||||
@@ -42,30 +43,44 @@ public class MailInboundChannelAdapterParser extends AbstractPollingInboundChann
|
||||
protected String parseSource(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
BASE_PACKAGE + ".MailReceivingMessageSource");
|
||||
builder.addConstructorArgReference(this.parseMailReceiver(element, parserContext));
|
||||
builder.addConstructorArgValue(this.parseMailReceiver(element, parserContext));
|
||||
return BeanDefinitionReaderUtils.registerWithGeneratedName(
|
||||
builder.getBeanDefinition(), parserContext.getRegistry());
|
||||
}
|
||||
|
||||
private String parseMailReceiver(Element element, ParserContext parserContext) {
|
||||
String storeUri = element.getAttribute("store-uri");
|
||||
Assert.hasText(storeUri, "the 'store-uri' attribute is required");
|
||||
private BeanDefinition parseMailReceiver(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder receiverBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
BASE_PACKAGE + ".config.MailReceiverFactoryBean");
|
||||
receiverBuilder.addPropertyValue("storeUri", storeUri);
|
||||
String propertiesRef = element.getAttribute("java-mail-properties");
|
||||
if (StringUtils.hasText(propertiesRef)) {
|
||||
receiverBuilder.addPropertyReference("javaMailProperties", propertiesRef);
|
||||
Object source = parserContext.extractSource(element);
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(receiverBuilder, element, "store-uri");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(receiverBuilder, element, "protocol");
|
||||
String session = element.getAttribute("session");
|
||||
if (StringUtils.hasText(session)) {
|
||||
if (element.hasAttribute("java-mail-properties") || element.hasAttribute("authenticator")) {
|
||||
parserContext.getReaderContext().error("Neither 'java-mail-properties' nor 'authenticator' " +
|
||||
"references are allowed when a 'session' reference has been provided.", source);
|
||||
}
|
||||
receiverBuilder.addPropertyReference("session", session);
|
||||
}
|
||||
Element pollerElement = DomUtils.getChildElementByTagName(element, "poller");
|
||||
if (pollerElement != null) {
|
||||
String mmpp = pollerElement.getAttribute("max-messages-per-poll");
|
||||
if (StringUtils.hasText(mmpp)) {
|
||||
receiverBuilder.addPropertyValue("maxFetchSize", mmpp);
|
||||
else {
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(receiverBuilder, element, "java-mail-properties");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(receiverBuilder, element, "authenticator");
|
||||
}
|
||||
String maxFetchSize = element.getAttribute("max-fetch-size");
|
||||
if (StringUtils.hasText(maxFetchSize)) {
|
||||
receiverBuilder.addPropertyValue("maxFetchSize", maxFetchSize);
|
||||
}
|
||||
else {
|
||||
Element pollerElement = DomUtils.getChildElementByTagName(element, "poller");
|
||||
if (pollerElement != null) {
|
||||
String mmpp = pollerElement.getAttribute("max-messages-per-poll");
|
||||
if (StringUtils.hasText(mmpp)) {
|
||||
receiverBuilder.addPropertyValue("maxFetchSize", mmpp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return BeanDefinitionReaderUtils.registerWithGeneratedName(
|
||||
receiverBuilder.getBeanDefinition(), parserContext.getRegistry());
|
||||
receiverBuilder.addPropertyValue("shouldDeleteMessages", element.getAttribute("should-delete-messages"));
|
||||
return receiverBuilder.getBeanDefinition();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -18,6 +18,10 @@ package org.springframework.integration.mail.config;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.URLName;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.integration.mail.AbstractMailReceiver;
|
||||
@@ -25,6 +29,7 @@ import org.springframework.integration.mail.ImapMailReceiver;
|
||||
import org.springframework.integration.mail.MailReceiver;
|
||||
import org.springframework.integration.mail.Pop3MailReceiver;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -34,10 +39,22 @@ public class MailReceiverFactoryBean implements FactoryBean, DisposableBean {
|
||||
|
||||
private volatile String storeUri;
|
||||
|
||||
private volatile String protocol;
|
||||
|
||||
private volatile Session session;
|
||||
|
||||
private volatile MailReceiver receiver;
|
||||
|
||||
private volatile Properties javaMailProperties;
|
||||
|
||||
private volatile Authenticator authenticator;
|
||||
|
||||
/**
|
||||
* Indicates whether retrieved messages should be deleted from the server.
|
||||
* This value will be <code>null</code> <i>unless</i> explicitly configured.
|
||||
*/
|
||||
private volatile Boolean shouldDeleteMessages = null;
|
||||
|
||||
private volatile int maxFetchSize = 1;
|
||||
|
||||
|
||||
@@ -45,10 +62,26 @@ public class MailReceiverFactoryBean implements FactoryBean, DisposableBean {
|
||||
this.storeUri = storeUri;
|
||||
}
|
||||
|
||||
public void setProtocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public void setSession(Session session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public void setJavaMailProperties(Properties javaMailProperties) {
|
||||
this.javaMailProperties = javaMailProperties;
|
||||
}
|
||||
|
||||
public void setAuthenticator(Authenticator authenticator) {
|
||||
this.authenticator = authenticator;
|
||||
}
|
||||
|
||||
public void setShouldDeleteMessages(Boolean shouldDeleteMessages) {
|
||||
this.shouldDeleteMessages = shouldDeleteMessages;
|
||||
}
|
||||
|
||||
public void setMaxFetchSize(int maxFetchSize) {
|
||||
this.maxFetchSize = maxFetchSize;
|
||||
}
|
||||
@@ -68,15 +101,45 @@ public class MailReceiverFactoryBean implements FactoryBean, DisposableBean {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void verifyProtocol() {
|
||||
if (StringUtils.hasText(this.storeUri)) {
|
||||
URLName urlName = new URLName(this.storeUri);
|
||||
if (this.protocol == null) {
|
||||
this.protocol = urlName.getProtocol();
|
||||
}
|
||||
else {
|
||||
Assert.isTrue(this.protocol.equals(urlName.getProtocol()),
|
||||
"The provided 'protocol' does not match that in the 'storeUri'.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Assert.hasText(this.protocol, "Either the 'storeUri' or 'protocol' is required.");
|
||||
}
|
||||
Assert.hasText(this.protocol, "Unable to resolve protocol.");
|
||||
}
|
||||
|
||||
private MailReceiver createReceiver() {
|
||||
Assert.hasText(this.storeUri, "the store URI is required");
|
||||
boolean isPop3 = this.storeUri.toLowerCase().startsWith("pop3");
|
||||
boolean isImap = this.storeUri.toLowerCase().startsWith("imap");
|
||||
this.verifyProtocol();
|
||||
boolean isPop3 = this.protocol.toLowerCase().startsWith("pop3");
|
||||
boolean isImap = this.protocol.toLowerCase().startsWith("imap");
|
||||
Assert.isTrue(isPop3 || isImap, "the store URI must begin with 'pop3' or 'imap'");
|
||||
AbstractMailReceiver receiver = isPop3 ? new Pop3MailReceiver(this.storeUri) : new ImapMailReceiver(this.storeUri);
|
||||
if (this.session != null) {
|
||||
Assert.isNull(this.javaMailProperties, "JavaMail Properties are not allowed when a Session has been provided.");
|
||||
Assert.isNull(this.authenticator, "A JavaMail Authenticator is not allowed when a Session has been provied.");
|
||||
receiver.setSession(this.session);
|
||||
}
|
||||
if (this.javaMailProperties != null) {
|
||||
receiver.setJavaMailProperties(this.javaMailProperties);
|
||||
}
|
||||
if (this.authenticator != null) {
|
||||
receiver.setJavaMailAuthenticator(this.authenticator);
|
||||
}
|
||||
if (this.shouldDeleteMessages != null) {
|
||||
// always set the value if configured explicitly
|
||||
// otherwise, the default is true for POP3 but false for IMAP
|
||||
receiver.setShouldDeleteMessages(this.shouldDeleteMessages);
|
||||
}
|
||||
receiver.setMaxFetchSize(this.maxFetchSize);
|
||||
return receiver;
|
||||
}
|
||||
|
||||
@@ -63,85 +63,146 @@
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="inbound-channel-adapter">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an inbound Channel Adapter that polls a mailbox for mail messages.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:sequence>
|
||||
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="channel" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.integration.core.MessageChannel"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="store-uri" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="java-mail-properties" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="java.util.Properties"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="auto-startup" type="xsd:string" default="true"/>
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="inboundMailAdapterType">
|
||||
<xsd:sequence>
|
||||
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="protocol" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The protocol to use (e.g. "pop3" or "imap"). Typically, either this or the 'store-uri' would be
|
||||
provided, but not both. However, at least one of them is required.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="imap-idle-channel-adapter">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an IMAP IDLE channel adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="channel" type="xsd:string" use="required">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.integration.core.MessageChannel"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="store-uri" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="java-mail-properties" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="java.util.Properties"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="task-executor" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.core.task.TaskExecutor"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="should-delete-messages" type="xsd:string" use="required">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specify whether mail messages should be deleted after retrieval.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="auto-startup" type="xsd:string" default="true"/>
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="inboundMailAdapterType">
|
||||
<xsd:attribute name="task-executor" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Reference to a TaskExecutor for sending inbound Mail to a MessageChannel asynchronously.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.core.task.TaskExecutor"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:complexType name="inboundMailAdapterType">
|
||||
<xsd:attribute name="id" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
A unique identifier for this Channel Adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="channel" type="xsd:string" use="required">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Reference for the MessageChannel to which this adapter will send Messages.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.integration.core.MessageChannel"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="store-uri" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The URI for the Mail Store. Typically of the form: [pop3|imap]://user:password@host:port/INBOX
|
||||
If this is not provided, then the store will be retrieved via the no-arg Session.getStore()
|
||||
instead of the Session.getStore(url) method.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="session" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Specify the javax.mail.Session reference.
|
||||
NOTE: if this is provided, then 'java-mail-properties' should not be.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="javax.mail.Session"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="java-mail-properties" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Reference to a 'java.util.Properties' instance with settings for the JavaMail Session.
|
||||
NOTE: if this is provided, then 'session' should not be.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="java.util.Properties"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="authenticator" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Specify the javax.mail.Authenticator.
|
||||
NOTE: if this is provided, then 'session' should not be.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="javax.mail.Authenticator"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="max-fetch-size" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specify the maximum number of Mail Messages to fetch per receive call.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="should-delete-messages" type="xsd:string" use="required">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specify whether mail messages should be deleted after retrieval.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="auto-startup" type="xsd:string" default="true">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Specify whether this endpoint should be started automatically. The default is TRUE.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="mail-to-string-transformer">
|
||||
<xsd:complexType>
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
<?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:mail="http://www.springframework.org/schema/integration/mail"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="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
|
||||
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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<!-- INT-982 -->
|
||||
|
||||
<mail:inbound-channel-adapter id="pop3ShouldDeleteTrue" store-uri="pop3:test" channel="testChannel" should-delete-messages="true" auto-startup="false"/>
|
||||
|
||||
<mail:inbound-channel-adapter id="pop3ShouldDeleteFalse" store-uri="pop3:test" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
<mail:inbound-channel-adapter id="imapShouldDeleteTrue" store-uri="imap:test" channel="testChannel" should-delete-messages="true" auto-startup="false"/>
|
||||
|
||||
<mail:inbound-channel-adapter id="imapShouldDeleteFalse" store-uri="imap:test" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
|
||||
<!-- INT-1158 -->
|
||||
|
||||
<context:property-placeholder properties-ref="configProperties"/>
|
||||
|
||||
<util:properties id="configProperties">
|
||||
<prop key="mail.delete.true">true</prop>
|
||||
<prop key="mail.delete.false">false</prop>
|
||||
</util:properties>
|
||||
|
||||
<mail:inbound-channel-adapter id="pop3ShouldDeleteTrueProperty" store-uri="pop3:test" channel="testChannel" should-delete-messages="${mail.delete.true}" auto-startup="false"/>
|
||||
|
||||
<mail:inbound-channel-adapter id="pop3ShouldDeleteFalseProperty" store-uri="pop3:test" channel="testChannel" should-delete-messages="${mail.delete.false}" auto-startup="false"/>
|
||||
|
||||
<mail:inbound-channel-adapter id="imapShouldDeleteTrueProperty" store-uri="imap:test" channel="testChannel" should-delete-messages="${mail.delete.true}" auto-startup="false"/>
|
||||
|
||||
<mail:inbound-channel-adapter id="imapShouldDeleteFalseProperty" store-uri="imap:test" channel="testChannel" should-delete-messages="${mail.delete.false}" auto-startup="false"/>
|
||||
|
||||
|
||||
<!-- INT-1159 -->
|
||||
|
||||
<mail:inbound-channel-adapter id="pop3WithAuthenticator" store-uri="pop3:test" authenticator="testAuthenticator" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
<mail:inbound-channel-adapter id="imapWithAuthenticator" store-uri="imap:test" authenticator="testAuthenticator" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
<mail:imap-idle-channel-adapter id="imapIdleWithAuthenticator" store-uri="imap:test" authenticator="testAuthenticator" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
<bean id="testAuthenticator" class="org.springframework.integration.mail.config.InboundChannelAdapterParserTests$TestAuthenticator"/>
|
||||
|
||||
|
||||
<!-- INT-1160 -->
|
||||
|
||||
<mail:inbound-channel-adapter id="pop3WithMaxFetchSize" store-uri="pop3:test" max-fetch-size="11" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
<mail:inbound-channel-adapter id="pop3WithMaxFetchSizeFallsBackToPollerMax" store-uri="pop3:test" channel="testChannel" should-delete-messages="false" auto-startup="false">
|
||||
<si:poller max-messages-per-poll="99">
|
||||
<si:interval-trigger interval="30" time-unit="SECONDS"/>
|
||||
</si:poller>
|
||||
</mail:inbound-channel-adapter>
|
||||
|
||||
<mail:inbound-channel-adapter id="imapWithMaxFetchSize" store-uri="imap:test" max-fetch-size="22" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
<mail:imap-idle-channel-adapter id="imapIdleWithMaxFetchSize" store-uri="imap:test" max-fetch-size="33" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
|
||||
<!-- INT-1161 -->
|
||||
|
||||
<mail:inbound-channel-adapter id="pop3WithSession" store-uri="pop3:test" session="testSession" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
<mail:inbound-channel-adapter id="imapWithSession" store-uri="imap:test" session="testSession" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
<mail:imap-idle-channel-adapter id="imapIdleWithSession" store-uri="imap:test" session="testSession" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
<bean id="testSession" class="javax.mail.Session" factory-method="getInstance">
|
||||
<constructor-arg>
|
||||
<props>
|
||||
<prop key="foo">bar</prop>
|
||||
</props>
|
||||
</constructor-arg>
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.mail.config.InboundChannelAdapterParserTests$TestAuthenticator"/>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- INT-1162 -->
|
||||
|
||||
<mail:inbound-channel-adapter id="pop3WithoutStoreUri" channel="testChannel" protocol="pop3" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
<mail:inbound-channel-adapter id="imapWithoutStoreUri" channel="testChannel" protocol="imap" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
<mail:imap-idle-channel-adapter id="imapIdleWithoutStoreUri" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
|
||||
<!-- COMMON CONFIGURATION -->
|
||||
|
||||
<si:channel id="testChannel"/>
|
||||
|
||||
<si:poller default="true" max-messages-per-poll="1">
|
||||
<si:interval-trigger interval="60" time-unit="SECONDS"/>
|
||||
</si:poller>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?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:mail="http://www.springframework.org/schema/integration/mail"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="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
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<!-- INT-1163 -->
|
||||
|
||||
<mail:inbound-channel-adapter id="invalid" channel="testChannel" protocol="pop3" auto-startup="false"/>
|
||||
|
||||
<si:channel id="testChannel"/>
|
||||
|
||||
<si:poller default="true" max-messages-per-poll="1">
|
||||
<si:interval-trigger interval="60" time-unit="SECONDS"/>
|
||||
</si:poller>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import javax.mail.Authenticator;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.mail.AbstractMailReceiver;
|
||||
import org.springframework.integration.mail.ImapIdleChannelAdapter;
|
||||
import org.springframework.integration.mail.ImapMailReceiver;
|
||||
import org.springframework.integration.mail.Pop3MailReceiver;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @since 1.0.5
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class InboundChannelAdapterParserTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
|
||||
//==================== INT-982 =====================
|
||||
|
||||
@Test
|
||||
public void pop3ShouldDeleteTrue() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("pop3ShouldDeleteTrue");
|
||||
assertEquals(Pop3MailReceiver.class, receiver.getClass());
|
||||
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
|
||||
assertTrue(value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pop3ShouldDeleteFalse() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("pop3ShouldDeleteFalse");
|
||||
assertEquals(Pop3MailReceiver.class, receiver.getClass());
|
||||
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
|
||||
assertFalse(value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imapShouldDeleteTrue() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("imapShouldDeleteTrue");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
|
||||
assertTrue(value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imapShouldDeleteFalse() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("imapShouldDeleteFalse");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
|
||||
assertFalse(value);
|
||||
}
|
||||
|
||||
|
||||
//==================== INT-1158 ====================
|
||||
|
||||
@Test
|
||||
public void pop3ShouldDeleteTrueProperty() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("pop3ShouldDeleteTrueProperty");
|
||||
assertEquals(Pop3MailReceiver.class, receiver.getClass());
|
||||
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
|
||||
assertTrue(value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pop3ShouldDeleteFalseProperty() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("pop3ShouldDeleteFalseProperty");
|
||||
assertEquals(Pop3MailReceiver.class, receiver.getClass());
|
||||
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
|
||||
assertFalse(value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imapShouldDeleteTrueProperty() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("imapShouldDeleteTrueProperty");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
|
||||
assertTrue(value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imapShouldDeleteFalseProperty() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("imapShouldDeleteFalseProperty");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
|
||||
assertFalse(value);
|
||||
}
|
||||
|
||||
|
||||
//==================== INT-1159 ====================
|
||||
|
||||
@Test
|
||||
public void pop3WithAuthenticator() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("pop3WithAuthenticator");
|
||||
assertEquals(Pop3MailReceiver.class, receiver.getClass());
|
||||
Object authenticator = new DirectFieldAccessor(receiver).getPropertyValue("javaMailAuthenticator");
|
||||
assertNotNull(authenticator);
|
||||
assertEquals(context.getBean("testAuthenticator"), authenticator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imapWithAuthenticator() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("imapWithAuthenticator");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
Object authenticator = new DirectFieldAccessor(receiver).getPropertyValue("javaMailAuthenticator");
|
||||
assertNotNull(authenticator);
|
||||
assertEquals(context.getBean("testAuthenticator"), authenticator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imapIdleWithAuthenticator() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("imapIdleWithAuthenticator");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
Object authenticator = new DirectFieldAccessor(receiver).getPropertyValue("javaMailAuthenticator");
|
||||
assertNotNull(authenticator);
|
||||
assertEquals(context.getBean("testAuthenticator"), authenticator);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class TestAuthenticator extends Authenticator {
|
||||
}
|
||||
|
||||
|
||||
//==================== INT-1160 ====================
|
||||
|
||||
@Test
|
||||
public void pop3WithMaxFetchSize() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("pop3WithMaxFetchSize");
|
||||
assertEquals(Pop3MailReceiver.class, receiver.getClass());
|
||||
Object value = new DirectFieldAccessor(receiver).getPropertyValue("maxFetchSize");
|
||||
assertEquals(11, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pop3WithMaxFetchSizeFallsBackToPollerMax() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("pop3WithMaxFetchSizeFallsBackToPollerMax");
|
||||
assertEquals(Pop3MailReceiver.class, receiver.getClass());
|
||||
Object value = new DirectFieldAccessor(receiver).getPropertyValue("maxFetchSize");
|
||||
assertEquals(99, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imapWithMaxFetchSize() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("imapWithMaxFetchSize");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
Object value = new DirectFieldAccessor(receiver).getPropertyValue("maxFetchSize");
|
||||
assertEquals(22, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imapIdleWithMaxFetchSize() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("imapIdleWithMaxFetchSize");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
Object value = new DirectFieldAccessor(receiver).getPropertyValue("maxFetchSize");
|
||||
assertEquals(33, value);
|
||||
}
|
||||
|
||||
|
||||
//==================== INT-1161 ====================
|
||||
|
||||
@Test
|
||||
public void pop3WithSession() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("pop3WithSession");
|
||||
assertEquals(Pop3MailReceiver.class, receiver.getClass());
|
||||
Object session = new DirectFieldAccessor(receiver).getPropertyValue("session");
|
||||
assertNotNull(session);
|
||||
assertEquals(context.getBean("testSession"), session);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imapWithSession() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("imapWithSession");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
Object session = new DirectFieldAccessor(receiver).getPropertyValue("session");
|
||||
assertNotNull(session);
|
||||
assertEquals(context.getBean("testSession"), session);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imapIdleWithSession() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("imapIdleWithSession");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
Object session = new DirectFieldAccessor(receiver).getPropertyValue("session");
|
||||
assertNotNull(session);
|
||||
assertEquals(context.getBean("testSession"), session);
|
||||
}
|
||||
|
||||
|
||||
//==================== INT-1162 ====================
|
||||
|
||||
@Test
|
||||
public void pop3WithoutStoreUri() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("pop3WithoutStoreUri");
|
||||
assertEquals(Pop3MailReceiver.class, receiver.getClass());
|
||||
Object url = new DirectFieldAccessor(receiver).getPropertyValue("url");
|
||||
assertNull(url);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imapWithoutStoreUri() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("imapWithoutStoreUri");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
Object url = new DirectFieldAccessor(receiver).getPropertyValue("url");
|
||||
assertNull(url);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imapIdleWithoutStoreUri() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("imapIdleWithoutStoreUri");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
Object url = new DirectFieldAccessor(receiver).getPropertyValue("url");
|
||||
assertNull(url);
|
||||
}
|
||||
|
||||
|
||||
//==================== INT-1163 ====================
|
||||
|
||||
@Test
|
||||
public void inboundChannelAdapterRequiresShouldDeleteMessages() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(
|
||||
"org/springframework/integration/mail/config/InboundChannelAdapterParserTests-invalidContext.xml");
|
||||
fail("expected a parser error");
|
||||
}
|
||||
catch(BeanDefinitionStoreException e) {
|
||||
assertEquals(SAXParseException.class, e.getCause().getClass());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//===================== COMMON =====================
|
||||
|
||||
private AbstractMailReceiver getReceiver(String name) {
|
||||
Object adapter = context.getBean(name);
|
||||
Object target = (adapter instanceof ImapIdleChannelAdapter) ? adapter
|
||||
: new DirectFieldAccessor(adapter).getPropertyValue("source");
|
||||
return (AbstractMailReceiver) new DirectFieldAccessor(target).getPropertyValue("mailReceiver");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,10 +16,10 @@
|
||||
<integration:channel id="channel"/>
|
||||
|
||||
<mail:inbound-channel-adapter id="imapAdapter"
|
||||
store-uri="imap:foo" java-mail-properties="props" channel="channel" auto-startup="false"/>
|
||||
store-uri="imap:foo" java-mail-properties="props" channel="channel" auto-startup="false" should-delete-messages="false"/>
|
||||
|
||||
<mail:inbound-channel-adapter id="pop3Adapter"
|
||||
store-uri="pop3:bar" java-mail-properties="props" channel="channel" auto-startup="false"/>
|
||||
store-uri="pop3:bar" java-mail-properties="props" channel="channel" auto-startup="false" should-delete-messages="true"/>
|
||||
|
||||
<util:properties id="props">
|
||||
<prop key="foo">bar</prop>
|
||||
|
||||
Reference in New Issue
Block a user