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 super();
33 }
34
35 protected void defaultHandler(Throwable t)
36 {
37 ServiceStatistics statistics = getServiceStatistics();
38
39 if (statistics != null)
40 {
41 statistics.incExecutionError();
42 }
43
44 super.defaultHandler(t);
45 }
46
47 protected void logFatal(MuleMessage message, Throwable t)
48 {
49 super.logFatal(message, t);
50
51 ServiceStatistics statistics = getServiceStatistics();
52 if (statistics != null)
53 {
54 statistics.incFatalError();
55 }
56 }
57
58 protected void routeException(MuleMessage message, ImmutableEndpoint failedEndpoint, Throwable t)
59 {
60 super.routeException(message, failedEndpoint, t);
61 List endpoints = getEndpoints(t);
62 if (CollectionUtils.isNotEmpty(endpoints) && getServiceStatistics() != null)
63 {
64 ServiceStatistics statistics = getServiceStatistics();
65 for (int i = 0; i < endpoints.size(); i++)
66 {
67 statistics.getOutboundRouterStat().incrementRoutedMessage((ImmutableEndpoint) endpoints.get(i));
68 }
69 }
70 }
71
72 protected ServiceStatistics getServiceStatistics()
73 {
74 MuleEvent event = RequestContext.getEvent();
75 if (event == null)
76 {
77
78 logger.fatal("The Default Service Exception Strategy has been invoked but there is no current event on the context");
79
80 return null;
81 }
82 else if(event.getService()==null)
83 {
84
85 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 return null;
87 }
88 else
89 {
90 return ((AbstractService)event.getService()).getStatistics();
91 }
92 }
93 }