1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
package org.mule.routing; |
16 | |
|
17 | |
import org.mule.DefaultMuleEvent; |
18 | |
import org.mule.api.MessagingException; |
19 | |
import org.mule.api.MuleEvent; |
20 | |
import org.mule.api.MuleException; |
21 | |
import org.mule.api.MuleMessage; |
22 | |
import org.mule.api.endpoint.OutboundEndpoint; |
23 | |
import org.mule.api.processor.MessageProcessor; |
24 | |
import org.mule.api.routing.CouldNotRouteOutboundMessageException; |
25 | |
import org.mule.routing.outbound.AbstractOutboundRouter; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | public class FirstSuccessful extends AbstractOutboundRouter implements MessageProcessor |
34 | |
{ |
35 | |
|
36 | |
|
37 | |
|
38 | |
@Override |
39 | |
public MuleEvent route(MuleEvent event) throws MessagingException |
40 | |
{ |
41 | 0 | MuleEvent retval = null; |
42 | |
|
43 | 0 | boolean failed = true; |
44 | 0 | for (MessageProcessor mp : routes) |
45 | |
{ |
46 | |
try |
47 | |
{ |
48 | 0 | MuleEvent toProcess = event; |
49 | 0 | if (mp instanceof OutboundEndpoint) |
50 | |
{ |
51 | 0 | toProcess = new DefaultMuleEvent(event.getMessage(), (OutboundEndpoint)mp, event.getSession()); |
52 | |
} |
53 | 0 | retval = mp.process(toProcess); |
54 | 0 | if (retval == null) |
55 | |
{ |
56 | 0 | failed = false; |
57 | |
} |
58 | |
else |
59 | |
{ |
60 | 0 | MuleMessage msg = retval.getMessage(); |
61 | 0 | failed = msg != null && msg.getExceptionPayload() != null; |
62 | |
} |
63 | |
} |
64 | 0 | catch (Exception ex) |
65 | |
{ |
66 | 0 | failed = true; |
67 | 0 | } |
68 | 0 | if (!failed) |
69 | 0 | break; |
70 | |
} |
71 | |
|
72 | 0 | if (failed) |
73 | |
{ |
74 | 0 | throw new CouldNotRouteOutboundMessageException(event, this); |
75 | |
} |
76 | |
|
77 | 0 | return retval; |
78 | |
} |
79 | |
|
80 | |
public boolean isMatch(MuleMessage message) throws MuleException |
81 | |
{ |
82 | 0 | return true; |
83 | |
} |
84 | |
} |