Hello, On Wed, Oct 14, 2015 at 3:13 PM, jamesburn <james.b...@oup.com> wrote: > Hi > > I'm using exec to call a BASH script to do some stuff. The output of exec is > returned as the body of my processed message, so I'm able, with <simple>, to > pick out whether the script succeeded: > > ... > <recipientList> > <simple>exec:PDFInvoicesCurl.sh?args=${file:name} {{InputFolder}} > {{SendURL}}</simple> > </recipientList> > <convertBodyTo type="String"/> > <choice> > <when> > <simple>${body} not contains 'HTTP/1.1 200 OK'</simple> > <log message="Problem with PDF Invoice send" > loggingLevel="WARN"/> > </when> > </choice> > ... > > This is great, but I'd like to try the BASH script again a couple of times > if the exec fails. The way to do this seems to use onException: > > http://camel.apache.org/how-do-i-retry-processing-a-message-from-a-certain-point-back-or-an-entire-route.html > <http://camel.apache.org/how-do-i-retry-processing-a-message-from-a-certain-point-back-or-an-entire-route.html> > > Is there a way to get the output of the exec (body) into the exception so I > can do a redelivery. Or can I setup a redelivery attempt based on my > <choice><when> above? >
Yes you can do this by seperating your litte snippet in a subroute, disable errorhandling in the subroute like the docs you linked say, throw an exception with the body in the message in your <when>. Note that when using redeliverypolicy, the body of the failed exchange will be caught by onException when redelivery has been exhausted. So you can get the body in both exchange body and exception message if you want. Your exception will be found in the property "CamelExceptionCaught" after exhausted redelivery. Of course other things can fail seperately and you need to handle that as well, either in onException or with the errorhandler. Something like this? <route errorHandlerRef="noErrorHandler"> <from uri="direct:execPdfInvoicesCurl"/> <onException> <exception>org.example.PdfInvoiceException</exception> <redeliveryPolicy maximumRedeliveries="3" redeliveryDelay="100"/> <!-- do errorhandling stuff for this exception --> </onException> <recipientList> <simple>exec:PDFInvoicesCurl.sh?args=${file:name} {{InputFolder}} {{SendURL}}</simple> </recipientList> <convertBodyTo type="String"/> <choice> <when> <simple>${body} not contains 'HTTP/1.1 200 OK'</simple> <throwException exceptionType="org.example.PdfInvoiceException" message="${body}"/> </when> </choice> </route> Please note I don't usually use XML route declarations. Also not sure if <throwException> allows simple language in message in 2.13.x > Using Camel 2.13.2 > > Thanks > > James > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Output-of-exec-used-for-exception-handling-to-enable-message-redelivery-tp5772641.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Kind regards Joakim Bjørnstad