You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by pokkie <iz...@gmail.com> on 2013/04/24 11:41:22 UTC
Custom processor result not passed to endpoint
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.
Re: Custom processor result not passed to endpoint
Posted by pokkie <iz...@gmail.com>.
Which was also picked up in 2008 :)
http://mail-archives.apache.org/mod_mbox/camel-users/200810.mbox/%3C4C1FB9C00D24A140906239533638C4D205AB72A5@EXVS04.exserver.dk%3E
--
View this message in context: http://camel.465427.n5.nabble.com/Custom-processor-result-not-passed-to-endpoint-tp5731425p5731475.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Custom processor result not passed to endpoint
Posted by pokkie <iz...@gmail.com>.
I sent the same attachment to a different mailbox and here is the exception
that I got when I tried to process it...
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
store file: /tmp/mailout/ID-defiant-55417-1366828640546-0-1
at
org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:271)
~[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.component.file.GenericFileProducer.writeFile(GenericFileProducer.java:257)
~[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.component.file.GenericFileProducer.processExchange(GenericFileProducer.java:159)
~[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.component.file.GenericFileProducer.process(GenericFileProducer.java:80)
~[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
~[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:122)
~[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:298)
~[camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:117)
~[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.interceptor.BacklogTracerInterceptor.process(BacklogTracerInterceptor.java:84)
~[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
~[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:390)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:273)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:335)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
[camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)
~[camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
~[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.FilterProcessor.process(FilterProcessor.java:58)
~[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.interceptor.BacklogTracerInterceptor.process(BacklogTracerInterceptor.java:84)
~[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
~[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:390)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:273)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:335)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:48)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:86)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.component.mail.MailConsumer.processExchange(MailConsumer.java:255)
[camel-mail-2.11.0.jar:2.11.0]
at
org.apache.camel.component.mail.MailConsumer.processBatch(MailConsumer.java:199)
[camel-mail-2.11.0.jar:2.11.0]
at org.apache.camel.component.mail.MailConsumer.poll(MailConsumer.java:118)
[camel-mail-2.11.0.jar:2.11.0]
at
org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:141)
[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:91)
[camel-core-2.11.0.jar:2.11.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
[na:1.7.0_17]
at
java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
[na:1.7.0_17]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
[na:1.7.0_17]
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
[na:1.7.0_17]
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
[na:1.7.0_17]
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
[na:1.7.0_17]
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
[na:1.7.0_17]
at java.lang.Thread.run(Thread.java:722) [na:1.7.0_17]
Caused by: org.apache.camel.InvalidPayloadException: No body available of
type: java.io.InputStream but has value:
javax.mail.internet.MimeMultipart@7265fa44 of type:
javax.mail.internet.MimeMultipart on: MailMessage: messageNumber=[13],
from=["LIFEESC (SYSTEM)" <li...@discovery.co.za>],
to=["discovery.sharenet@gmail.com" <di...@gmail.com>],
subject=[FW: Sharenet Delivery Data Price List], sentDate=[24 Apr 2013
8:33:42 PM], receivedDate=[24 Apr 2013 8:35:16 PM]. Caused by: No type
converter available to convert from type: javax.mail.internet.MimeMultipart
to the required type: java.io.InputStream with value
javax.mail.internet.MimeMultipart@7265fa44. Exchange[MailMessage:
messageNumber=[13], from=["LIFEESC (SYSTEM)" <li...@discovery.co.za>],
to=["discovery.sharenet@gmail.com" <di...@gmail.com>],
subject=[FW: Sharenet Delivery Data Price List], sentDate=[24 Apr 2013
8:33:42 PM], receivedDate=[24 Apr 2013 8:35:16 PM]]. Caused by:
[org.apache.camel.NoTypeConversionAvailableException - No type converter
available to convert from type: javax.mail.internet.MimeMultipart to the
required type: java.io.InputStream with value
javax.mail.internet.MimeMultipart@7265fa44]
at
org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:101)
~[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:262)
~[camel-core-2.11.0.jar:2.11.0]
... 76 common frames omitted
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type
converter available to convert from type: javax.mail.internet.MimeMultipart
to the required type: java.io.InputStream with value
javax.mail.internet.MimeMultipart@7265fa44
at
org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:181)
~[camel-core-2.11.0.jar:2.11.0]
at
org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99)
~[camel-core-2.11.0.jar:2.11.0]
... 77 common frames omitted
--
View this message in context: http://camel.465427.n5.nabble.com/Custom-processor-result-not-passed-to-endpoint-tp5731425p5731474.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Custom processor result not passed to endpoint
Posted by Claus Ibsen <cl...@gmail.com>.
Stream caching doesn't apply to attachments. You have to deal with
that yourselves.
On Wed, Apr 24, 2013 at 2:15 PM, pokkie <iz...@gmail.com> wrote:
> I have enabled StreamCaching as per the documentation but no luck.
>
> I have another email account but I cannot access that at work as we have a
> proxy server and I don't think (please correct me if I am wrong) its
> possible to configure the imap camel component to go through a proxy server.
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Custom-processor-result-not-passed-to-endpoint-tp5731425p5731435.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: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Re: Custom processor result not passed to endpoint
Posted by pokkie <iz...@gmail.com>.
I have enabled StreamCaching as per the documentation but no luck.
I have another email account but I cannot access that at work as we have a
proxy server and I don't think (please correct me if I am wrong) its
possible to configure the imap camel component to go through a proxy server.
--
View this message in context: http://camel.465427.n5.nabble.com/Custom-processor-result-not-passed-to-endpoint-tp5731425p5731435.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Custom processor result not passed to endpoint
Posted by Claus Ibsen <cl...@gmail.com>.
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 <iz...@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: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen