1
2
3
4
5
6
7 package org.mule.test.integration.transaction;
8
9 import org.mule.api.transaction.Transaction;
10 import org.mule.transaction.TransactionCoordination;
11
12 import java.util.Map;
13
14 import org.apache.commons.logging.Log;
15 import org.apache.commons.logging.LogFactory;
16
17
18
19
20
21 public class XABridgeComponent
22 {
23 private static Log log = LogFactory.getLog(XABridgeComponent.class);
24
25 public static boolean mayRollback = false;
26
27
28
29
30
31
32
33 protected void mayRollback() throws Exception
34 {
35 if (mayRollback)
36 {
37 Transaction tx = TransactionCoordination.getInstance().getTransaction();
38 if (tx != null)
39 {
40 if (Math.random() < 0.3)
41 {
42 log.info("Marking transaction for rollback");
43 tx.setRollbackOnly();
44 }
45 }
46 }
47 }
48
49
50
51
52
53
54
55
56 public Object onJdbcMessage(Map msg) throws Exception
57 {
58 mayRollback();
59 return msg.get("data").toString();
60 }
61
62
63
64
65
66
67
68
69 public Object onJmsMessage(String msg) throws Exception
70 {
71 mayRollback();
72 return msg;
73 }
74
75 }