Josh
Josh

Reputation: 53

Apache Camel Simple predicate in XML route not working - need to convert header to String?

Any help here would be greatly appreciated :)

I have this code in my Camel route XML file:

<choice>
    <when>
        <simple>${header.CamelHttpQuery} not contains '%'</simple>
        <process ref="firstResponseTransformer"/>
    </when>
    <otherwise>
        <process ref="secondResponseTransformer"/>
    </otherwise>
</choice>

(I have also tried !contains)

As you can see, I want to go to different classes to prepare my response depending on a condition.

I can see by using a breakpoint in the processor hit previously in the route, that the value of exchange > in > headers > CamelHttpQuery is "" but regardless of whether the condition should be true, the transformer in the otherwise tag is always the one to be hit.

The simple statement looks correct to me based on the Camel docs, and I have other simple statements in the code base which seem to be working fine.

Anyone have any idea why the simple isn't working when it should be true?

Quite stuck. Thanks in advance.

Camel version 2.12.4

Edit: I think it is because I need to convert header.CamelHttpQuery from Character to String, does anyone know how to do this in Simple?

Upvotes: 1

Views: 1361

Answers (1)

Josh
Josh

Reputation: 53

The problem was that my header.CamelHttpQuery was Character not String.

As suggested by Bedla in above comment, I fixed with: <simple>${headerAs(CamelHttpQuery,String)} not contains '%'</simple>

Upvotes: 1

Related Questions