How to Edit Default Mule Error message..?

痴心易碎 提交于 2019-12-07 23:27:19

问题


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.

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

Note : Actually i wanted to return a JSON String as an Error message. Something like :

{
  Exception: "Invalid URL"
}

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


回答1:


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>


来源:https://stackoverflow.com/questions/8154508/how-to-edit-default-mule-error-message

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!