View Javadoc

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