1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.routing.inbound; |
12 | |
|
13 | |
import org.mule.MuleManager; |
14 | |
import org.mule.impl.MuleEvent; |
15 | |
import org.mule.impl.MuleMessage; |
16 | |
import org.mule.impl.model.seda.SedaComponent; |
17 | |
import org.mule.umo.MessagingException; |
18 | |
import org.mule.umo.UMOComponent; |
19 | |
import org.mule.umo.UMOEvent; |
20 | |
import org.mule.umo.UMOException; |
21 | |
import org.mule.umo.UMOMessage; |
22 | |
import org.mule.umo.routing.RoutingException; |
23 | |
import org.mule.umo.routing.UMOInboundRouterCollection; |
24 | |
import org.mule.umo.routing.UMOOutboundRouterCollection; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | 0 | public class ForwardingConsumer extends SelectiveConsumer |
32 | |
{ |
33 | |
|
34 | |
public UMOEvent[] process(UMOEvent event) throws MessagingException |
35 | |
{ |
36 | 0 | if (super.process(event) != null) |
37 | |
{ |
38 | 0 | UMOOutboundRouterCollection router = event.getComponent().getDescriptor().getOutboundRouter(); |
39 | |
|
40 | |
|
41 | |
|
42 | 0 | event.setStopFurtherProcessing(true); |
43 | |
|
44 | 0 | UMOComponent component = event.getComponent(); |
45 | |
|
46 | |
|
47 | 0 | if (component != null && component instanceof SedaComponent && |
48 | |
((MuleManager) MuleManager.getInstance()).getStatistics() != null && |
49 | |
((MuleManager) MuleManager.getInstance()).getStatistics().isEnabled()) |
50 | |
{ |
51 | 0 | if (((SedaComponent) component).getStatistics().isEnabled()) |
52 | |
{ |
53 | 0 | if (event.isSynchronous()) |
54 | |
{ |
55 | 0 | ((SedaComponent) component).getStatistics().incReceivedEventSync(); |
56 | 0 | ((SedaComponent) component).getStatistics().incSentEventSync(); |
57 | |
} |
58 | |
else |
59 | |
{ |
60 | 0 | ((SedaComponent) component).getStatistics().incReceivedEventASync(); |
61 | 0 | ((SedaComponent) component).getStatistics().incSentEventASync(); |
62 | |
} |
63 | 0 | UMOInboundRouterCollection inboundRouter = event.getComponent().getDescriptor().getInboundRouter(); |
64 | 0 | if (inboundRouter != null && inboundRouter.getStatistics() != null && inboundRouter.getStatistics().isEnabled()) |
65 | |
{ |
66 | 0 | inboundRouter.getStatistics().incrementRoutedMessage(event.getEndpoint()); |
67 | |
} |
68 | |
|
69 | |
} |
70 | |
} |
71 | |
|
72 | |
|
73 | 0 | if (router == null) |
74 | |
{ |
75 | 0 | logger.debug("Descriptor has no outbound router configured to forward to, continuing with normal processing"); |
76 | 0 | return new UMOEvent[]{event}; |
77 | |
} |
78 | |
else |
79 | |
{ |
80 | |
try |
81 | |
{ |
82 | 0 | UMOMessage message = new MuleMessage(event.getTransformedMessage(), event.getMessage()); |
83 | |
|
84 | 0 | UMOMessage response = router.route(message, event.getSession(), event.isSynchronous()); |
85 | |
|
86 | |
|
87 | 0 | if (response != null) |
88 | |
{ |
89 | 0 | return new UMOEvent[]{new MuleEvent(response, event)}; |
90 | |
} |
91 | |
else |
92 | |
{ |
93 | 0 | return null; |
94 | |
} |
95 | |
|
96 | |
} |
97 | 0 | catch (UMOException e) |
98 | |
{ |
99 | 0 | throw new RoutingException(event.getMessage(), event.getEndpoint(), e); |
100 | |
} |
101 | |
} |
102 | |
} |
103 | 0 | return null; |
104 | |
} |
105 | |
} |