Exception exceptions thrown by the service Screenshot to

Exception
Strategy

 

Objective:

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

Mule application must be
able to handle exceptional situations that can occur from time to time. This
document will cover how to manage and work with such exceptional situations.

 

Error
Handling and Recovery:

 

Choice Exception Strategy:

You can define a choice
exception strategy to customize the way Mule handles a message with an error
based on the message’s content at the moment it throws an exception. A choice
exception strategy catches all exceptions thrown within its parent flow,
examines message contents and exception type, then routes messages to the
appropriate exception strategy for processing.

Usually, you define more
than one exception strategy within a choice exception strategy. Each exception
strategy – either catch or rollback – uses a Mule expression to advise the
choice exception strategy which type of messages it accepts and processes.

 

Catch
Exception Strategy:

            You can define a
catch exception strategy to customize the way Mule handles messages with errors.
A catch exception strategy catches all exceptions thrown within its parent flow
and processes them, thereby overriding Mule’s implicit default exception
strategy.

 

Mule’s catch exception
strategy behavior is similar to a Java catch block, except that you cannot
throw a new exception or catch another exception within a catch exception
strategy.

 

Use
Cases:

            global-BKS-Choice_Exception_Strategy
contains with catch-exception-strategies.

 

Doc:name        Catch Exception Strategy
When               expression to indicate the
SoapFaultException, the catch exception strategy handles when it is
embedded within a Choice Exception Strategy.

            #exception.causedBy(org.mule.module.ws.consumer.SoapFaultException)”

Added
message processors as child elements of the catch-exception-strategy to
build a flow that processes messages that throw exceptions in the parent
flow. Refer to sample code below in which a set-property and
expression-component.

           

           

 

           

                        Global-scatter
catch exception strategy contains Expression to Create exception response
payload

Doc:Name       : Expression – Create exception
response payload
When               : Error in Web Services
Flow

                                     
And pattern matches with KS0076

Refer
to sample implementation

 

                       

 

Web
service call and catching exceptions thrown by the service

Screenshot
to consume the web service of type SOAP

           

 

 

 

 

 

 

 

 

 

Error
handling by using reference exception strategy  to catch exceptions thrown by web service

 


Sample
response after catching exception from the web service consume

 

WARN  2018-01-29 02:44:16,042
mule-domain-santander.HTTP_Listener_mule-domain-santander.worker.01
org.apache.cxf.phase.PhaseInterceptorChain: Interceptor for
{http://support.cxf.module.mule.org/}ProxyService#{http://support.cxf.module.mule.org/}invoke
has thrown exception, unwinding now

org.apache.cxf.interceptor.Fault:
Error sending HTTP request to
http://einstein2.sov.pre.corp/PRPRUS_ENS/ws/PROCOR_Def_Listener.

            at
org.mule.module.cxf.transport.MuleUniversalConduit$2.handleMessage(MuleUniversalConduit.java:201)
~mule-module-cxf-3.9.0.jar:3.9.0

      at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
~cxf-api-2.7.19-MULE-002.jar:2.7.19.MULE-002

            at
org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:572) ~cxf-api-2.7.19-MULE-002.jar:2.7.19.MULE-002
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:481)
~cxf-api-2.7.19-MULE-002.jar:2.7.19.MULE-002           at
org.mule.module.cxf.CxfOutboundMessageProcessor.doSendWithClient(CxfOutboundMessageProcessor.java:293)
~mule-module-cxf-3.9.0.jar:3.9.0     at
org.mule.module.cxf.CxfOutboundMessageProcessor.process(CxfOutboundMessageProcessor.java:131)
~mule-module-cxf-3.9.0.jar:3.9.0

 

 

Mule
config.xml: A mule-config.xml file will be used as the
root configuration file to be loaded. In a simple words mule-config.xml is
place where all the common configurations can be configured. In this use case
the error handling is done in mule-config.xml see the below screenshots and for
more information regarding the mule config.xml and how it works referring to
url:
https://forums.mulesoft.com/questions/4473/how_to_import_other_mule_config_files_within_mule_config_xml.html.

Figure a:

Figure b:

 

 

     

           

 

 

 

 

 

 

 

 

                        Global-scatter
catch exception strategy contains Expression to Create exception response
payload which is in the configured in the mule-config.xml

Doc:Name       : mule config – Create exception
response payload
When               : Error in Web Services
Flow

                                     
And pattern matches with KS0076

 

 

 The catch exception strategy caught the
exception and the retrieves the corresponding exception message and
returns the message see the screenshots.

 

6.      In
this corresponding use case the even though the status code is 200 the response
body returns is error flag with empty message.