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