1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.processor; |
12 | |
|
13 | |
import org.mule.api.MessagingException; |
14 | |
import org.mule.api.MuleEvent; |
15 | |
import org.mule.api.MuleException; |
16 | |
import org.mule.api.processor.MessageProcessor; |
17 | |
import org.mule.api.transaction.TransactionCallback; |
18 | |
import org.mule.api.transaction.TransactionConfig; |
19 | |
import org.mule.config.i18n.CoreMessages; |
20 | |
import org.mule.transaction.TransactionTemplate; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class TransactionalInterceptingMessageProcessor extends AbstractInterceptingMessageProcessor |
28 | |
{ |
29 | |
protected TransactionConfig transactionConfig; |
30 | |
|
31 | |
public TransactionalInterceptingMessageProcessor(TransactionConfig transactionConfig) |
32 | 0 | { |
33 | 0 | this.transactionConfig = transactionConfig; |
34 | 0 | } |
35 | |
|
36 | |
public MuleEvent process(final MuleEvent event) throws MuleException |
37 | |
{ |
38 | 0 | if (next == null) |
39 | |
{ |
40 | 0 | return event; |
41 | |
} |
42 | |
else |
43 | |
{ |
44 | 0 | TransactionTemplate<MuleEvent> tt = new TransactionTemplate<MuleEvent>(transactionConfig, event.getMuleContext()); |
45 | 0 | TransactionCallback<MuleEvent> cb = new TransactionCallback<MuleEvent>() |
46 | 0 | { |
47 | |
public MuleEvent doInTransaction() throws Exception |
48 | |
{ |
49 | 0 | return next.process(event); |
50 | |
} |
51 | |
}; |
52 | |
|
53 | |
try |
54 | |
{ |
55 | 0 | return tt.execute(cb); |
56 | |
} |
57 | 0 | catch (MessagingException e) |
58 | |
{ |
59 | 0 | throw e; |
60 | |
} |
61 | 0 | catch (Exception e) |
62 | |
{ |
63 | 0 | throw new MessagingException(CoreMessages.errorInvokingMessageProcessorWithinTransaction( |
64 | |
next, transactionConfig), event, e); |
65 | |
} |
66 | |
} |
67 | |
} |
68 | |
} |