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/08 06:41:56 UTC

svn commit: r654409 - in /activemq/camel/trunk/components/camel-mail/src: main/java/org/apache/camel/component/mail/ test/java/org/apache/camel/component/mail/

Author: davsclaus
Date: Wed May  7 21:41:55 2008
New Revision: 654409

URL: http://svn.apache.org/viewvc?rev=654409&view=rev
Log:
CAMEL-335
- MailConsumer only starts to poll when its connected and can reconnect if needed. Tested SSL with gmail, see documentation on wiki.

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
    activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentTest.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=654409&r1=654408&r2=654409&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 Wed May  7 21:41:55 2008
@@ -144,6 +144,18 @@
         return properties;
     }
 
+   /**
+     * Is the used protocol to be secure or not
+     */
+    public boolean isSecureProtocol() {
+        return this.protocol.equalsIgnoreCase("smtps") || this.protocol.equalsIgnoreCase("pop3s")
+               || this.protocol.equalsIgnoreCase("imaps");
+    }
+
+    public String getMailStoreLogInformation() {
+        return "MailStore [" + protocol + "//" + host + ":" + port + "] folder=[" + folderName + "]";
+    }
+
     // Properties
     // -------------------------------------------------------------------------
 
@@ -325,4 +337,5 @@
     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=654409&r1=654408&r2=654409&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 Wed May  7 21:41:55 2008
@@ -52,23 +52,14 @@
     @Override
     protected void doStart() throws Exception {
         super.doStart();
-
-        MailConfiguration config = endpoint.getConfiguration();
-        store = sender.getSession().getStore(config.getProtocol());
-        store.connect(config.getHost(), config.getPort(), config.getUsername(), config.getPassword());
-
-        folder = store.getFolder(config.getFolderName());
-        if (folder == null || !folder.exists()) {
-            throw new FolderNotFoundException(folder, "Folder not found or invalid: " + config.getFolderName());
-        }
     }
 
     @Override
     protected void doStop() throws Exception {
-        if (folder.isOpen()) {
+        if (folder != null && folder.isOpen()) {
             folder.close(true);
         }
-        if (store.isConnected()) {
+        if (store != null && store.isConnected()) {
             store.close();
         }
 
@@ -76,9 +67,11 @@
     }
 
     protected void poll() throws Exception {
+        ensureIsConnected();
+
         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");
+            throw new IllegalStateException("MailConsumer did not connect properly to the MailStore: " +
+                endpoint.getConfiguration().getMailStoreLogInformation());
         }
 
         if (LOG.isDebugEnabled()) {
@@ -121,6 +114,25 @@
         }
     }
 
+    protected void ensureIsConnected() throws MessagingException {
+        MailConfiguration config = endpoint.getConfiguration();
+
+        if (store == null || !store.isConnected()) {
+            store = sender.getSession().getStore(config.getProtocol());
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Connecting to MailStore at host " + config.getHost() + " on port " + config.getPort());
+            }
+            store.connect(config.getHost(), config.getPort(), config.getUsername(), config.getPassword());
+        }
+
+        if (folder == null) {
+            folder = store.getFolder(config.getFolderName());
+            if (folder == null || !folder.exists()) {
+                throw new FolderNotFoundException(folder, "Folder not found or invalid: " + config.getFolderName());
+            }
+        }
+    }
+
     /**
      * Process all the messages
      */

Modified: activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentTest.java?rev=654409&r1=654408&r2=654409&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentTest.java (original)
+++ activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentTest.java Wed May  7 21:41:55 2008
@@ -110,7 +110,7 @@
 
     public void testManyConfigurations() throws Exception {
         MailEndpoint endpoint = resolveMandatoryEndpoint("smtp://james@myhost:30/subject?password=secret"
-            + "&from=me@camelriders.org&DeleteProcessedMessages=false&defaultEncoding=iso-8859-1&folderName=riders");
+            + "&from=me@camelriders.org&deleteProcessedMessages=false&defaultEncoding=iso-8859-1&folderName=riders");
         MailConfiguration config = endpoint.getConfiguration();
         assertEquals("getProtocol()", "smtp", config.getProtocol());
         assertEquals("getHost()", "myhost", config.getHost());