Author: davsclaus
Date: Mon Jan 12 22:49:52 2009
New Revision: 734053

URL: http://svn.apache.org/viewvc?rev=734053&view=rev
Log:
CAMEL-1249: Fixed bug in mail component when using multiple mail 
configurations. (bad Claus)

Modified:
    
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java
    
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/MailEndpoint.java

Modified: 
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java?rev=734053&r1=734052&r2=734053&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java
 (original)
+++ 
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java
 Mon Jan 12 22:49:52 2009
@@ -27,6 +27,7 @@
 import org.apache.camel.impl.DefaultComponent;
 import org.apache.camel.impl.DefaultHeaderFilterStrategy;
 import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.util.ObjectHelper;
 
 /**
  * Component for JavaMail.
@@ -56,15 +57,25 @@
         if ("nntp".equalsIgnoreCase(url.getScheme())) {
             throw new UnsupportedOperationException("nntp protocol is not 
supported");
         }
-        
-        MailConfiguration config = new MailConfiguration();
+
+        // must use copy as each endpoint can have different options
+        ObjectHelper.notNull(configuration, "configuration");
+        MailConfiguration config = configuration.copy();
+
+        // only configure if we have a url with a known protocol
         config.configure(url);
         configureAdditionalJavaMailProperties(config, parameters);
 
-        // lets make sure we copy the configuration as each endpoint can 
customize its own version
         MailEndpoint endpoint = new MailEndpoint(uri, this, config);
-
         setProperties(endpoint.getConfiguration(), parameters);
+
+        // sanity check that we know the mail server
+        ObjectHelper.notEmpty(config.getHost(), "host");
+        ObjectHelper.notEmpty(config.getProtocol(), "protocol");
+        if (config.getPort() <= 0) {
+            throw new IllegalArgumentException("port mut be specified");
+        }
+
         return endpoint;
     }
 

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=734053&r1=734052&r2=734053&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
 Mon Jan 12 22:49:52 2009
@@ -20,12 +20,12 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
-
 import javax.mail.Authenticator;
 import javax.mail.Message;
 import javax.mail.PasswordAuthentication;
 import javax.mail.Session;
 
+import org.apache.camel.RuntimeCamelException;
 import org.springframework.mail.javamail.JavaMailSenderImpl;
 
 /**
@@ -33,7 +33,7 @@
  *
  * @version $Revision$
  */
-public class MailConfiguration {
+public class MailConfiguration implements Cloneable {
 
     public static final String DEFAULT_FOLDER_NAME = "INBOX";
     public static final String DEFAULT_FROM = "ca...@localhost";
@@ -63,6 +63,17 @@
     public MailConfiguration() {
     }
 
+    /**
+     * Returns a copy of this configuration
+     */
+    public MailConfiguration copy() {
+        try {
+            return (MailConfiguration) clone();
+        } catch (CloneNotSupportedException e) {
+            throw new RuntimeCamelException(e);
+        }
+    }
+
     public void configure(URI uri) {
         String value = uri.getHost();
         if (value != null) {
@@ -82,10 +93,10 @@
         }
 
         int port = uri.getPort();
-        if (port >= 0) {
+        if (port > 0) {
             setPort(port);
-        } else {
-            // resolve default port if no port number was provided
+        } else if (port <= 0 && this.port <= 0) {
+            // resolve default port if no port number was provided, and not 
already configured with a port number
             setPort(MailUtils.getDefaultPortForProtocol(uri.getScheme()));
         }
     }
@@ -170,7 +181,7 @@
         return properties;
     }
 
-   /**
+    /**
      * Is the used protocol to be secure or not
      */
     public boolean isSecureProtocol() {

Modified: 
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java?rev=734053&r1=734052&r2=734053&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
 (original)
+++ 
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
 Mon Jan 12 22:49:52 2009
@@ -39,7 +39,7 @@
     public MailEndpoint(String uri, MailComponent component, MailConfiguration 
configuration) {
         super(uri, component);
         this.configuration = configuration;
-        binding = new MailBinding(component.getHeaderFilterStrategy());
+        this.binding = new MailBinding(component.getHeaderFilterStrategy());
     }
 
     public MailEndpoint(String endpointUri, MailConfiguration configuration) {


Reply via email to