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