如何编辑默认骡子错误信息..? [英] How to Edit Default Mule Error message..?

查看:303
本文介绍了如何编辑默认骡子错误信息..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have defined a Mule HTTP Inbound Endpoint as :

<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>

现在这项服务工作正常。

Now this Service Works Fine.

但当我输入一个变形的URL,如 http:// localhost:1212 / jcore / insert / feedasdasdAwes / 时,我从MULE收到以下消息:

But When i type a Deformed URL , something like "http://localhost:1212/jcore/insert/feedasdasdAwes/", I get the following Message from MULE :

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

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

My Question is : How can i Change the above default Message to Something of my own.?

注意:实际上我想将JSON字符串作为错误消息返回。类似于:

{
  Exception: "Invalid URL"
}

如果可能,那么可以在上面抛出 HTTP 404:未找到错误case.. ??

And if possible, then "Can MULE throw HTTP 404 : Not Found Error in above case"..??

推荐答案

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

You just need to make your endpoint accept all sub-paths and then handle wrong ones with message routing:

<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>

这篇关于如何编辑默认骡子错误信息..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆