¿Cómo manejar las excepciones no comprobadas / en tiempo de ejecución en MULE?

Does anybody know how to handle Unchecked / Runtime Exceptions in MULE..??

I mean, in my java code, for a certain reason , i am "throwing an Exception" and i want Mule to detect it and route it to proper flow , where i can Log or Print that Exception.

So , What exactly should i place in my "flow" in Mule Config File to achieve that.

Mi código Java:

public Object xyz (Map payload) throws Exception {
    if (payload.isEmpty()) {
        throw new Exception ("New Exception") ;
    }
}

My Mule Config file :

<flow name="APIAuthenticate">

    <http:inbound-endpoint address="http://localhost:1212/jcore/authorize" transformer-refs="HttpParams" responseTransformer-refs="JavaObjectToJson" contentType="application/json" encoding="UTF-8">
        <not-filter>
            <wildcard-filter pattern="/favicon.ico"/>
        </not-filter>
    </http:inbound-endpoint>

    <component class="main.java.com.abc.XYZ"/>

</flow>

Any help will be deeply appreciated..!!

preguntado el 08 de noviembre de 11 a las 10:11

2 Respuestas

Configuring a default-exception-strategy in your flow should allow you to catch the exceptions (even runtime ones) and deal with them.

Lea el error handling reference guide para más información.

respondido 08 nov., 11:22

i know "default-exception-strategy" handles the error. But i always throw a 500 Server error at the client side (the one who hit that URL). I want to Show some neat Exception to the Client. in form of String or some HashMap. Now tell me , what should i do..?? - Ramandeep Singh

You're saying your default-exception-strategy handles the thrown exception but still a 500 is returned to the client? - David Dossot

Yes..I think what "default-exception-strategy" does is, it catches an Error and route it some other flow, where we can "log that error" or "output it to some file or console". But to the client , it always show "Server Error"..!! - Ramandeep Singh

OK, but if what if your exception handler returns another message, like an error one? - David Dossot

the flow will be broken , no log would be generated , but client would be shown the usual "Server Error" message. - Ramandeep Singh

Ok..i did some hit and trial and i figured out that

  • When the Exception is arrojado, an Exception Strategy is required like default-exception-strategy OR custom-exception-strategy is required, that would route the flow to some Class that would handle it and do required Actions.

  • But When we Regreso an Exception (like below), then we can use the exception-payload-filter or manera? attribute of Mule to handle it.

    public Object xyz (Map payload) throws Exception {
        if (payload.isEmpty()) {
            return new Exception ("New Exception") ;
        }
    }
    

Please Correct me if i am wrong..??

Also if there are other answers to this question, please be kind to put them..

respondido 09 nov., 11:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.