首页 > 解决方案 > Java骆驼路线永远不会达到否则声明

问题描述

我正在创建一个基于文件名将文件传输到新位置的服务。问题是即使第一个 when 为假(文件名不以“START”开头),也永远不会到达第二个 else 语句。此外, from uri 有 delete=true 选项,也许这会影响某些事情。结果是该文件刚刚被删除。

        <route id="outgoing" errorHandlerRef="outgoingDeadLetterErrorHandler">
            <from uri="OutgoingSource"/>

            <choice>
                <when>
                    <simple>${file:name} starts with 'START'</simple>

                    <convertBodyTo type="java.lang.String"/>
                    <choice>
                        <when>
                            <xpath>/File/Header/@x = 'X'</xpath>
                            <to ref="OutgoingErrorDestination"/>
                        </when>
                        <when>
                            <xpath>/Header/@y = 'Y'</xpath>
                            <to ref="OutgoingDestination"/>
                        </when>
                        <otherwise>
                            <to ref="OutgoingErrorDestination"/>
                        </otherwise>
                    </choice>
                </when>
                <otherwise>
                    <to ref="OutgoingErrorDestination"/>
                </otherwise>
            </choice>
        </route>

标签: javaapache-camel

解决方案


file:name 相对于起始目录(即 file:name = test\hello.txt)

如果您只想测试文件名,您应该使用 file:onlyname.noext

<simple>${file:onlyname.noext} starts with 'START'</simple>

推荐阅读