1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.routing; |
12 | |
|
13 | |
import org.mule.DefaultMuleEvent; |
14 | |
import org.mule.api.MuleEvent; |
15 | |
import org.mule.api.MuleMessage; |
16 | |
import org.mule.api.MuleSession; |
17 | |
import org.mule.api.endpoint.OutboundEndpoint; |
18 | |
import org.mule.api.routing.RoutingException; |
19 | |
import org.mule.api.routing.ServiceRoutingException; |
20 | |
import org.mule.config.i18n.CoreMessages; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | 6 | public class ForwardingCatchAllStrategy extends AbstractCatchAllStrategy |
30 | |
{ |
31 | 6 | private boolean sendTransformed = false; |
32 | |
|
33 | |
public MuleMessage catchMessage(MuleMessage message, MuleSession session, boolean synchronous) |
34 | |
throws RoutingException |
35 | |
{ |
36 | 6 | if (getEndpoint() == null) |
37 | |
{ |
38 | 2 | throw new ServiceRoutingException(CoreMessages.noCatchAllEndpointSet(), message, |
39 | |
getEndpoint(), session.getService()); |
40 | |
} |
41 | |
try |
42 | |
{ |
43 | 4 | OutboundEndpoint endpoint = getEndpoint(); |
44 | 4 | if (sendTransformed && endpoint.getTransformers() != null) |
45 | |
{ |
46 | 2 | message.applyTransformers(endpoint.getTransformers()); |
47 | |
} |
48 | |
|
49 | 4 | MuleEvent newEvent = new DefaultMuleEvent(message, endpoint, session, synchronous); |
50 | |
|
51 | 4 | if (synchronous) |
52 | |
{ |
53 | 2 | MuleMessage result = endpoint.send(newEvent); |
54 | 2 | if (statistics != null) |
55 | |
{ |
56 | 0 | statistics.incrementRoutedMessage(getEndpoint()); |
57 | |
} |
58 | 2 | return result; |
59 | |
} |
60 | |
else |
61 | |
{ |
62 | 2 | endpoint.dispatch(newEvent); |
63 | 2 | if (statistics != null) |
64 | |
{ |
65 | 0 | statistics.incrementRoutedMessage(getEndpoint()); |
66 | |
} |
67 | 2 | return null; |
68 | |
} |
69 | |
} |
70 | 0 | catch (Exception e) |
71 | |
{ |
72 | 0 | throw new RoutingException(message, getEndpoint(), e); |
73 | |
|
74 | |
} |
75 | |
} |
76 | |
|
77 | |
public boolean isSendTransformed() |
78 | |
{ |
79 | 0 | return sendTransformed; |
80 | |
} |
81 | |
|
82 | |
public void setSendTransformed(boolean sendTransformed) |
83 | |
{ |
84 | 2 | this.sendTransformed = sendTransformed; |
85 | 2 | } |
86 | |
} |