2

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

Ramandeep Singh
  • 5,063
  • 3
  • 28
  • 34

1 Answers1

2

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>
David Dossot
  • 33,403
  • 4
  • 38
  • 72
  • WOW..!!..It really Worked..!!..Thanx David..!! :) ...N one more thing , Where would i find a good documentation to study such concepts for MULE (mule-config).? ..Actually i always have difficulty in building mule-config file..!! – Ramandeep Singh Nov 17 '11 at 06:41
  • The reference I'm constantly using is: http://www.mulesoft.org/documentation/display/MULE3USER – David Dossot Nov 17 '11 at 15:55