Java 为什么我的Apache Camel条件路由总是执行第一个选项?
我有一个驼峰路径(除其他外)应该运行验证器,但只有当设置了某个属性时,即Java 为什么我的Apache Camel条件路由总是执行第一个选项?,java,routes,apache-camel,choice,Java,Routes,Apache Camel,Choice,我有一个驼峰路径(除其他外)应该运行验证器,但只有当设置了某个属性时,即com.acme.ValidatorOn 路线的相关部分如下所示: <choice> <when> <simple>{{com.acme.ValidatorOn}} == true</simple> <to uri="validator:MyWebService.xsd" /> </when> </c
com.acme.ValidatorOn
路线的相关部分如下所示:
<choice>
<when>
<simple>{{com.acme.ValidatorOn}} == true</simple>
<to uri="validator:MyWebService.xsd" />
</when>
</choice>
即使使用伪造的属性名,验证程序仍在执行。因此,我更进一步,还添加了一个
:
<choice>
<when>
<simple>5 == 6</simple>
<log message="first choice" />
</when>
<otherwise>
<log message="second choice"/>
</otherwise>
</choice>
回答晚了,但将来可能会有帮助。发件人: 解析器仅限于支持单个运算符。
要启用它,左值必须包含在
${}
中。语法是:
${leftValue} OP rightValue
必须使用简单表达式。也就是说,使用属性的值设置头,然后在
中使用${headers.yourHeader}
EDIT:我找到了一个更好的解决方案:使用一种简单的方法获取属性:
${properties:com.acme.ValidatorOn}
在哪里找到了使用“{{}}”占位符而不是“${}”占位符的例子?我有一个名为springpropertyconfiguer
的bean,它定义了{{
和一个占位符后缀}
,用于来自特定属性文件的任何属性。这在我的应用程序中的其他路由中也适用。对我来说,这个问题看起来很奇怪,但一般来说,如果左侧没有使用exchange()的数据进行函数计算,则不建议使用SIMPLE请看我发布的链接中的评论。您是否尝试将其替换为spel?#{com.blahblahthiswillnotwork.ValidatorOn==true}您是否找到了解决问题的方法?
<route autoStartup="false" id="com.acme.doStuffRoute">
<from uri="spring-ws:rootqname:{namepace}doStuff?endpointMapping=#com.acme.EndpointMapping"/>
<setHeader headerName="Exchange.HTTP_QUERY">
<simple>certainProperty=${ref:certainProperty}</simple>
</setHeader>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<policy ref="com.acme.Administrators">
<choice>
<when>
<simple>{{com.acme.ValidatorOn}} == true</simple>
<to uri="validator:MyWebService.xsd"/>
</when>
</choice>
<to pattern="InOut" uri="xslt:/xslt/do-stuff-request.xsl?transformerFactory=transformerFactory&uriResolver=uriResolver"/>
<to ref="com.acme.ToLogging"/>
<transform>
<method bean="msgTransform" method="encrypt"/>
</transform>
<to uri="ref:doMoreStuffEndpoint"/>
<transform>
<method bean="msgTransform" method="decrypt"/>
</transform>
<to ref="com.acme.FromLogging"/>
<to uri="xslt:/xslt/do-stuff-request.xsl?transformerFactory=transformerFactory&uriResolver=uriResolver"/>
<process ref="com.acme.MetricsProcessor"/>
</policy>
</route>
${leftValue} OP rightValue