Apache Camel的默认路由

问题描述 投票:0回答:2

我正在使用Apache Camel。使用XML DSL,我的意思是类似

<rests id="rests" xmlns="http://camel.apache.org/schema/spring">
    <rest id="rest-custom">
        <get uri="my_method" method="">
            <description>...</description>
            <param name="..." ... />
            <route>
                <process ref="..." />
                <to uri="..." />
            </route>
        </get>

        <post uri="another_method" method="" >
            <description>...</description>
            <param name="..." .../>
            <route>
                <process ref="..." />
                <to uri="..." />
            </route>
        </post>
...

因此,如果我想要新的路线,我只需添加新的<get><post>,它就可以正常工作。

但是现在我想添加一些DEFAULT方法。我的意思是,类似所有配置底部的<get uri="*"><post uri="*">。因此,如果我的网址与列表中的任何网址都不匹配-它将变为默认网址,并且我可以使用自定义处理器进行处理(这是我想要的行为)。

目前我不知道该怎么做。试图处理404响应,但仍然没有成功。看起来解决方案应该很简单,但是还找不到。

java apache-camel dsl
2个回答
0
投票
我看到这样的默认设置只有一种可能的用例:如果您得到了

具有相同功能的多个URL。

如果是这种情况,并且您的客户不希望或无法切换到单个URL,则在传入请求到达您的Camel应用程序之前,您仍可以对传入请求使用

URL重写

如果您想

“捕获”所有未知URL

(错误),我猜您应该使用标准骆驼错误处理(请参阅Error HandlerException clause),因为这些REST DSL块在内部转换为标准的骆驼路线。

0
投票
终于找到了解决方法。

<get uri="/?matchOnUriPrefix=true&amp;bridgeEndpoint=true" method=""> <description>Default GET method</description> <route> ... </route> </get>

参数

matchOnUriPrefix = true&bridgeEndpoint = true达到了目的。

© www.soinside.com 2019 - 2024. All rights reserved.