camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: 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/
Date Tue, 19 Jan 2010 08:16:16 GMT
Hi

Is it possible to use the Camel syntax for header keys?

> +    public static final String GMAIL_SENDER = "org.apache.camel.component.gae.mail.Sender";

Should be

    public static final String GMAIL_SENDER = "CamelGaeMailSender";

Using dots in keys causes issues when wiring over some transports.
And then it also doesn't look like a Class or Class name which people
could mistake it with.


On Tue, Jan 19, 2010 at 8:09 AM,  <krasserm@apache.org> wrote:
> 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:user1@gmail.com?to=user2@gmail.com&subject=test");
> +        endpoint = createEndpoint("gmail:user1@gmail.com" +
> +                       "?to=user2@gmail.com" +
> +                "&cc=user4@gmail.com" +
> +                "&bcc=user5@gmail.com" +
> +                       "&subject=test");
>     }
>
>     @Before
> @@ -55,6 +60,9 @@
>     public void testWriteFrom() {
>         binding.writeFrom(endpoint, exchange, message);
>         assertEquals("user1@gmail.com", message.getSender());
> +        exchange.getIn().setHeader(GMailBinding.GMAIL_SENDER, "user3@gmail.com");
> +        binding.writeFrom(endpoint, exchange, message);
> +        assertEquals("user3@gmail.com", message.getSender());
>     }
>
>     @Test
> @@ -67,6 +75,57 @@
>     }
>
>     @Test
> +    public void testWriteCc() {
> +        binding.writeCc(endpoint, exchange, message);
> +        assertEquals("user4@gmail.com", message.getCc().iterator().next());
> +        exchange.getIn().setHeader(GMailBinding.GMAIL_CC, "user3@gmail.com");
> +        binding.writeCc(endpoint, exchange, message);
> +        assertEquals("user3@gmail.com", message.getCc().iterator().next());
> +    }
> +
> +    @Test
> +    public void testWriteBcc() {
> +        binding.writeBcc(endpoint, exchange, message);
> +        assertEquals("user5@gmail.com", message.getBcc().iterator().next());
> +        exchange.getIn().setHeader(GMailBinding.GMAIL_BCC, "user3@gmail.com");
> +        binding.writeBcc(endpoint, exchange, message);
> +        assertEquals("user3@gmail.com", message.getBcc().iterator().next());
> +    }
> +
> +    @Test
> +    public void testWriteToMultiple() {
> +        binding.writeTo(endpoint, exchange, message);
> +        assertEquals("user2@gmail.com", message.getTo().iterator().next());
> +        exchange.getIn().setHeader(GMailBinding.GMAIL_TO, "user3@gmail.com,user4@gmail.com");
> +        binding.writeTo(endpoint, exchange, message);
> +        assertEquals(2, message.getTo().size());
> +        assertTrue(message.getTo().contains("user3@gmail.com"));
> +        assertTrue(message.getTo().contains("user4@gmail.com"));
> +    }
> +
> +    @Test
> +    public void testWriteCcMultiple() {
> +        binding.writeCc(endpoint, exchange, message);
> +        assertEquals("user4@gmail.com", message.getCc().iterator().next());
> +        exchange.getIn().setHeader(GMailBinding.GMAIL_CC, "user3@gmail.com,user4@gmail.com");
> +        binding.writeCc(endpoint, exchange, message);
> +        assertEquals(2, message.getCc().size());
> +        assertTrue(message.getCc().contains("user3@gmail.com"));
> +        assertTrue(message.getCc().contains("user4@gmail.com"));
> +    }
> +
> +    @Test
> +    public void testWriteBccMultiple() {
> +        binding.writeBcc(endpoint, exchange, message);
> +        assertEquals("user5@gmail.com", message.getBcc().iterator().next());
> +        exchange.getIn().setHeader(GMailBinding.GMAIL_BCC, "user3@gmail.com,user4@gmail.com");
> +        binding.writeBcc(endpoint, exchange, message);
> +        assertEquals(2, message.getBcc().size());
> +        assertTrue(message.getBcc().contains("user3@gmail.com"));
> +        assertTrue(message.getBcc().contains("user4@gmail.com"));
> +    }
> +
> +    @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:user1@gmail.com")
>             .append("?").append("subject=test")
>             .append(AMP).append("to=user2@gmail.com")
> +            .append(AMP).append("cc=user3@gmail.com")
> +            .append(AMP).append("bcc=user4@gmail.com")
>             .append(AMP).append("mailServiceRef=#mockMailService")
>             .append(AMP).append("outboundBindingRef=#customBinding");
>         GMailEndpoint endpoint = createEndpoint(buffer.toString());
>         assertEquals("test", endpoint.getSubject());
>         assertEquals("user1@gmail.com", endpoint.getSender());
>         assertEquals("user2@gmail.com", endpoint.getTo());
> +        assertEquals("user3@gmail.com", endpoint.getCc());
> +        assertEquals("user4@gmail.com", endpoint.getBcc());
>         assertFalse(endpoint.getOutboundBinding().getClass().equals(GMailBinding.class));
>         assertTrue(endpoint.getOutboundBinding() instanceof GMailBinding);
>         assertTrue(endpoint.getMailService() instanceof MockMailService);
>
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Mime
View raw message