You could make a Processor that gives you control to carry the message forward,
even to multiple places.
Clearly this is versatile, you can customize. Creating a deep copy --
exchange.copy() (Camel 3) and exchange.copy(true) Camel 2 are helpful here.
```
ProducerTemplate producer = camelContext.createProducerTemplate();
Endpoint routeDestination = camelContext.getEndpoint("seda:nextStep");
Endpoing exceptionDestination =
camelContext.getEndpoint("seda:exception processing");
Exchange exchangeException = exchange.copy();
// OR
Exchange exchangeException = ExchangeBuilder.anExchange(camelContext)
.withPattern(ExchangePattern.InOptionalOut)
.withProperty("exception thrown!", message)
.withBody(message.getBody())
.build();
try {
// step 1 that is evil and throws an exception that should not stop
route but needs handling
// you could maybe call SomeProcessor.process() and not have to
change source code too much or call a converter directly
producer.asyncSend(exchangeDestination, exchange);
exchangeException.getIn().setBody(step1Result);
} catch ..... {
// what do you need for exception processing?
exchangeException.getIn().setBody(e, Exception.class);
// process error and keep going
producer.asyncSend(exchangeException, exchangeException);
producer.asyncSend(exchangeDestination, exchange);
// depending on how much exception handling is needed, you might
not need another route.
}
```
Sincerely,
Jeremy Cox
Software Engineer
Universal Gateway at Progeny Systems
Urgent contact: Text 859.322.3214
Email [email protected]
-----Original Message-----
From: Harsh Karn [mailto:[email protected]]
Sent: Thursday, July 15, 2021 9:54 AM
To: [email protected]
Subject: Re: Exit split on exception but continue route
External E-mail --- CAUTION: This email originated from outside Progeny
Systems. Do not click links or open attachments unless you recognize the sender
and know the content is safe.
Yes. With .handled(true) it still stops the route immediately when
stopOnException() is set.
Without .stopOnException() it just continues as normal. What I'm trying to do
is to stop the split on exception but continue remaining steps in the route
after the split.
*Thanks*
*Harsh*
On Thu, Jul 15, 2021 at 2:00 AM Вячеслав Бойко <[email protected]> wrote:
> Hi!
>
> Did you try
>
> .onException(YourException.class)
> . handle(true)
>
> ?
>
> Harsh Karn <[email protected]> 14 июля 2021 г. 23:34:11 написал:
>
> > Hi,
> >
> > Is there any way to stop executing split on exception but continue
> running
> > the rest of the route after split or the outer route?
> >
> > I tried setting stopOnException() but it stops the route immediately
> > and nothing can be done following the exception.
> >
> > I tried using aggregationtrategy but I don't see any option to stop
> running
> > split if I see exception raised or handled.
> >
> > *Thanks*
> > *Harsh*
>
>