You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by huntc <hu...@mac.com> on 2010/01/13 11:47:43 UTC

Retrieving MailMessage bodies as DataHandler objects

Hi there,

Supposing that I receive an Exchange using Camel Mail and I want to see
whether the body is of the required MIME type; is it valid to do this:

  // See if our exchange body contains the calendar object.
  DataHandler bodyDataHandler = exchange.getIn().getBody(
  		DataHandler.class);
  if (bodyDataHandler != null) {
    ...
  }

I know that I can retrieve attachments as DataHandlers, but am I able to do
so for the body itself? The documentation implies that the body is coerced
to a string...

I have already incorporated the above code in my application and I'm waiting
for someone to send the type of message that may also answer this post.
However it'll be several hours before I know.

Thanks!

Kind regards,
Christopher
-- 
View this message in context: http://old.nabble.com/Retrieving-MailMessage-bodies-as-DataHandler-objects-tp27142905p27142905.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Retrieving MailMessage bodies as DataHandler objects

Posted by huntc <hu...@mac.com>.

Claus Ibsen-2 wrote:
> 
> You can get access to the underlying javax.mail.Message...
> 
Thanks Claus. I'm now trying out the following and just waiting for another
message to come through:


  // See if our exchange body contains the calendar object.
  javax.mail.Message mailMessage = exchange.getIn(MailMessage.class)
    .getMessage();
  if (logger.isDebugEnabled()) {
    logger.debug("Message received: " + mailMessage);
  }
  try {
    DataHandler bodyDataHandler = mailMessage.getDataHandler();
    if (bodyDataHandler != null) {
      addCalendarDataToCalendars(calendars, bodyDataHandler);
    }
  } catch (MessagingException e) {
    logger.error(e);
  }


-- 
View this message in context: http://old.nabble.com/Retrieving-MailMessage-bodies-as-DataHandler-objects-tp27142905p27158347.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Retrieving MailMessage bodies as DataHandler objects

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You can get access to the underlying javax.mail.Message
https://svn.apache.org/repos/asf/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailMessage.java

javax.mail.Message mailMessage = exchange.getIn(MailMessage.class).getMessge();

And maybe there is a type converter for that as well. I cant remember
javax.mail.Message mailMessage = exchage.getIn().getBody(javax.mail.Message);



On Wed, Jan 13, 2010 at 11:47 AM, huntc <hu...@mac.com> wrote:
>
> Hi there,
>
> Supposing that I receive an Exchange using Camel Mail and I want to see
> whether the body is of the required MIME type; is it valid to do this:
>
>  // See if our exchange body contains the calendar object.
>  DataHandler bodyDataHandler = exchange.getIn().getBody(
>                DataHandler.class);
>  if (bodyDataHandler != null) {
>    ...
>  }
>
> I know that I can retrieve attachments as DataHandlers, but am I able to do
> so for the body itself? The documentation implies that the body is coerced
> to a string...
>
> I have already incorporated the above code in my application and I'm waiting
> for someone to send the type of message that may also answer this post.
> However it'll be several hours before I know.
>
> Thanks!
>
> Kind regards,
> Christopher
> --
> View this message in context: http://old.nabble.com/Retrieving-MailMessage-bodies-as-DataHandler-objects-tp27142905p27142905.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
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

Re: Retrieving MailMessage bodies as DataHandler objects

Posted by huntc <hu...@mac.com>.

willem.jiang wrote:
> 
> Camel Message has getAttachements() method which can help you get the 
> DataHandlers.
> 
Thanks Willem - I know about the attachments. My case is where I'm dealing
with a single part message and its not text content i.e. its text/calendar.
-- 
View this message in context: http://old.nabble.com/Retrieving-MailMessage-bodies-as-DataHandler-objects-tp27142905p27158300.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Retrieving MailMessage bodies as DataHandler objects

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

Camel Message has getAttachements() method which can help you get the 
DataHandlers.
You can find the unit test of camel-mail here[1]

[1] 
https://svn.apache.org/repos/asf/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailAttachmentTest.java

Willem

huntc wrote:
> Hi there,
> 
> Supposing that I receive an Exchange using Camel Mail and I want to see
> whether the body is of the required MIME type; is it valid to do this:
> 
>   // See if our exchange body contains the calendar object.
>   DataHandler bodyDataHandler = exchange.getIn().getBody(
>   		DataHandler.class);
>   if (bodyDataHandler != null) {
>     ...
>   }
> 
> I know that I can retrieve attachments as DataHandlers, but am I able to do
> so for the body itself? The documentation implies that the body is coerced
> to a string...
> 
> I have already incorporated the above code in my application and I'm waiting
> for someone to send the type of message that may also answer this post.
> However it'll be several hours before I know.
> 
> Thanks!
> 
> Kind regards,
> Christopher