You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2008/05/04 18:12:16 UTC
svn commit: r653240 - in
/activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail:
MailConfiguration.java MailConsumer.java
Author: davsclaus
Date: Sun May 4 09:12:16 2008
New Revision: 653240
URL: http://svn.apache.org/viewvc?rev=653240&view=rev
Log:
CAMEL-335
- Added option for connectionTimeout
- Camel sets default java mail properties if none provided
Modified:
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
Modified: activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java?rev=653240&r1=653239&r2=653240&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java (original)
+++ activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java Sun May 4 09:12:16 2008
@@ -35,6 +35,7 @@
public static final String DEFAULT_FOLDER_NAME = "INBOX";
public static final String DEFAULT_FROM = "camel@localhost";
+ public static final long DEFAULT_CONNECTION_TIMEOUT = 30000L;
private Properties javaMailProperties;
private String protocol;
@@ -52,6 +53,7 @@
private Map<Message.RecipientType, String> recipients = new HashMap<Message.RecipientType, String>();
private int fetchSize = -1;
private boolean debugMode;
+ private long connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
public MailConfiguration() {
}
@@ -94,15 +96,19 @@
// sets the debug mode of the underlying mail framework
answer.getSession().setDebug(debugMode);
+ if (javaMailProperties != null) {
+ answer.setJavaMailProperties(javaMailProperties);
+ } else {
+ // set default properties if none provided
+ answer.setJavaMailProperties(createJavaMailProperties());
+ }
+
if (defaultEncoding != null) {
answer.setDefaultEncoding(defaultEncoding);
}
if (host != null) {
answer.setHost(host);
}
- if (javaMailProperties != null) {
- answer.setJavaMailProperties(javaMailProperties);
- }
if (port >= 0) {
answer.setPort(port);
}
@@ -121,6 +127,23 @@
return answer;
}
+ private Properties createJavaMailProperties() {
+ // clone the system properties
+ Properties properties = (Properties)System.getProperties().clone();
+ properties.put("mail." + protocol + ".connectiontimeout", connectionTimeout);
+ properties.put("mail." + protocol + ".timeout", connectionTimeout);
+ properties.put("mail." + protocol + ".host", host);
+ properties.put("mail." + protocol + ".port", "" + port);
+ properties.put("mail." + protocol + ".user", username);
+ properties.put("mail." + protocol + ".rsetbeforequit", "true");
+ properties.put("mail." + protocol + ".auth", "true");
+ properties.put("mail.transport.protocol", protocol);
+ properties.put("mail.store.protocol", protocol);
+ properties.put("mail.host", host);
+ properties.put("mail.user", username);
+ return properties;
+ }
+
// Properties
// -------------------------------------------------------------------------
@@ -294,4 +317,12 @@
public void setDebugMode(boolean debugMode) {
this.debugMode = debugMode;
}
+
+ public long getConnectionTimeout() {
+ return connectionTimeout;
+ }
+
+ public void setConnectionTimeout(long connectionTimeout) {
+ this.connectionTimeout = connectionTimeout;
+ }
}
Modified: activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java?rev=653240&r1=653239&r2=653240&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java (original)
+++ activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java Sun May 4 09:12:16 2008
@@ -76,8 +76,14 @@
}
protected void poll() throws Exception {
+ if (store == null || folder == null) {
+ throw new IllegalStateException("MailConsumer did not start properly. Camel does not have access to the MailStore or MailFolder."
+ + " Check log files for errors reported during starting this component");
+ }
+
if (LOG.isDebugEnabled()) {
- LOG.debug("Polling mailfolder " + folder.getFullName() + " at host " + endpoint.getConfiguration().getHost() + ":" + endpoint.getConfiguration().getPort());
+ LOG.debug("Polling mailfolder " + folder.getFullName() + " at host " +
+ endpoint.getConfiguration().getHost() + ":" + endpoint.getConfiguration().getPort());
}
if (endpoint.getConfiguration().getFetchSize() == 0) {