Apache camel onException和deadLetterChannel问题

时间:2012-03-08 04:05:21

标签: java apache-camel

我已将路由配置为将邮件重新传送3次到HTTP网址,并在所有重新传递尝试失败时记录该邮件。这按预期工作。但是,正如您在日志中看到的那样,HttpOperationFailedException似乎仍然传播到errorHandler(deadLetterChannel("log:com.xcg.routes?level=ERROR&showAll=true&multiline=true").useOriginalMessage());。我不希望将其传播到deadLetterChannel。我只是希望onException(HttpOperationFailedException.class)记录它。怎么做?

**路线Def **

@Override
public void configure()
{
    onException(HttpOperationFailedException.class).maximumRedeliveries(3).redeliveryDelay(1000).to("log:com.xcg.routes?level=WARN&showAll=true&multiline=true");
    errorHandler(deadLetterChannel("log:com.xcg.routes?level=ERROR&showAll=true&multiline=true").useOriginalMessage());
    from("file://C:/temp/orders/incoming?move=processed&moveFailed=failed")
        .bean(new OrderEdiTocXml(smooksOrder))
        .to("file://C:/temp/orders/incoming?move=processed&moveFailed=failed")
        .convertBodyTo(String.class).
        .convertBodyTo(Document.class).choice()
        .when(xpath("/cXML/Response/Status/@text='OK'"))
        .to("file://C:/temp/orders/valid" + "?fileName=${header.CamelFileNameOnly}.xml")
        .otherwise()
        .to("file://C:/temp/error?fileName=${header.CamelFileNameOnly}-failed-validation.xml");
}

LOG

[Invalid file specified for console output: C:\Status.log]
[                      Thread-1] FakeFtpServer                  INFO  Starting the server on port 0
[                      Thread-1] FakeFtpServer                  INFO  Actual server port is 53765
[                          main] MainSupport                    INFO  Apache Camel 2.9.0 starting
[                          main] AnnotationTypeConverterLoader  INFO  Found 3 packages with 15 @Converter classes to load
[                          main] DefaultTypeConverter           INFO  Loaded 168 core type converters (total 168 type converters)
[                          main] AnnotationTypeConverterLoader  INFO  Loaded 2 @Converter classes
[                          main] DefaultTypeConverter           INFO  Loaded additional 9 type converters (total 177 type converters) in 0.010 seconds
[                          main] DefaultCamelContext            INFO  Apache Camel 2.9.0 (CamelContext: camel-1) is starting
[                          main] ManagementStrategyFactory      INFO  JMX enabled. Using ManagedManagementStrategy.
[                          main] ultManagementLifecycleStrategy INFO  StatisticsLevel at All so enabling load performance statistics
[                          main] HttpComponent                  INFO  Created ClientConnectionManager org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager@8b058b
[                          main] HttpComponent                  INFO  Registering PLAIN scheme http on port 8080
[                          main] HttpComponent                  INFO  Registering PLAIN scheme http4 on port 8080
[                          main] HttpComponent                  INFO  Registering PLAIN scheme http on port 8080
[                          main] HttpComponent                  INFO  Registering PLAIN scheme http4 on port 8080
[                          main] DefaultCamelContext            INFO  Route: route1 started and consuming from: Endpoint[file://C:/temp/orders/incoming?move=processed&moveFailed=failed]
[                          main] DefaultCamelContext            INFO  Route: route2 started and consuming from: Endpoint[file://C:/temp/invoices/incoming?move=processed]
[                          main] DefaultCamelContext            INFO  Total 2 routes, of which 2 is started.
[                          main] DefaultCamelContext            INFO  Apache Camel 2.9.0 (CamelContext: camel-1) started in 0.585 seconds
UnbInterchangeOrder [order=UnhOrder [messageReferenceNumber=1, messageType=ORDERS, versionNumber=D, releaseNumber=01B, controllingAgency=UN, associationAssignedCode=EAN010, beginningOfMessage=BgmBeginningOfMessage [messageNameCode=220, messageIdentifier=R-95300561X, messageFunctionCode=9], dateTimePeriodList=[DtmDateTimePeriod [functionCode=137, text=20110210, formatCode=102], DtmDateTimePeriod [functionCode=2, text=20110211, formatCode=102]], nameAndAddressList=[NadNameAndAddress [partyFunctionCodeQualifier=BY, partyIdentifier=9313938000631, codeListIdentificationCode=, codeListResponsibleAgencyCode=9], NadNameAndAddress [partyFunctionCodeQualifier=ST, partyIdentifier=9216GR, codeListIdentificationCode=, codeListResponsibleAgencyCode=92], NadNameAndAddress [partyFunctionCodeQualifier=SU, partyIdentifier=963725, codeListIdentificationCode=, codeListResponsibleAgencyCode=92]], lineItemList=[LinLineItem [lineItemIdentifier=1, actionRequest=, itemIdentifier=19300601396099, itemTypeIdentificationCode=SRV, quantityList=[QtyQuantity [quantityTypeCodeQualifier=21, quantity=4]], price=PriPrice [priceCodeQualifier=1E, priceAmount=5.412]]], monetaryAmountTypeCodeQualifier=86, monetaryAmount=21.648], UnbInterchange [syntaxIdentifier=UNOA, syntaxVersionNumber=3, senderIdentifier=9313938000631, senderCodeQualifier=ZZ, recipientIdentifier=9343015000575, recipientCodeQualifier=ZZ, date=Tue Nov 02 00:00:00 EDT 2010, time=Thu Jan 01 09:26:00 EST 1970, controlRef=1, ackRequest=1]]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.022/cXML.dtd">
<cXML payloadID="1" timestamp="2010-11-02T09:26:00-0400"><Header><From><Credential domain="9313938000631" /></From><To><Credential domain="9343015000575" /></To></Header><Request><OrderRequest><OrderRequestHeader orderID="R-95300561X" orderDate="2011-02-10T00:00:00-0500"><Total><Money currency="AUD">21.648</Money></Total><ShipTo><Address><Name xml:lang="en">9216GR</Name></Address></ShipTo></OrderRequestHeader><ItemOut quantity="4" lineNumber="1"><ItemID><SupplierPartID>19300601396099</SupplierPartID></ItemID><ItemDetail><UnitPrice><Money currency="AUD">5.412</Money></UnitPrice></ItemDetail></ItemOut></OrderRequest></Request></cXML>

[3 - ErrorHandlerRedeliveryTask] routes                         WARN  Exchange[
, Id:ID-Owner-PC-53766-1331180687900-0-1
, ExchangePattern:InOnly
, Properties:{CamelToEndpoint=log://com.xcg.routes?level=WARN&multiline=true&showAll=true, CamelBatchComplete=true, CamelBatchSize=1, CamelCreatedTimestamp=Wed Mar 07 23:24:53 EST 2012, CamelFailureEndpoint=http4://host:port/cXML/Mai, CamelFileExchangeFile=GenericFile[C:\temp\orders\incoming\po-request.edi], CamelBatchIndex=0, CamelExceptionCaught=org.apache.camel.component.http4.HttpOperationFailedException: HTTP operation failed invoking http://host:port/cXML/Mai with statusCode: 404}
, Headers:{CamelFileAbsolutePath=C:\temp\orders\incoming\po-request.edi, CamelFileRelativePath=po-request.edi, CamelRedelivered=true, CamelRedeliveryCounter=3, CamelFileLastModified=Thu Feb 09 22:45:42 EST 2012, CamelFileAbsolute=true, CamelFileParent=C:\temp\orders\incoming, CamelFileNameOnly=po-request.edi, CamelRedeliveryMaxCounter=3, CamelFileLength=308, CamelFileName=po-request.edi, CamelFilePath=C:\temp\orders\incoming\po-request.edi, breadcrumbId=ID-Owner-PC-53766-1331180687900-0-2}
, BodyType:String
, Body:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.022/cXML.dtd">
<cXML payloadID="1" timestamp="2010-11-02T09:26:00-0400"><Header><From><Credential domain="9313938000631" /></From><To><Credential domain="9343015000575" /></To></Header><Request><OrderRequest><OrderRequestHeader orderID="R-95300561X" orderDate="2011-02-10T00:00:00-0500"><Total><Money currency="AUD">21.648</Money></Total><ShipTo><Address><Name xml:lang="en">9216GR</Name></Address></ShipTo></OrderRequestHeader><ItemOut quantity="4" lineNumber="1"><ItemID><SupplierPartID>19300601396099</SupplierPartID></ItemID><ItemDetail><UnitPrice><Money currency="AUD">5.412</Money></UnitPrice></ItemDetail></ItemOut></OrderRequest></Request></cXML>

, CaughtExceptionType:org.apache.camel.component.http4.HttpOperationFailedException, CaughtExceptionMessage:HTTP operation failed invoking http://host:port/cXML/Mai with statusCode: 404, StackTrace:org.apache.camel.component.http4.HttpOperationFailedException: HTTP operation failed invoking http://host:port/cXML/Mai with statusCode: 404
    at org.apache.camel.component.http4.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:223)
    at org.apache.camel.component.http4.HttpProducer.process(HttpProducer.java:151)
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:115)
    at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:285)
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:110)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:71)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.RedeliveryErrorHandler$AsyncRedeliveryTask.call(RedeliveryErrorHandler.java:131)
    at org.apache.camel.processor.RedeliveryErrorHandler$AsyncRedeliveryTask.call(RedeliveryErrorHandler.java:99)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

, Out: null
]
[3 - ErrorHandlerRedeliveryTask] GenericFileOnCompletion        WARN  Rollback file strategy: org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy@8905bd for file: GenericFile[C:\temp\orders\incoming\po-request.edi]
[3 - ErrorHandlerRedeliveryTask] DeadLetterChannel              ERROR Failed delivery for exchangeId: ID-Owner-PC-53766-1331180687900-0-1. Exhausted after delivery attempt: 4 caught: org.apache.camel.component.http4.HttpOperationFailedException: HTTP operation failed invoking http://host:port/cXML/Mai with statusCode: 404. Processed by failure processor: FatalFallbackErrorHandler[Channel[sendTo(Endpoint[log://com.xcg.routes?level=WARN&multiline=true&showAll=true])]]
org.apache.camel.component.http4.HttpOperationFailedException: HTTP operation failed invoking http://host:port/cXML/Mai with statusCode: 404
    at org.apache.camel.component.http4.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:223)[camel-http4-2.9.0.jar:2.9.0]
    at org.apache.camel.component.http4.HttpProducer.process(HttpProducer.java:151)[camel-http4-2.9.0.jar:2.9.0]
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:115)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:285)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:110)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:71)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.RedeliveryErrorHandler$AsyncRedeliveryTask.call(RedeliveryErrorHandler.java:131)[camel-core-2.9.0.jar:2.9.0]
    at org.apache.camel.processor.RedeliveryErrorHandler$AsyncRedeliveryTask.call(RedeliveryErrorHandler.java:99)[camel-core-2.9.0.jar:2.9.0]
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)[:1.6.0_27]
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)[:1.6.0_27]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)[:1.6.0_27]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)[:1.6.0_27]
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_27]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_27]
    at java.lang.Thread.run(Thread.java:662)[:1.6.0_27]

1 个答案:

答案 0 :(得分:4)

如果要抑制异常,则需要使用processed(true)。

 onException(HttpOperationFailedException.class)
   .maximumRedeliveries(3).redeliveryDelay(1000)
   .handled(true)
   .to("log:com.xcg.routes?level=WARN&showAll=true&multiline=true");