2

我已将 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/”,我从 MULE 收到以下消息:

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 Error”吗??

4

1 回答 1

2

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

<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>
于 2011-11-17T06:30:15.620 回答