【问题标题】:How to Edit Default Mule Error message..?如何编辑默认 Mule 错误消息..?
【发布时间】:2011-11-17 14:30:15
【问题描述】:

我已将 Mule HTTP 入站端点定义为:

<flow name="jfeed_fill_data">
    <http:inbound-endpoint address="http://localhost:1212/jcore/insert/feed/">
    </http:inbound-endpoint>
<component class="main.java.com.joshlabs.jcore.Feed"/>
</flow>

现在这项服务运行良好。

但是当我输入变形 URL 时,例如 "http://localhost:1212/jcore/insert/feedasdasdAwes/",我收到以下消息骡子:

Cannot bind to address "http://localhost:1212/jcore/insert/feedasdasdAwes/"
No component registered on that endpoint

我的问题是:如何将上述默认消息更改为我自己的内容?

注意:实际上我想返回一个 JSON 字符串作为错误消息。类似的东西:

{
  Exception: "Invalid URL"
}

如果可能的话,那么“在上述情况下,MULE 会抛出 HTTP 404 : Not Found 错误”..??

【问题讨论】:

    标签: http mule inbound


    【解决方案1】:

    您只需要让您的端点接受所有子路径,然后使用消息路由处理错误的子路径:

    <flow name="jfeed_fill_data">
        <http:inbound-endpoint address="http://localhost:1212" />
        <choice>
            <when evaluator="header" expression="INBOUND:http.request.path=/jcore/insert/feed/">
                <component class="main.java.com.joshlabs.jcore.Feed"/>
            </when>
            <otherwise>
                <message-properties-transformer>
                    <add-message-property key="http.status" value="404"/>
                </message-properties-transformer>
                <expression-transformer>
                    <return-argument evaluator="string" expression="{Exception: &quot;Invalid URL&quot;}"/>
                </expression-transformer>
            </otherwise>
        </choice>
    </flow>
    

    【讨论】:

    • 哇..!!..它真的有效..!!..谢谢大卫..!! :) ...还有一件事,我在哪里可以找到一个好的文档来研究 MULE(mule-config)的这些概念。? ..实际上我在构建 mule-config 文件时总是有困难..!!
    • 我经常使用的参考是:mulesoft.org/documentation/display/MULE3USER
    猜你喜欢
    • 2019-10-24
    • 1970-01-01
    • 1970-01-01
    • 2016-03-04
    • 1970-01-01
    • 1970-01-01
    • 2017-03-09
    • 2018-12-01
    • 2019-03-20
    相关资源
    最近更新 更多