Question

Does anybody know how to print full stack trace on the Browser, when a Runtime Exception occurs in MULE..??

When a runtime Exception occurs, MULE throws a 500 Server Error to the client , but shows no details to the client. It prints the whole stack trace in Console or Log Files (like the following) :

Root Exception stack trace:
java.sql.SQLException: Invalid column name
    at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3677)
    at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:2749)
    at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:494)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' 
    for everything)

Can i show the same stack Trace on the Browser (to the client)..??

And if possible , then also tell me how to switch ON or OFF printing of Stack Trace on Browser..??

(It may be possible that sometime in future , i dont want to show stack trace on browser)

Was it helpful?

Solution

Yes this is possible. I assume you are using a regular HTTP endpoint and this is a REST type service(?) If so, you can simply put a try/catch around the code causing the exception and return whatever text you want.

There are also exception strategies (http://www.mulesoft.org/documentation/display/MULE3USER/Error+Handling) for doing more sophisticated error handling, but it sounds like you are looking for the simple answer above.

If this doesn't answer your question, please provide more info about your mule config and the service that is raising the exception.

OTHER TIPS

There is nothing out of the box in Mule to do that. You have to implement an exception handler that will format the stacktrace in the Message exception payload and return it to the caller.

In your case, the HTTP transport has a particularity that can be found in the HttpMessageReceiver code:

try
{
    conn.writeResponse(processRequest(request));
}
catch (Exception e)
{
...
    conn.writeResponse(buildFailureResponse(request.getRequestLine().getHttpVersion(), httpStatus, e.getMessage()));

This means that when an exception crops-up to the top level, the creation of the failure message response is not customizable: you get this pretty technical message back and that is all.

I see two options to solve your problem:

  • sub-class HttpMessageReceiver and make the response message customizable in your version,
  • drop the HTTP transport in favor of the Jetty one (look at the bookstore example) and customize the response error messages at the web container level.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top