2

Is there a way to do smth like this to work? I am talking about the condition inside when.

.choice()
       .when(Exchange::isFailed)
         .to(direct(URI_DEADLETTER))

I tried:

.when(method(Exchange.class, "isFailed"))
.when().exchange(Exchange::isFailed)

For the first solution an error is thrown and the second is not working. I know that I can create a new class and a method inside, from here: How do i use java boolean condition in camel route? And I read about the predicat here: http://www.davsclaus.com/2009/02/apache-camel-and-using-compound.html. But without using a new class or predicat, is there a way that I can achieve this?

agata
  • 481
  • 2
  • 9
  • 29

1 Answers1

3

A lazy solution is to use Camel simple language (http://camel.apache.org/simple.html) which allows you to access anything (headers, properties, body, method, etc..) of current exchange

.choice()
.when( simple("${exception} != null") )

A more OO solution would be to use Camel Predicate (Builder):

Predicate condition1 = ...
Predicate condition2 = ...; 
Predicate isFailed = PredicateBuilder.or(condition1, condition2);   


.choice()
    .when( isFailed )   
TacheDeChoco
  • 3,683
  • 1
  • 14
  • 17