Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Grab Bits and Bytes From a Mule Exception Class

DZone's Guide to

How to Grab Bits and Bytes From a Mule Exception Class

Most of us usually use #[exception] to log errors in our mule flows. Let's see how we can get most out of the exception class in our mule flows.

· Integration Zone
Free Resource

Learn how API management supports better integration in Achieving Enterprise Agility with Microservices and API Management, brought to you in partnership with 3scale

Most of us usually use #[exception] to log errors in our mule flows. Let's see how can we get most out of the exception class in our mule flows.

Let's take a scenario where we get a connection timeout exception over an http rest call.

Image title

Take a closer look at what gets logged using the below MELs when used in the Logger component present a Catch Exception Strategy.

1. Exception- #[exception] 

Exception- org.mule.api.MessagingException: Error sending HTTP request. 

2. Exception Class- #[exception.getClass()]

Exception Class- class org.mule.api.MessagingException

3. Exception Cause- #[exception.getCause()]

Exception Cause- java.net.ConnectException: Connect timeout

4. Exception Info- #[exception.getInfo()]    

Exception Info- {Payload Type=java.lang.String, Element=/sampleFlow1/processors/1 @   sample:sample.xml:16 (HTTP), Payload=, Element XML=<http:request config-           ref="HTTP_Request_Configuration" path="/Ok" method="GET" doc:name="HTTP">     </http:request>}

5. Exception Message- #[exception.getMessage()]    

Exception Message- Error sending HTTP request.

6. Exception Detailed Message- #[exception.getDetailedMessage()]

Exception Detailed Message- 
********************************************************************************
Message : Error sending HTTP request.
Payload : 
Payload Type : java.lang.String
Element : /sampleFlow1/processors/1 @ sample:sample.xml:16 (HTTP)
Element XML : <http:request config-ref="HTTP_Request_Configuration" path="/Ok" method="GET" doc:name="HTTP"></http:request>
--------------------------------------------------------------------------------
Root Exception stack trace:
java.net.ConnectException: Connect timeout
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectCompletionHandler.cancelled(SingleEndpointPool.java:1284)
at org.glassfish.grizzly.impl.SafeFutureImpl.notifyCompletionHandlers(SafeFutureImpl.java:185)
at org.glassfish.grizzly.impl.SafeFutureImpl.done(SafeFutureImpl.java:277)
at org.glassfish.grizzly.impl.SafeFutureImpl$Sync.innerCancel(SafeFutureImpl.java:389)
at org.glassfish.grizzly.impl.SafeFutureImpl.cancel(SafeFutureImpl.java:247)
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectTimeoutWorker.doWork(SingleEndpointPool.java:1352)
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectTimeoutWorker.doWork(SingleEndpointPool.java:1344)
at org.glassfish.grizzly.utils.DelayedExecutor$DelayedRunnable.run(DelayedExecutor.java:158)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)

********************************************************************************

7. Exception Summary Message- #[exception.getSummaryMessage()]

Exception Summary Message- 
********************************************************************************
Message : Error sending HTTP request.
Element : /sampleFlow1/processors/1 @ sample:sample.xml:16 (HTTP)
--------------------------------------------------------------------------------
Exception stack is:
Error sending HTTP request. (org.mule.api.MessagingException)
org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectCompletionHandler.cancelled(SingleEndpointPool.java:1284)
org.glassfish.grizzly.impl.SafeFutureImpl.notifyCompletionHandlers(SafeFutureImpl.java:185)
org.glassfish.grizzly.impl.SafeFutureImpl.done(SafeFutureImpl.java:277)
org.glassfish.grizzly.impl.SafeFutureImpl$Sync.innerCancel(SafeFutureImpl.java:389)
org.glassfish.grizzly.impl.SafeFutureImpl.cancel(SafeFutureImpl.java:247)
org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectTimeoutWorker.doWork(SingleEndpointPool.java:1352)
org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectTimeoutWorker.doWork(SingleEndpointPool.java:1344)
org.glassfish.grizzly.utils.DelayedExecutor$DelayedRunnable.run(DelayedExecutor.java:158)
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
java.lang.Thread.run(Thread.java:745)

(set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

8. Exception Verbose Message- #[exception.getVerboseMessage()]

Exception Verbose Message- 
********************************************************************************
Message : Error sending HTTP request.
Payload : 
Payload Type : java.lang.String
Element : /sampleFlow1/processors/1 @ sample:sample.xml:16 (HTTP)
Element XML : <http:request config-ref="HTTP_Request_Configuration" path="/Ok" method="GET" doc:name="HTTP"></http:request>
--------------------------------------------------------------------------------
Root Exception stack trace:
java.net.ConnectException: Connect timeout
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectCompletionHandler.cancelled(SingleEndpointPool.java:1284)
at org.glassfish.grizzly.impl.SafeFutureImpl.notifyCompletionHandlers(SafeFutureImpl.java:185)
at org.glassfish.grizzly.impl.SafeFutureImpl.done(SafeFutureImpl.java:277)
at org.glassfish.grizzly.impl.SafeFutureImpl$Sync.innerCancel(SafeFutureImpl.java:389)
at org.glassfish.grizzly.impl.SafeFutureImpl.cancel(SafeFutureImpl.java:247)
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectTimeoutWorker.doWork(SingleEndpointPool.java:1352)
at org.glassfish.grizzly.connectionpool.SingleEndpointPool$ConnectTimeoutWorker.doWork(SingleEndpointPool.java:1344)
at org.glassfish.grizzly.utils.DelayedExecutor$DelayedRunnable.run(DelayedExecutor.java:158)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)

********************************************************************************

9. Exception Code- #[exception.getExceptionCode()]

Exception Code- -1

10. Exception Message Code- #[exception.getMessageCode()]

Exception Message Code- -1


11. Get Flow name that generated the Exception- 

#[exception.event.flowConstruct.name]    



You can actually try all of these in your MELs and get the most out of a mule exception class, so grab the best-suited one for your project. 

Thanks for reading! I hope this helps. Suggestions are welcomed in the comments.

Unleash the power of your APIs with future-proof API management - Create your account and start your free trial today, brought to you in partnership with 3scale.

Topics:
mule ,mule esb ,anypoint studio ,mulesoft

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}