You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Steve973 <st...@gmail.com> on 2022/01/17 16:50:45 UTC
What is the correct way to build a Predicate from an Expression?
Hello. I am trying to create a Predicate from an Expression. The
Expression is created from a String. This is what I am trying to do:
String language = "simple";
String value = "${body} contains 'test'";
Expression expression = ExpressionBuilder.languageExpression(language,
value);
Predicate predicate = PredicateBuilder.toPredicate(expression);
My debugging output *looks* like I am creating it properly:
predicate: language[simple:${body} contains 'test']
But when I try to use this when processing an Exchange, I am getting a null
pointer exception:
java.lang.NullPointerException: null
at
org.apache.camel.support.builder.ExpressionBuilder$22.matches(ExpressionBuilder.java:784)
~[camel-support-3.15.0-SNAPSHOT.jar:3.15.0-SNAPSHOT]
Can anyone give me an idea about what I might be missing?
Thanks,
Steve
Re: What is the correct way to build a Predicate from an Expression?
Posted by Steve973 <st...@gmail.com>.
Thank you. That worked well!
Steve
On Mon, Jan 17, 2022 at 12:18 PM Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> Language lan = context.resolveLanguage("simple")
> Predicate p = lan.createPredicate(....)
> p.init(context)
>
>
>
> On Mon, Jan 17, 2022 at 5:50 PM Steve973 <st...@gmail.com> wrote:
> >
> > Hello. I am trying to create a Predicate from an Expression. The
> > Expression is created from a String. This is what I am trying to do:
> >
> > String language = "simple";
> > String value = "${body} contains 'test'";
> > Expression expression = ExpressionBuilder.languageExpression(language,
> > value);
> > Predicate predicate = PredicateBuilder.toPredicate(expression);
> >
> > My debugging output *looks* like I am creating it properly:
> > predicate: language[simple:${body} contains 'test']
> >
> > But when I try to use this when processing an Exchange, I am getting a
> null
> > pointer exception:
> > java.lang.NullPointerException: null
> > at
> >
> org.apache.camel.support.builder.ExpressionBuilder$22.matches(ExpressionBuilder.java:784)
> > ~[camel-support-3.15.0-SNAPSHOT.jar:3.15.0-SNAPSHOT]
> >
> > Can anyone give me an idea about what I might be missing?
> >
> > Thanks,
> > Steve
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>
Re: What is the correct way to build a Predicate from an Expression?
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Language lan = context.resolveLanguage("simple")
Predicate p = lan.createPredicate(....)
p.init(context)
On Mon, Jan 17, 2022 at 5:50 PM Steve973 <st...@gmail.com> wrote:
>
> Hello. I am trying to create a Predicate from an Expression. The
> Expression is created from a String. This is what I am trying to do:
>
> String language = "simple";
> String value = "${body} contains 'test'";
> Expression expression = ExpressionBuilder.languageExpression(language,
> value);
> Predicate predicate = PredicateBuilder.toPredicate(expression);
>
> My debugging output *looks* like I am creating it properly:
> predicate: language[simple:${body} contains 'test']
>
> But when I try to use this when processing an Exchange, I am getting a null
> pointer exception:
> java.lang.NullPointerException: null
> at
> org.apache.camel.support.builder.ExpressionBuilder$22.matches(ExpressionBuilder.java:784)
> ~[camel-support-3.15.0-SNAPSHOT.jar:3.15.0-SNAPSHOT]
>
> Can anyone give me an idea about what I might be missing?
>
> Thanks,
> Steve
--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2