You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache Camel Choice组件When条件判断报错求助:SimpleIllegalSyntaxException

Fixing SimpleIllegalSyntaxException in Apache Camel Choice When Condition

Let's break down why you're hitting that error first:

SimpleIllegalSyntaxException: is operator cannot find class with name: VS at location 22 ${body.recType} is 'VS'

In Apache Camel's Simple language, the is operator is designed to check object types, not string equality. When you write ${body.recType} is 'VS', Camel tries to locate a class named VS (which doesn't exist in your codebase), hence the syntax exception.

Valid Solutions to Compare String Values

Here are a few reliable ways to check if recType matches the constant 'VS':

1. Use the == operator for string equality

The Simple language uses == to compare string values directly. Update your when condition like this:

from("direct:processAccounts")
    .process(filterProcessor)
    .split(simple("${body}"))
    .choice()
        .when(simple("${body.recType} == 'VS'"))
            .process((exchange) -> {
                log.info("VS:");
            })
        .otherwise()
            .to("stream:out");

2. Use the explicit eq function

For more readable equality checks, you can use the eq function instead:

.when(simple("${body.recType} eq 'VS'"))

3. Type-safe Java Predicate (avoid Simple language parsing)

If you want to skip Simple language syntax entirely and use type-safe code, you can directly check the value via the entity's getter method:

.when(exchange -> {
    Records record = exchange.getIn().getBody(Records.class);
    return "VS".equals(record.getRecType());
})

This approach eliminates any parsing-related errors and gives you full control over the comparison logic.

Quick Reminder

Keep these Simple language rules in mind for future use:

  • is = checks if an object is an instance of a specific class (e.g., ${body} is com.example.Records)
  • == / eq = checks value equality for strings, numbers, and primitives

内容的提问来源于stack exchange,提问作者Jericho

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:29:36