svn commit: r900682 - in /camel/trunk/components/camel-gae: ./ src/main/java/org/apache/camel/component/gae/mail/ src/test/java/org/apache/camel/component/gae/mail/

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r900682 - in /camel/trunk/components/camel-gae: ./ src/main/java/org/apache/camel/component/gae/mail/ src/test/java/org/apache/camel/component/gae/mail/

krasserm-2
Author: krasserm
Date: Tue Jan 19 07:09:00 2010
New Revision: 900682

URL: http://svn.apache.org/viewvc?rev=900682&view=rev
Log:
extension to the gmail component to support cc, bcc, recipient lists and overriding the sender

Modified:
    camel/trunk/components/camel-gae/pom.xml
    camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/mail/GMailBinding.java
    camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/mail/GMailEndpoint.java
    camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/mail/GMailBindingTest.java
    camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/mail/GMailEndpointTest.java

Modified: camel/trunk/components/camel-gae/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/pom.xml?rev=900682&r1=900681&r2=900682&view=diff
==============================================================================
--- camel/trunk/components/camel-gae/pom.xml (original)
+++ camel/trunk/components/camel-gae/pom.xml Tue Jan 19 07:09:00 2010
@@ -32,7 +32,7 @@
 
   <properties>
  <camel.osgi.export.pkg>org.apache.camel.component.gae.*</camel.osgi.export.pkg>
-    <appengine-sdk-version>1.2.8</appengine-sdk-version>
+    <appengine-sdk-version>1.3.0</appengine-sdk-version>
   </properties>
 
   <dependencies>

Modified: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/mail/GMailBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/mail/GMailBinding.java?rev=900682&r1=900681&r2=900682&view=diff
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/mail/GMailBinding.java (original)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/mail/GMailBinding.java Tue Jan 19 07:09:00 2010
@@ -27,16 +27,34 @@
 public class GMailBinding implements OutboundBinding<GMailEndpoint, Message, Void> {
 
     /**
+     * Camel header for setting the mail message sender.
+     */
+    public static final String GMAIL_SENDER = "org.apache.camel.component.gae.mail.Sender";
+    
+    /**
      * Camel header for setting the mail message subject.
      */
     public static final String GMAIL_SUBJECT = "org.apache.camel.component.gae.mail.Subject";
-    
+
     /**
-     * Camel header for setting the mail message recipient (list).
+     * Camel header for setting the mail message to-recipient (single recipient
+     * or comma-separated list).
      */
     public static final String GMAIL_TO = "org.apache.camel.component.gae.mail.To";
     
     /**
+     * Camel header for setting the mail message cc-recipient (single recipient
+     * or comma-separated list).
+     */
+    public static final String GMAIL_CC = "org.apache.camel.component.gae.mail.Cc";
+    
+    /**
+     * Camel header for setting the mail message bcc-recipient (single recipient
+     * or comma-separated list).
+     */
+    public static final String GMAIL_BCC = "org.apache.camel.component.gae.mail.Bcc";
+    
+    /**
      * Reads data from <code>exchange</code> and writes it to a newly created
      * {@link Message} instance. The <code>request</code> parameter is
      * ignored.
@@ -52,6 +70,8 @@
         Message message = new Message();
         writeFrom(endpoint, exchange, message);
         writeTo(endpoint, exchange, message);
+        writeCc(endpoint, exchange, message);
+        writeBcc(endpoint, exchange, message);
         writeSubject(endpoint, exchange, message);
         writeBody(endpoint, exchange, message);
         writeAttachments(endpoint, exchange, message);
@@ -66,16 +86,39 @@
     }
 
     protected void writeFrom(GMailEndpoint endpoint, Exchange exchange, Message request) {
-        request.setSender(endpoint.getSender());
+        String sender = (String)exchange.getIn().getHeader(GMAIL_SENDER);
+        if (sender == null) {
+            sender = endpoint.getSender();
+        }
+        request.setSender(sender);
     }
     
     protected void writeTo(GMailEndpoint endpoint, Exchange exchange, Message request) {
-        // TODO: support comma-separated list of receivers
         String to = (String)exchange.getIn().getHeader(GMAIL_TO);
         if (to == null) {
             to = endpoint.getTo();
         }
-        request.setTo(to);
+        request.setTo(to.split(","));
+    }
+    
+    protected void writeCc(GMailEndpoint endpoint, Exchange exchange, Message request) {
+        String cc = (String)exchange.getIn().getHeader(GMAIL_CC);
+        if (cc == null) {
+            cc = endpoint.getCc();
+        }
+        if (cc != null) {
+            request.setCc(cc.split(","));
+        }
+    }
+    
+    protected void writeBcc(GMailEndpoint endpoint, Exchange exchange, Message request) {
+        String bcc = (String)exchange.getIn().getHeader(GMAIL_BCC);
+        if (bcc == null) {
+            bcc = endpoint.getBcc();
+        }
+        if (bcc != null) {
+            request.setBcc(bcc.split(","));
+        }
     }
     
     protected void writeSubject(GMailEndpoint endpoint, Exchange exchange, Message request) {

Modified: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/mail/GMailEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/mail/GMailEndpoint.java?rev=900682&r1=900681&r2=900682&view=diff
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/mail/GMailEndpoint.java (original)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/mail/GMailEndpoint.java Tue Jan 19 07:09:00 2010
@@ -41,6 +41,10 @@
     
     private String to;
     
+    private String cc;
+    
+    private String bcc;
+    
     public GMailEndpoint(String endpointUri, String sender) {
         super(endpointUri);
         this.sender = sender;
@@ -82,6 +86,22 @@
         this.to = to;
     }
 
+    public String getCc() {
+        return cc;
+    }
+
+    public void setCc(String cc) {
+        this.cc = cc;
+    }
+
+    public String getBcc() {
+        return bcc;
+    }
+
+    public void setBcc(String bcc) {
+        this.bcc = bcc;
+    }
+
     public Consumer createConsumer(Processor processor) throws Exception {
         throw new UnsupportedOperationException("consumption from gmail endpoint not supported");
     }

Modified: camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/mail/GMailBindingTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/mail/GMailBindingTest.java?rev=900682&r1=900681&r2=900682&view=diff
==============================================================================
--- camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/mail/GMailBindingTest.java (original)
+++ camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/mail/GMailBindingTest.java Tue Jan 19 07:09:00 2010
@@ -28,6 +28,7 @@
 import static org.apache.camel.component.gae.mail.GMailTestUtils.createMessage;
 import static org.apache.camel.component.gae.mail.GMailTestUtils.getCamelContext;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 public class GMailBindingTest {
 
@@ -42,7 +43,11 @@
     @BeforeClass
     public static void setUpClass() throws Exception {
         binding = new GMailBinding();
-        endpoint = createEndpoint("gmail:[hidden email]?to=[hidden email]&subject=test");
+        endpoint = createEndpoint("gmail:[hidden email]" +
+         "?to=[hidden email]" +
+                "&cc=[hidden email]" +
+                "&bcc=[hidden email]" +
+         "&subject=test");
     }
     
     @Before
@@ -55,6 +60,9 @@
     public void testWriteFrom() {
         binding.writeFrom(endpoint, exchange, message);
         assertEquals("[hidden email]", message.getSender());
+        exchange.getIn().setHeader(GMailBinding.GMAIL_SENDER, "[hidden email]");
+        binding.writeFrom(endpoint, exchange, message);
+        assertEquals("[hidden email]", message.getSender());
     }
     
     @Test
@@ -67,6 +75,57 @@
     }
     
     @Test
+    public void testWriteCc() {
+        binding.writeCc(endpoint, exchange, message);
+        assertEquals("[hidden email]", message.getCc().iterator().next());
+        exchange.getIn().setHeader(GMailBinding.GMAIL_CC, "[hidden email]");
+        binding.writeCc(endpoint, exchange, message);
+        assertEquals("[hidden email]", message.getCc().iterator().next());
+    }
+    
+    @Test
+    public void testWriteBcc() {
+        binding.writeBcc(endpoint, exchange, message);
+        assertEquals("[hidden email]", message.getBcc().iterator().next());
+        exchange.getIn().setHeader(GMailBinding.GMAIL_BCC, "[hidden email]");
+        binding.writeBcc(endpoint, exchange, message);
+        assertEquals("[hidden email]", message.getBcc().iterator().next());
+    }
+    
+    @Test
+    public void testWriteToMultiple() {
+        binding.writeTo(endpoint, exchange, message);
+        assertEquals("[hidden email]", message.getTo().iterator().next());
+        exchange.getIn().setHeader(GMailBinding.GMAIL_TO, "[hidden email],[hidden email]");
+        binding.writeTo(endpoint, exchange, message);
+        assertEquals(2, message.getTo().size());
+        assertTrue(message.getTo().contains("[hidden email]"));
+        assertTrue(message.getTo().contains("[hidden email]"));
+    }
+    
+    @Test
+    public void testWriteCcMultiple() {
+        binding.writeCc(endpoint, exchange, message);
+        assertEquals("[hidden email]", message.getCc().iterator().next());
+        exchange.getIn().setHeader(GMailBinding.GMAIL_CC, "[hidden email],[hidden email]");
+        binding.writeCc(endpoint, exchange, message);
+        assertEquals(2, message.getCc().size());
+        assertTrue(message.getCc().contains("[hidden email]"));
+        assertTrue(message.getCc().contains("[hidden email]"));
+    }
+    
+    @Test
+    public void testWriteBccMultiple() {
+        binding.writeBcc(endpoint, exchange, message);
+        assertEquals("[hidden email]", message.getBcc().iterator().next());
+        exchange.getIn().setHeader(GMailBinding.GMAIL_BCC, "[hidden email],[hidden email]");
+        binding.writeBcc(endpoint, exchange, message);
+        assertEquals(2, message.getBcc().size());
+        assertTrue(message.getBcc().contains("[hidden email]"));
+        assertTrue(message.getBcc().contains("[hidden email]"));
+    }
+    
+    @Test
     public void testWriteSubject() {
         binding.writeSubject(endpoint, exchange, message);
         assertEquals("test", message.getSubject());

Modified: camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/mail/GMailEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/mail/GMailEndpointTest.java?rev=900682&r1=900681&r2=900682&view=diff
==============================================================================
--- camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/mail/GMailEndpointTest.java (original)
+++ camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/mail/GMailEndpointTest.java Tue Jan 19 07:09:00 2010
@@ -32,12 +32,16 @@
         StringBuffer buffer = new StringBuffer("gmail:[hidden email]")
             .append("?").append("subject=test")
             .append(AMP).append("to=[hidden email]")
+            .append(AMP).append("cc=[hidden email]")
+            .append(AMP).append("bcc=[hidden email]")
             .append(AMP).append("mailServiceRef=#mockMailService")
             .append(AMP).append("outboundBindingRef=#customBinding");
         GMailEndpoint endpoint = createEndpoint(buffer.toString());
         assertEquals("test", endpoint.getSubject());
         assertEquals("[hidden email]", endpoint.getSender());
         assertEquals("[hidden email]", endpoint.getTo());
+        assertEquals("[hidden email]", endpoint.getCc());
+        assertEquals("[hidden email]", endpoint.getBcc());
         assertFalse(endpoint.getOutboundBinding().getClass().equals(GMailBinding.class));
         assertTrue(endpoint.getOutboundBinding() instanceof GMailBinding);
         assertTrue(endpoint.getMailService() instanceof MockMailService);