1
2
3
4
5
6
7
8
9
10
11 package org.mule.impl;
12
13 import org.mule.impl.model.AbstractComponent;
14 import org.mule.management.stats.ComponentStatistics;
15 import org.mule.umo.UMOComponent;
16 import org.mule.umo.UMOEvent;
17 import org.mule.umo.UMOMessage;
18 import org.mule.umo.endpoint.UMOEndpoint;
19 import org.mule.umo.endpoint.UMOImmutableEndpoint;
20
21
22
23
24
25
26 public class DefaultComponentExceptionStrategy extends DefaultExceptionStrategy
27 {
28
29
30
31 protected UMOComponent component;
32
33 protected ComponentStatistics statistics;
34
35 public DefaultComponentExceptionStrategy()
36 {
37 super();
38 }
39
40
41
42
43
44
45
46 public DefaultComponentExceptionStrategy(UMOComponent component)
47 {
48 super();
49 setComponent(component);
50 }
51
52
53
54
55 public UMOComponent getComponent()
56 {
57 return component;
58 }
59
60 protected void defaultHandler(Throwable t)
61 {
62
63
64
65 if (component == null)
66 {
67 UMOEvent event = RequestContext.getEvent();
68 if (event == null)
69 {
70
71 logger.fatal("The Default Component Exception Strategy has been invoked but there is no current event on the context");
72 logger.fatal("The error is: " + t.getMessage(), t);
73 }
74 else
75 {
76 setComponent(event.getComponent());
77 }
78 }
79
80 if (statistics != null)
81 {
82 statistics.incExecutionError();
83 }
84
85 super.defaultHandler(t);
86 }
87
88 protected void logFatal(UMOMessage message, Throwable t)
89 {
90 super.logFatal(message, t);
91 if (statistics != null)
92 {
93 statistics.incFatalError();
94 }
95 }
96
97 protected void routeException(UMOMessage message, UMOImmutableEndpoint failedEndpoint, Throwable t)
98 {
99 UMOEndpoint ep = getEndpoint(t);
100 if (ep != null)
101 {
102 super.routeException(message, failedEndpoint, t);
103 if (statistics != null)
104 {
105 statistics.getOutboundRouterStat().incrementRoutedMessage(ep);
106 }
107 }
108 }
109
110 public void setComponent(UMOComponent component)
111 {
112 this.component = component;
113 if (component instanceof AbstractComponent)
114 {
115 if (statistics != null)
116 {
117 this.statistics = ((AbstractComponent) component).getStatistics();
118 }
119 }
120 }
121 }