View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.endpoint.outbound;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.MuleException;
11  import org.mule.api.transaction.Transaction;
12  import org.mule.api.transaction.TransactionException;
13  import org.mule.processor.AbstractInterceptingMessageProcessor;
14  import org.mule.transaction.TransactionCoordination;
15  
16  /**
17   * MessageProcessor implementation that stops outbound flow is the current
18   * transaction has been rolled back.
19   */
20  public class OutboundTxRollbackMessageProcessor extends AbstractInterceptingMessageProcessor
21  {
22      public MuleEvent process(MuleEvent event) throws MuleException
23      {
24          // No point continuing if the service has rolledback the transaction
25          if (isTransactionRollback())
26          {
27              return event;
28          }
29          else
30          {
31              return processNext(event);
32          }
33      }
34  
35      /**
36       * Checks to see if the current transaction has been rolled back
37       */
38      protected boolean isTransactionRollback()
39      {
40          try
41          {
42              Transaction tx = TransactionCoordination.getInstance().getTransaction();
43              if (tx != null && tx.isRollbackOnly())
44              {
45                  return true;
46              }
47          }
48          catch (TransactionException e)
49          {
50              // TODO MULE-863: What should we really do?
51              logger.warn(e.getMessage());
52          }
53          return false;
54      }
55  }