camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1142654 - in /camel/trunk/components/camel-mail/src: main/java/org/apache/camel/component/mail/ test/java/org/apache/camel/component/mail/
Date Mon, 04 Jul 2011 13:25:16 GMT
Author: cschneider
Date: Mon Jul  4 13:25:16 2011
New Revision: 1142654

URL: http://svn.apache.org/viewvc?rev=1142654&view=rev
Log:
CAMEL-4173 Fixed Nullpointer Exception when sending null body, added test, removed 2 unused
imports

Modified:
    camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
    camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/DetermineContentTypeIssueTest.java
    camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomContentTypeTest.java
    camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailProducerUnsupportedCharsetTest.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=1142654&r1=1142653&r2=1142654&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
Mon Jul  4 13:25:16 2011
@@ -184,9 +184,14 @@ public class MailBinding {
         String contentType = determineContentType(configuration, exchange);
 
         LOG.trace("Using Content-Type {} for MimeMessage: {}", contentType, part);
+        
+        String body = exchange.getIn().getBody(String.class);
+        if (body == null) {
+            body = "";
+        }
 
         // always store content in a byte array data store to avoid various content type
and charset issues
-        DataSource ds = new ByteArrayDataSource(exchange.getIn().getBody(String.class), contentType);
+        DataSource ds = new ByteArrayDataSource(body, contentType);
         part.setDataHandler(new DataHandler(ds));
 
         // set the content type header afterwards

Modified: camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/DetermineContentTypeIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/DetermineContentTypeIssueTest.java?rev=1142654&r1=1142653&r2=1142654&view=diff
==============================================================================
--- camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/DetermineContentTypeIssueTest.java
(original)
+++ camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/DetermineContentTypeIssueTest.java
Mon Jul  4 13:25:16 2011
@@ -17,7 +17,6 @@
 package org.apache.camel.component.mail;
 
 import org.apache.camel.Exchange;
-import org.apache.camel.converter.IOConverter;
 import org.apache.camel.test.junit4.ExchangeTestSupport;
 import org.junit.Test;
 

Modified: camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomContentTypeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomContentTypeTest.java?rev=1142654&r1=1142653&r2=1142654&view=diff
==============================================================================
--- camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomContentTypeTest.java
(original)
+++ camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomContentTypeTest.java
Mon Jul  4 13:25:16 2011
@@ -56,6 +56,18 @@ public class MailCustomContentTypeTest e
         assertEquals("text/html; charset=iso-8859-1", msg.getContentType());
         assertEquals("<html><body><h1>Hello</h1>World</body></html>",
msg.getContent());
     }
+    
+    @Test
+    public void testNullBody() throws Exception {
+        Mailbox.clearAll();
+
+        template.sendBodyAndHeader("direct:b", null, "contentType", "text/plain; charset=iso-8859-1");
+
+        Mailbox box = Mailbox.get("claus@localhost");
+        Message msg = box.get(0);
+        assertEquals("text/plain; charset=iso-8859-1", msg.getContentType());
+        assertEquals("", msg.getContent());
+    }
 
     @Test
     public void testSendPlainMailContentTypeInHeader() throws Exception {

Modified: camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailProducerUnsupportedCharsetTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailProducerUnsupportedCharsetTest.java?rev=1142654&r1=1142653&r2=1142654&view=diff
==============================================================================
--- camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailProducerUnsupportedCharsetTest.java
(original)
+++ camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailProducerUnsupportedCharsetTest.java
Mon Jul  4 13:25:16 2011
@@ -23,7 +23,6 @@ import java.util.Map;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.converter.IOConverter;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 import org.jvnet.mock_javamail.Mailbox;



Mime
View raw message