骆驼 - 捕捉全球异常

时间:2013-02-01 14:22:03

标签: apache-camel apache-servicemix

我的路线中有很多转换,有时由于某些错误的文件或其他原因导致其中一些转换失败,所以当出现一些异常时我必须发送一封电子邮件。所以在上下文中我已声明如下:

<camel:onException useOriginalMessage="true">
  <camel:exception>javax.xml.transform.TransformerException</camel:exception>
  <camel:redeliveryPolicy maximumRedeliveries="3"/>
  <camel:to uri="smtp://localhost:25?From=noreply-esb@me.com&amp;To=me@me.com" />
</camel:onException>

但是没有任何事情发生,因为我的骆驼正在不停地进行转换而且还没有发送电子邮件。

这是日志:

2013-02-01 14:55:09,645 | WARN  | ox/products_list | GenericFileOnCompletion          | ?                                   ? | 92 - org.apache.camel.camel-core - 2.8.5 | Rollback file strategy: org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy@6fc72332 for file: GenericFile[/opt/servicemix/data/smx-data/outbox/products_list/product_export.xml]
2013-02-01 14:55:10,238 | ERROR | ox/products_list | DefaultErrorHandler              | ?                                   ? | 92 - org.apache.camel.camel-core - 2.8.5 | Failed delivery for exchangeId: ID-esb1-prod-prod-thesting-cyso-net-44582-1359563246542-5-1329. Exhausted after delivery attempt: 1 caught: javax.xml.transform.TransformerException: XML document structures must start and end within the same entity.
javax.xml.transform.TransformerException: XML document structures must start and end within the same entity.
        at org.apache.xalan.transformer.TransformerImpl.fatalError(TransformerImpl.java:780)[:]
        at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:756)[:]
        at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1273)[:]
        at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1251)[:]
        at org.apache.camel.builder.xml.XsltBuilder.process(XsltBuilder.java:123)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.impl.ProcessorEndpoint.onExchange(ProcessorEndpoint.java:102)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:72)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:48)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:114)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:284)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:109)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:69)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:90)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:318)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:209)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:306)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:116)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:79)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:111)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:69)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:61)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:114)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:284)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:109)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:69)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:90)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:318)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:209)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:306)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:111)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:69)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:61)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:114)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:284)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:109)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:69)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:90)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:306)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:318)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:209)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:139)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:106)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.MulticastProcessor.doProcessSequential(MulticastProcessor.java:573)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.MulticastProcessor.doProcessSequential(MulticastProcessor.java:506)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.MulticastProcessor.process(MulticastProcessor.java:219)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:69)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:90)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:306)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:139)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:106)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:69)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:353)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:176)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:137)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:139)[92:org.apache.camel.camel-core:2.8.5]
        at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:91)[92:org.apache.camel.camel-core:2.8.5]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)[:1.6.0_26]
        at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)[:1.6.0_26]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)[:1.6.0_26]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)[:1.6.0_26]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)[:1.6.0_26]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)[:1.6.0_26]
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_26]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_26]
        at java.lang.Thread.run(Thread.java:662)[:1.6.0_26]

我做错了吗?

1 个答案:

答案 0 :(得分:1)

如果转换失败,下次不太可能完成 - 数据错误。因此,针对您案件的重新发送政策要少一点。

但是,尝试将异常设置为已处理,然后设置smtp端点。

<camel:handled>
      <camel:constant>true</camel:constant>
</camel:handled>