camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Jackson <foamd...@gmail.com>
Subject Re: Testing consuming mail with attachments
Date Sat, 13 Mar 2010 09:31:08 GMT
Hi,

This is a follow up to conclude how I tested consuming mail
attachments in camel 2.1 + spring.  Posting here because others on the
user list may find this useful going forward.

With camel 2.1 it doesn't seem to be possible to completely decouple
the processing of email messages with attachments from some link to
camel.  My goal was to have a simple POJO with a single method which
would accept an attachment and write it to disk.

Using the Processor interface as suggested[1] in the docs would have
meant that the bean was no longer a POJO.  I also wanted to avoid if
possible being coupled to the camel datatypes (Exchange etc).

Using bean parameter binding[2] I could specify which param should be
treated as a Header or Body, but there (as yet) isn't an @Attachments.

I settled on the following signature in my process method:

public void process(Message msg) throws Exception

Where the only coupling to camel is in the Message datatype

With an @Attachments binding I could have decoupled a step further to

public void process(@Attachments Map<String, DataHandler> msg) throws
Exception (however the @Attachments would still be camel specific code
- but I guess that's about the least coupled you can get).

The alternative of course would be if the consumption of an email from
a mailbox would produce a message of the type MimeMessage, not the
camel specific Message (indeed MailMessage).

So the flow is:

camel-mail endpoint receives email -> converts to camel MailMessage ->
my processor (which has to handle camel Message) -> disk

I'm not sure whether or not my use-case points to a missing annotation
for @Attachments, but I suggest at least for the sake of completeness
that this annotation be added to camel trunk:

package org.apache.camel;

import java.lang.annotation.Documented;

/**
 * Marks a parameter as being an injection point of the attachments of
an inbound {@link Message}
 *
 * @see Message#getAttachments()
 */
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Target({ElementType.PARAMETER })
public @interface Attachments {
}

Thanks for the help,
Kev

[1] http://camel.apache.org/mail.html
[2] http://camel.apache.org/parameter-binding-annotations.html

Mime
View raw message