1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.exception; |
12 | |
|
13 | |
import org.mule.RequestContext; |
14 | |
import org.mule.api.MuleContext; |
15 | |
import org.mule.api.MuleEvent; |
16 | |
import org.mule.api.MuleMessage; |
17 | |
import org.mule.api.processor.MessageProcessor; |
18 | |
import org.mule.api.service.Service; |
19 | |
import org.mule.management.stats.ServiceStatistics; |
20 | |
import org.mule.util.CollectionUtils; |
21 | |
|
22 | |
import java.util.List; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class DefaultServiceExceptionStrategy extends AbstractMessagingExceptionStrategy |
30 | |
{ |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public DefaultServiceExceptionStrategy() |
36 | |
{ |
37 | 0 | super(); |
38 | 0 | } |
39 | |
|
40 | |
public DefaultServiceExceptionStrategy(MuleContext muleContext) |
41 | |
{ |
42 | 0 | super(); |
43 | 0 | setMuleContext(muleContext); |
44 | 0 | } |
45 | |
|
46 | |
@Override |
47 | |
protected void defaultHandler(Throwable t) |
48 | |
{ |
49 | 0 | ServiceStatistics statistics = getServiceStatistics(); |
50 | |
|
51 | 0 | if (statistics != null) |
52 | |
{ |
53 | 0 | statistics.incExecutionError(); |
54 | |
} |
55 | |
|
56 | 0 | super.defaultHandler(t); |
57 | 0 | } |
58 | |
|
59 | |
@Override |
60 | |
protected void logFatal(MuleMessage message, Throwable t) |
61 | |
{ |
62 | 0 | ServiceStatistics statistics = getServiceStatistics(); |
63 | 0 | if (statistics != null) |
64 | |
{ |
65 | 0 | statistics.incFatalError(); |
66 | |
} |
67 | |
|
68 | 0 | super.logFatal(message, t); |
69 | 0 | } |
70 | |
|
71 | |
@Override |
72 | |
protected void routeException(MuleMessage message, MessageProcessor target, Throwable t) |
73 | |
{ |
74 | 0 | super.routeException(message, target, t); |
75 | 0 | List<MessageProcessor> processors = getMessageProcessors(t); |
76 | 0 | if (CollectionUtils.isNotEmpty(processors) && getServiceStatistics() != null) |
77 | |
{ |
78 | 0 | ServiceStatistics statistics = getServiceStatistics(); |
79 | 0 | for (MessageProcessor endpoint : processors) |
80 | |
{ |
81 | 0 | statistics.getOutboundRouterStat().incrementRoutedMessage(endpoint); |
82 | |
} |
83 | |
} |
84 | 0 | } |
85 | |
|
86 | |
protected ServiceStatistics getServiceStatistics() |
87 | |
{ |
88 | 0 | MuleEvent event = RequestContext.getEvent(); |
89 | 0 | if (event == null) |
90 | |
{ |
91 | |
|
92 | 0 | logger.fatal("The Default Service Exception Strategy has been invoked but there is no current event on the context"); |
93 | |
|
94 | 0 | return null; |
95 | |
} |
96 | 0 | else if(event.getFlowConstruct()!=null && event.getFlowConstruct() instanceof Service) |
97 | |
{ |
98 | 0 | return ((Service) event.getFlowConstruct()).getStatistics(); |
99 | |
} |
100 | |
else |
101 | |
{ |
102 | |
|
103 | 0 | logger.fatal("The Default Service Exception Strategy has been invoked but there is no current service on the context. Please report this to dev@mule.codehaus.org"); |
104 | 0 | return null; |
105 | |
} |
106 | |
} |
107 | |
} |