title: How to break/stop sequence if exception occurs in mediator using WSO2 ESB
body: <p>i am trying to implement logic that if during execution of sequence any error occurs, like e.g JMS endpoint is invalid, So sequence should drop here and log the message.</p>
  
  <p>The actual mediation is like below:</p>
  
  <p>Validate-->Clone-->Log   Clone mediation snapshot attached.<img src="https://i.stack.imgur.com/QxIya.png" alt="enter image description here"></p>
  
  <p>My Service Code is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;proxy xmlns="http://ws.apache.org/ns/synapse"
         name="AdapterService"
         transports="jms"
         statistics="disable"
         trace="disable"
         startOnLoad="true"&gt;
     &lt;target&gt;
        &lt;inSequence&gt;
           &lt;log level="full" separator="..... XML Received..."/&gt;
           &lt;validate source="//DOCUMENT03"&gt;
              &lt;schema key="conf:/DOCUMENT03_CUSTOM.xsd"/&gt;
              &lt;on-fail&gt;
                 &lt;makefault version="pox"&gt;
                    &lt;reason value="Invalid XML"/&gt;
                    &lt;detail&gt;Error while validating  XML at  Adapter Service.&lt;/detail&gt;
                 &lt;/makefault&gt;
                 &lt;log level="full" category="ERROR" separator="... XML Error..."/&gt;
                 &lt;drop/&gt;
              &lt;/on-fail&gt;
           &lt;/validate&gt;
           &lt;clone&gt;
              &lt;target&gt;
                 &lt;sequence&gt;
                    &lt;script language="js"&gt;mc.getEnvelope().getBody().getFirstElement().getFirstElement().getFirstElement().detach();&lt;/script&gt;
                    &lt;log level="full"/&gt;
                    &lt;property name="OUT_ONLY" value="true" scope="default" type="STRING"/&gt;
                    &lt;send&gt;
                       &lt;endpoint&gt;
                          &lt;address uri=**"jms:/BookingMessage?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;amp;java.naming.provider.url=tcp://1929.168.1.113:61616&amp;amp;transport.jms.DestinationType=queue"**
                                   format="pox"&gt;
                             &lt;timeout&gt;
                                &lt;duration&gt;10&lt;/duration&gt;
                                &lt;responseAction&gt;fault&lt;/responseAction&gt;
                             &lt;/timeout&gt;
                             &lt;suspendOnFailure&gt;
                                &lt;errorCodes&gt;101507,101505,101503&lt;/errorCodes&gt;
                                &lt;progressionFactor&gt;1.0&lt;/progressionFactor&gt;
                                &lt;maximumDuration&gt;10&lt;/maximumDuration&gt;
                             &lt;/suspendOnFailure&gt;
                             &lt;markForSuspension&gt;
                                &lt;errorCodes&gt;101508,101504&lt;/errorCodes&gt;
                                &lt;retriesBeforeSuspension&gt;5&lt;/retriesBeforeSuspension&gt;
                                &lt;retryDelay&gt;10&lt;/retryDelay&gt;
                             &lt;/markForSuspension&gt;
                          &lt;/address&gt;
                       &lt;/endpoint&gt;
                    &lt;/send&gt;
                    &lt;payloadFactory media-type="xml"&gt;
                       &lt;format&gt;
                          &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
                             &lt;soapenv:Body&gt;$1&lt;/soapenv:Body&gt;
                          &lt;/soapenv:Envelope&gt;
                       &lt;/format&gt;
                       &lt;args&gt;
                          &lt;arg xmlns:tns="http://com.sanomalearning/cdm/finance/generalledger/v1"
                               evaluator="xml"
                               expression="//DOCUMENT03/CMMHeader"/&gt;
                       &lt;/args&gt;
                    &lt;/payloadFactory&gt;
                    &lt;log level="full"/&gt;
                    &lt;property name="OUT_ONLY" value="true" scope="default" type="STRING"/&gt;
                    &lt;send&gt;
                       &lt;endpoint key="conf:/CMMHeaderQueueUrl"/&gt;
                    &lt;/send&gt;
                    &lt;log level="full" separator="Message Sent to Queue"/&gt;
                 &lt;/sequence&gt;
              &lt;/target&gt;
           &lt;/clone&gt;
        &lt;/inSequence&gt;
        &lt;outSequence&gt;
           &lt;send/&gt;
        &lt;/outSequence&gt;
        &lt;faultSequence&gt;
           &lt;log level="custom" separator=","&gt;
              &lt;property name="text" value="***FAult Handler***"/&gt;
           &lt;/log&gt;
           &lt;property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/&gt;
           &lt;drop/&gt;
           &lt;log level="custom"&gt;
              &lt;property name="text" value="An unexpected error occured"/&gt;
              &lt;property name="message" expression="get-property('ERROR_MESSAGE')"/&gt;
              &lt;property name="code" expression="get-property('ERROR_CODE')"/&gt;
              &lt;property name="detail" expression="get-property('ERROR_DETAIL')"/&gt;
              &lt;property name="exception" expression="get-property('ERROR_EXCEPTION')"/&gt;
           &lt;/log&gt;
           &lt;drop/&gt;
        &lt;/faultSequence&gt;
     &lt;/target&gt;
     &lt;parameter name="transport.jms.ContentType"&gt;
        &lt;rules&gt;
           &lt;jmsProperty&gt;contentType&lt;/jmsProperty&gt;
           &lt;default&gt;application/xml&lt;/default&gt;
        &lt;/rules&gt;
     &lt;/parameter&gt;
     &lt;parameter name="transport.jms.ConnectionFactory"&gt;myQueueConnectionFactory&lt;/parameter&gt;
     &lt;parameter name="transport.jms.DestinationType"&gt;queue&lt;/parameter&gt;
     &lt;parameter name="transport.jms.Destination"&gt;AdapterService.01.Request.Queue&lt;/parameter&gt;
     &lt;description/&gt;
  &lt;/proxy&gt;
  </code></pre>
  
  <p>Now when i execute this service after receiving request from queue, it is not sending message to invalid queue but sending message to second Url. Now i want if message is not sent to invalid endpoint then sequence should dropped. The invalid url is Bold.               </p>