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.config.DefaultMuleConfiguration; |
19 | |
import org.mule.config.ExceptionHelper; |
20 | |
import org.mule.management.stats.FlowConstructStatistics; |
21 | |
import org.mule.management.stats.ServiceStatistics; |
22 | |
import org.mule.util.CollectionUtils; |
23 | |
|
24 | |
import java.util.List; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class DefaultServiceExceptionStrategy extends AbstractMessagingExceptionStrategy |
32 | |
{ |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public DefaultServiceExceptionStrategy() |
38 | |
{ |
39 | 0 | super(); |
40 | 0 | } |
41 | |
|
42 | |
public DefaultServiceExceptionStrategy(MuleContext muleContext) |
43 | |
{ |
44 | 0 | super(); |
45 | 0 | setMuleContext(muleContext); |
46 | 0 | } |
47 | |
|
48 | |
@Override |
49 | |
protected void defaultHandler(Throwable t) |
50 | |
{ |
51 | 0 | FlowConstructStatistics statistics = getFlowConstructStatistics(); |
52 | |
|
53 | 0 | if (statistics != null && statistics.isEnabled()) |
54 | |
{ |
55 | 0 | statistics.incExecutionError(); |
56 | |
} |
57 | |
|
58 | 0 | super.defaultHandler(DefaultMuleConfiguration.fullStackTraces ? t : ExceptionHelper.sanitize(t)); |
59 | 0 | } |
60 | |
|
61 | |
@Override |
62 | |
protected void logFatal(MuleMessage message, Throwable t) |
63 | |
{ |
64 | 0 | FlowConstructStatistics statistics = getFlowConstructStatistics(); |
65 | 0 | if (statistics != null && statistics.isEnabled()) |
66 | |
{ |
67 | 0 | statistics.incFatalError(); |
68 | |
} |
69 | |
|
70 | 0 | super.logFatal(message, t); |
71 | 0 | } |
72 | |
|
73 | |
@Override |
74 | |
protected void routeException(MuleMessage message, MessageProcessor target, Throwable t) |
75 | |
{ |
76 | 0 | super.routeException(message, target, t); |
77 | 0 | List<MessageProcessor> processors = getMessageProcessors(t); |
78 | 0 | if (CollectionUtils.isNotEmpty(processors) && getFlowConstructStatistics() instanceof ServiceStatistics) |
79 | |
{ |
80 | 0 | ServiceStatistics statistics = getServiceStatistics(); |
81 | 0 | if (statistics.isEnabled()) |
82 | |
{ |
83 | 0 | for (MessageProcessor endpoint : processors) |
84 | |
{ |
85 | 0 | statistics.getOutboundRouterStat().incrementRoutedMessage(endpoint); |
86 | |
} |
87 | |
} |
88 | |
} |
89 | 0 | } |
90 | |
|
91 | |
protected FlowConstructStatistics getFlowConstructStatistics() |
92 | |
{ |
93 | 0 | MuleEvent event = RequestContext.getEvent(); |
94 | 0 | if (event == null) |
95 | |
{ |
96 | |
|
97 | 0 | logger.fatal("The Default Service Exception Strategy has been invoked but there is no current event on the context"); |
98 | |
|
99 | 0 | return null; |
100 | |
} |
101 | 0 | else if(event.getFlowConstruct()!= null ) |
102 | |
{ |
103 | 0 | return event.getFlowConstruct().getStatistics(); |
104 | |
} |
105 | |
else |
106 | |
{ |
107 | |
|
108 | |
|
109 | 0 | return null; |
110 | |
} |
111 | |
} |
112 | |
|
113 | |
protected ServiceStatistics getServiceStatistics() |
114 | |
{ |
115 | 0 | FlowConstructStatistics stats = getFlowConstructStatistics(); |
116 | 0 | if (!(stats instanceof ServiceStatistics)) |
117 | |
{ |
118 | |
|
119 | 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"); |
120 | 0 | return null; |
121 | |
} |
122 | 0 | return (ServiceStatistics) stats; |
123 | |
} |
124 | |
} |