Hi

Sounds like the attachments is stream based, and therfore only readable once.

See this related FAQ
http://camel.apache.org/why-is-my-message-body-empty.html


On Wed, Apr 24, 2013 at 11:41 AM, pokkie <izak.wess...@gmail.com> wrote:
> Hi,
>
> I am consuming emails with attachments in my application but I need to write
> the contents of the attachments out to an endpoint.
>
> Here is my route :
>
>  from("imap://user@mail.server?password=password")
>         .routePolicy(startPolicy).noAutoStartup()
>         .process(new MyMailProcessor())
>         .to("file:/tmp/mailout/");
>
> Here is MyMailProcessor as per (http://camel.apache.org/mail.html) :
>
> public class MyMailProcessor implements Processor
> {
>
>   @Override
>   public void process(Exchange exchange) throws Exception
>   {
>     // the API is a bit clunky so we need to loop
>     Map<String, DataHandler> attachments =
> exchange.getIn().getAttachments();
>
>     if (attachments.size() > 0)
>     {
>       for (String name : attachments.keySet())
>       {
>         DataHandler dh = attachments.get(name);
>         // get the file name
>         String filename = dh.getName();
>
>         // get the content and convert it to byte[]
>         byte[] data = exchange.getContext().getTypeConverter()
>             .convertTo(byte[].class, dh.getInputStream());
>
>         // write the data to a file
>         FileOutputStream out = new FileOutputStream(filename);
>         out.write(data);
>         out.flush();
>         out.close();
>       }
>     }
>   }
> }
>
> However, for some reason the file contents are no longer being written to
> /tmp/mailout. I say no longer because about a week ago I did have it working
> but for some reason, it now writes it out to the directory where the
> application is executing from and no longer written to the destination
> .to("file:/tmp/mailout/");
>
> Any ideas?
>
> Thanks
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Custom-processor-result-not-passed-to-endpoint-tp5731425.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cib...@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Reply via email to