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