camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r791068 - in /camel/trunk/components/camel-mail/src: main/java/org/apache/camel/component/mail/ test/java/org/apache/camel/component/mail/
Date Sat, 04 Jul 2009 07:01:51 GMT
Author: davsclaus
Date: Sat Jul  4 07:01:51 2009
New Revision: 791068

URL: http://svn.apache.org/viewvc?rev=791068&view=rev
Log:
CAMEL-1693: Added option to use a custom mail sender when sending mails.

Added:
    camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomMailSenderTest.java
  (with props)
Modified:
    camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java
    camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
    camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java

Modified: camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java?rev=791068&r1=791067&r2=791068&view=diff
==============================================================================
--- camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java
(original)
+++ camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailComponent.java
Sat Jul  4 07:01:51 2009
@@ -77,6 +77,7 @@
         return endpoint;
     }
 
+    @SuppressWarnings("unchecked")
     private void configureAdditionalJavaMailProperties(MailConfiguration config, Map parameters)
{
         // we cannot remove while iterating, as we will get a modification exception
         Set toRemove = new HashSet();

Modified: camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java?rev=791068&r1=791067&r2=791068&view=diff
==============================================================================
--- camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
(original)
+++ camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
Sat Jul  4 07:01:51 2009
@@ -26,6 +26,7 @@
 import javax.mail.Session;
 
 import org.apache.camel.RuntimeCamelException;
+import org.springframework.mail.javamail.JavaMailSender;
 import org.springframework.mail.javamail.JavaMailSenderImpl;
 
 /**
@@ -35,6 +36,7 @@
  */
 public class MailConfiguration implements Cloneable {   
 
+    private JavaMailSender javaMailSender;
     private Properties javaMailProperties;
     private Properties additionalJavaMailProperties;
     private String protocol;
@@ -210,6 +212,14 @@
     // Properties
     // -------------------------------------------------------------------------
 
+    public JavaMailSender getJavaMailSender() {
+        return javaMailSender;
+    }
+
+    public void setJavaMailSender(JavaMailSender javaMailSender) {
+        this.javaMailSender = javaMailSender;
+    }
+
     public String getDefaultEncoding() {
         return defaultEncoding;
     }

Modified: camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java?rev=791068&r1=791067&r2=791068&view=diff
==============================================================================
--- camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
(original)
+++ camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
Sat Jul  4 07:01:51 2009
@@ -60,7 +60,11 @@
     }
 
     public Producer createProducer() throws Exception {
-        JavaMailSender sender = configuration.createJavaMailSender();
+        JavaMailSender sender = configuration.getJavaMailSender();
+        if (sender == null) {
+            // use default mail sender
+            sender = configuration.createJavaMailSender();
+        }
         return createProducer(sender);
     }
 
@@ -77,6 +81,7 @@
                 + " cannot be used for a MailConsumer. Please use another protocol such as
pop3 or imap.");
         }
 
+        // must use java mail sender impl as we need to get hold of a mail session
         JavaMailSenderImpl sender = configuration.createJavaMailSender();
         return createConsumer(processor, sender);
     }

Added: camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomMailSenderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomMailSenderTest.java?rev=791068&view=auto
==============================================================================
--- camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomMailSenderTest.java
(added)
+++ camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomMailSenderTest.java
Sat Jul  4 07:01:51 2009
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.component.mail;
+
+import java.io.InputStream;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.springframework.mail.MailException;
+import org.springframework.mail.SimpleMailMessage;
+import org.springframework.mail.javamail.JavaMailSender;
+import org.springframework.mail.javamail.MimeMessagePreparator;
+
+/**
+ * @version $Revision$
+ */
+public class MailCustomMailSenderTest extends CamelTestSupport {
+
+    private static boolean sent;
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("mySender", new MySender());
+        return jndi;
+    }
+
+    @Test
+    public void testSendWithCustomMailSender() throws Exception {
+        sendBody("smtp://claus@localhost?javaMailSender=#mySender", "Hello World");
+
+        assertTrue("Should have used custom mail sender", sent);
+    }
+
+    private class MySender implements JavaMailSender {
+
+        public void send(SimpleMailMessage simpleMessage) throws MailException {
+            // noop
+        }
+
+        public void send(SimpleMailMessage[] simpleMessages) throws MailException {
+            // noop
+        }
+
+        public MimeMessage createMimeMessage() {
+            return null;
+        }
+
+        public MimeMessage createMimeMessage(InputStream contentStream) throws MailException
{
+            return null;
+        }
+
+        public void send(MimeMessage mimeMessage) throws MailException {
+            // noop
+        }
+
+        public void send(MimeMessage[] mimeMessages) throws MailException {
+            // noop
+        }
+
+        public void send(MimeMessagePreparator mimeMessagePreparator) throws MailException
{
+            sent = true;
+        }
+
+        public void send(MimeMessagePreparator[] mimeMessagePreparators) throws MailException
{
+            // noop
+        }
+    }
+
+}

Propchange: camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomMailSenderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomMailSenderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message