Ramandeep Singh
Ramandeep Singh

Reputation: 5253

How to Edit Default Mule Error message..?

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

Upvotes: 2

Views: 1460

Answers (1)

David Dossot
David Dossot

Reputation: 33413

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>

Upvotes: 2

Related Questions