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.exception.SystemExceptionHandler; |
16 | |
import org.mule.api.transport.Connectable; |
17 | |
import org.mule.context.notification.ExceptionNotification; |
18 | |
import org.mule.message.DefaultExceptionPayload; |
19 | |
import org.mule.transport.ConnectException; |
20 | |
|
21 | |
import java.lang.reflect.InvocationTargetException; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
public class DefaultSystemExceptionStrategy extends AbstractExceptionListener implements SystemExceptionHandler |
27 | |
{ |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public DefaultSystemExceptionStrategy() |
33 | |
{ |
34 | 0 | super(); |
35 | 0 | } |
36 | |
|
37 | |
public DefaultSystemExceptionStrategy(MuleContext muleContext) |
38 | |
{ |
39 | 0 | super(); |
40 | 0 | setMuleContext(muleContext); |
41 | 0 | } |
42 | |
|
43 | |
public void handleException(Exception e) |
44 | |
{ |
45 | 0 | Connectable connectable = null; |
46 | |
|
47 | |
|
48 | 0 | if (e instanceof InvocationTargetException) |
49 | |
{ |
50 | 0 | Throwable t = e.getCause(); |
51 | |
|
52 | 0 | e = t instanceof Exception ? (Exception) t : new Exception(t); |
53 | |
} |
54 | |
|
55 | 0 | if (enableNotifications) |
56 | |
{ |
57 | 0 | fireNotification(new ExceptionNotification(e)); |
58 | |
} |
59 | |
|
60 | 0 | if (e instanceof ConnectException) |
61 | |
{ |
62 | 0 | logger.info("Exception caught is a ConnectException, attempting to reconnect..."); |
63 | 0 | connectable = ((ConnectException) e).getFailed(); |
64 | |
try |
65 | |
{ |
66 | 0 | logger.debug("Disconnecting " + connectable.getClass().getName()); |
67 | 0 | connectable.disconnect(); |
68 | |
} |
69 | 0 | catch (Exception e1) |
70 | |
{ |
71 | 0 | logger.error(e1.getMessage()); |
72 | 0 | } |
73 | |
} |
74 | |
|
75 | 0 | logException(e); |
76 | |
|
77 | 0 | handleTransaction(e); |
78 | |
|
79 | 0 | if (RequestContext.getEvent() != null) |
80 | |
{ |
81 | 0 | RequestContext.setExceptionPayload(new DefaultExceptionPayload(e)); |
82 | |
} |
83 | |
|
84 | 0 | if (connectable != null) |
85 | |
{ |
86 | |
|
87 | |
try |
88 | |
{ |
89 | 0 | logger.debug("Reconnecting " + connectable.getClass().getName()); |
90 | 0 | connectable.connect(); |
91 | |
} |
92 | 0 | catch (Exception e2) |
93 | |
{ |
94 | 0 | logger.error(e2.getMessage()); |
95 | 0 | } |
96 | |
} |
97 | 0 | } |
98 | |
} |