1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.service; |
12 | |
|
13 | |
import org.mule.DefaultExceptionStrategy; |
14 | |
import org.mule.RequestContext; |
15 | |
import org.mule.api.MuleEvent; |
16 | |
import org.mule.api.MuleMessage; |
17 | |
import org.mule.api.endpoint.ImmutableEndpoint; |
18 | |
import org.mule.management.stats.ServiceStatistics; |
19 | |
import org.mule.util.CollectionUtils; |
20 | |
|
21 | |
import java.util.List; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
public class DefaultServiceExceptionStrategy extends DefaultExceptionStrategy |
29 | |
{ |
30 | |
public DefaultServiceExceptionStrategy() |
31 | |
{ |
32 | 1552 | super(); |
33 | 1552 | } |
34 | |
|
35 | |
protected void defaultHandler(Throwable t) |
36 | |
{ |
37 | 0 | ServiceStatistics statistics = getServiceStatistics(); |
38 | |
|
39 | 0 | if (statistics != null) |
40 | |
{ |
41 | 0 | statistics.incExecutionError(); |
42 | |
} |
43 | |
|
44 | 0 | super.defaultHandler(t); |
45 | 0 | } |
46 | |
|
47 | |
protected void logFatal(MuleMessage message, Throwable t) |
48 | |
{ |
49 | 0 | super.logFatal(message, t); |
50 | |
|
51 | 0 | ServiceStatistics statistics = getServiceStatistics(); |
52 | 0 | if (statistics != null) |
53 | |
{ |
54 | 0 | statistics.incFatalError(); |
55 | |
} |
56 | 0 | } |
57 | |
|
58 | |
protected void routeException(MuleMessage message, ImmutableEndpoint failedEndpoint, Throwable t) |
59 | |
{ |
60 | 0 | super.routeException(message, failedEndpoint, t); |
61 | 0 | List endpoints = getEndpoints(t); |
62 | 0 | if (CollectionUtils.isNotEmpty(endpoints) && getServiceStatistics() != null) |
63 | |
{ |
64 | 0 | ServiceStatistics statistics = getServiceStatistics(); |
65 | 0 | for (int i = 0; i < endpoints.size(); i++) |
66 | |
{ |
67 | 0 | statistics.getOutboundRouterStat().incrementRoutedMessage((ImmutableEndpoint) endpoints.get(i)); |
68 | |
} |
69 | |
} |
70 | 0 | } |
71 | |
|
72 | |
protected ServiceStatistics getServiceStatistics() |
73 | |
{ |
74 | 0 | MuleEvent event = RequestContext.getEvent(); |
75 | 0 | if (event == null) |
76 | |
{ |
77 | |
|
78 | 0 | logger.fatal("The Default Service Exception Strategy has been invoked but there is no current event on the context"); |
79 | |
|
80 | 0 | return null; |
81 | |
} |
82 | 0 | else if(event.getService()==null) |
83 | |
{ |
84 | |
|
85 | 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"); |
86 | 0 | return null; |
87 | |
} |
88 | |
else |
89 | |
{ |
90 | 0 | return ((AbstractService)event.getService()).getStatistics(); |
91 | |
} |
92 | |
} |
93 | |
} |