Author: davsclaus
Date: Fri Nov 27 06:30:59 2009
New Revision: 884750
URL: http://svn.apache.org/viewvc?rev=884750&view=rev
Log:
CAMEL-2232: Fixed mail component and multiple endpoints mixing up recipients
and only use from the last defined endpoint.
Added:
camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentRecipientSetTest.java
(with props)
camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailToMultipleEndpointsTest.java
(with props)
Modified:
camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
Modified:
camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java?rev=884750&r1=884749&r2=884750&view=diff
==============================================================================
---
camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
(original)
+++
camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
Fri Nov 27 06:30:59 2009
@@ -358,7 +358,7 @@
}
/**
- * Appends the Mail headers from the endpoint configuraiton.
+ * Appends the Mail headers from the endpoint configuration.
*/
protected void setRecipientFromEndpointConfiguration(MimeMessage
mimeMessage, MailEndpoint endpoint)
throws MessagingException {
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=884750&r1=884749&r2=884750&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
Fri Nov 27 06:30:59 2009
@@ -69,7 +69,11 @@
*/
public MailConfiguration copy() {
try {
- return (MailConfiguration) clone();
+ MailConfiguration copy = (MailConfiguration) clone();
+ // must set a new recipients map as clone just reuse the same
reference
+ copy.recipients = new HashMap<Message.RecipientType, String>();
+ copy.recipients.putAll(this.recipients);
+ return copy;
} catch (CloneNotSupportedException e) {
throw new RuntimeCamelException(e);
}
Added:
camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentRecipientSetTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentRecipientSetTest.java?rev=884750&view=auto
==============================================================================
---
camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentRecipientSetTest.java
(added)
+++
camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentRecipientSetTest.java
Fri Nov 27 06:30:59 2009
@@ -0,0 +1,83 @@
+/**
+ * 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 javax.mail.Message;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.jvnet.mock_javamail.Mailbox;
+
+/**
+ * @version $Revision$
+ */
+public class MailComponentRecipientSetTest extends CamelTestSupport {
+
+ @Test
+ public void testMultipleEndpoints() throws Exception {
+ Mailbox.clearAll();
+
+ template.sendBodyAndHeader("direct:a", "Hello World", "Subject",
"Hello a");
+ template.sendBodyAndHeader("direct:b", "Bye World", "Subject", "Hello
b");
+ template.sendBodyAndHeader("direct:c", "Hi World", "Subject", "Hello
c");
+
+ Mailbox boxA = Mailbox.get("[email protected]");
+ assertEquals(1, boxA.size());
+ assertEquals("Hello a", boxA.get(0).getSubject());
+ assertEquals("Hello World", boxA.get(0).getContent());
+ assertEquals("[email protected]", boxA.get(0).getFrom()[0].toString());
+ assertEquals("[email protected]",
boxA.get(0).getRecipients(Message.RecipientType.CC)[0].toString());
+
+ Mailbox boxB = Mailbox.get("[email protected]");
+ assertEquals(1, boxB.size());
+ assertEquals("Hello b", boxB.get(0).getSubject());
+ assertEquals("Bye World", boxB.get(0).getContent());
+ assertEquals("[email protected]", boxB.get(0).getFrom()[0].toString());
+ assertEquals("[email protected]",
boxB.get(0).getRecipients(Message.RecipientType.CC)[0].toString());
+
+ Mailbox boxC = Mailbox.get("[email protected]");
+ assertEquals(1, boxC.size());
+ assertEquals("Hello c", boxC.get(0).getSubject());
+ assertEquals("Hi World", boxC.get(0).getContent());
+ assertEquals("[email protected]", boxC.get(0).getFrom()[0].toString());
+ assertEquals("[email protected]",
boxC.get(0).getRecipients(Message.RecipientType.CC)[0].toString());
+ assertEquals("[email protected]",
boxC.get(0).getRecipients(Message.RecipientType.CC)[1].toString());
+ // no spy as its overridden by endpoint
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ MailConfiguration config = new MailConfiguration();
+ config.setCC("[email protected]");
+ config.setFrom("[email protected]");
+
+ MailComponent mail = context.getComponent("smtp",
MailComponent.class);
+ mail.setConfiguration(config);
+
+
from("direct:a").to("smtp://localhost?username=james2&password=secret&[email protected]");
+
+
from("direct:b").to("smtp://localhost?username=james&password=secret&[email protected]&[email protected]");
+
+
from("direct:c").to("smtp://localhost?username=admin&password=secret&[email protected]&[email protected],[email protected]");
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange:
camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentRecipientSetTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentRecipientSetTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailToMultipleEndpointsTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailToMultipleEndpointsTest.java?rev=884750&view=auto
==============================================================================
---
camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailToMultipleEndpointsTest.java
(added)
+++
camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailToMultipleEndpointsTest.java
Fri Nov 27 06:30:59 2009
@@ -0,0 +1,73 @@
+/**
+ * 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 javax.mail.Message;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.jvnet.mock_javamail.Mailbox;
+
+/**
+ * @version $Revision$
+ */
+public class MailToMultipleEndpointsTest extends CamelTestSupport {
+
+ @Test
+ public void testMultipleEndpoints() throws Exception {
+ Mailbox.clearAll();
+
+ template.sendBodyAndHeader("direct:a", "Hello World", "Subject",
"Hello a");
+ template.sendBodyAndHeader("direct:b", "Bye World", "Subject", "Hello
b");
+ template.sendBodyAndHeader("direct:c", "Hi World", "Subject", "Hello
c");
+
+ Mailbox boxA = Mailbox.get("[email protected]");
+ assertEquals(1, boxA.size());
+ assertEquals("Hello a", boxA.get(0).getSubject());
+ assertEquals("Hello World", boxA.get(0).getContent());
+ assertEquals("[email protected]", boxA.get(0).getFrom()[0].toString());
+
+ Mailbox boxB = Mailbox.get("[email protected]");
+ assertEquals(1, boxB.size());
+ assertEquals("Hello b", boxB.get(0).getSubject());
+ assertEquals("Bye World", boxB.get(0).getContent());
+ assertEquals("[email protected]", boxB.get(0).getFrom()[0].toString());
+
+ Mailbox boxC = Mailbox.get("[email protected]");
+ assertEquals(1, boxC.size());
+ assertEquals("Hello c", boxC.get(0).getSubject());
+ assertEquals("Hi World", boxC.get(0).getContent());
+ assertEquals("[email protected]", boxC.get(0).getFrom()[0].toString());
+ assertEquals("[email protected]",
boxC.get(0).getRecipients(Message.RecipientType.CC)[0].toString());
+ assertEquals("[email protected]",
boxC.get(0).getRecipients(Message.RecipientType.CC)[1].toString());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
from("direct:a").to("smtp://localhost?username=james2&password=secret&[email protected]&[email protected]");
+
+
from("direct:b").to("smtp://localhost?username=james&password=secret&[email protected]&[email protected]");
+
+
from("direct:c").to("smtp://localhost?username=admin&password=secret&[email protected]&[email protected]&[email protected],[email protected]");
+ }
+ };
+ }
+}
Propchange:
camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailToMultipleEndpointsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailToMultipleEndpointsTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date