1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.service.processor; |
12 | |
|
13 | |
import org.mule.DefaultMuleEvent; |
14 | |
import org.mule.DefaultMuleMessage; |
15 | |
import org.mule.api.MuleEvent; |
16 | |
import org.mule.api.MuleException; |
17 | |
import org.mule.api.routing.OutboundRouterCollection; |
18 | |
import org.mule.api.service.Service; |
19 | |
import org.mule.component.simple.PassThroughComponent; |
20 | |
import org.mule.processor.AbstractInterceptingMessageProcessor; |
21 | |
import org.mule.transport.NullPayload; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public class ServiceOutboundMessageProcessor extends AbstractInterceptingMessageProcessor |
33 | |
{ |
34 | |
|
35 | |
protected Service service; |
36 | |
|
37 | |
public ServiceOutboundMessageProcessor(Service service) |
38 | 0 | { |
39 | 0 | this.service = service; |
40 | 0 | } |
41 | |
|
42 | |
public MuleEvent process(MuleEvent event) throws MuleException |
43 | |
{ |
44 | |
|
45 | 0 | boolean syncNullPayload = event.getEndpoint().getExchangePattern().hasResponse() |
46 | |
&& (event.getMessage().getPayload() instanceof NullPayload); |
47 | |
|
48 | 0 | if (event.isStopFurtherProcessing()) |
49 | |
{ |
50 | 0 | logger.debug("MuleEvent stop further processing has been set, no outbound routing will be performed."); |
51 | 0 | return event; |
52 | |
} |
53 | |
|
54 | 0 | else if (event != null && !syncNullPayload) |
55 | |
{ |
56 | 0 | if (!(service.getOutboundMessageProcessor() instanceof OutboundRouterCollection) |
57 | |
|| (service.getOutboundMessageProcessor() instanceof OutboundRouterCollection && ((OutboundRouterCollection) service.getOutboundMessageProcessor()).hasEndpoints())) |
58 | |
{ |
59 | |
MuleEvent outboundEvent; |
60 | 0 | if (event.getEndpoint().getExchangePattern().hasResponse()) |
61 | |
{ |
62 | |
|
63 | 0 | outboundEvent = new DefaultMuleEvent(new DefaultMuleMessage(event.getMessage() |
64 | |
.getPayload(), event.getMessage(), event.getMuleContext()), event); |
65 | |
} |
66 | |
else |
67 | |
{ |
68 | 0 | outboundEvent = event; |
69 | |
} |
70 | |
|
71 | 0 | MuleEvent outboundResult = processNext(outboundEvent); |
72 | |
|
73 | 0 | if (outboundResult != null) |
74 | |
{ |
75 | 0 | event = outboundResult; |
76 | |
} |
77 | 0 | else if (service.getComponent() instanceof PassThroughComponent) |
78 | |
{ |
79 | |
|
80 | |
|
81 | |
|
82 | 0 | event = new DefaultMuleEvent(new DefaultMuleMessage(NullPayload.getInstance(), |
83 | |
event.getMessage(), service.getMuleContext()), event); |
84 | |
} |
85 | 0 | } |
86 | |
else |
87 | |
{ |
88 | 0 | logger.debug("Outbound router on service '" + service.getName() |
89 | |
+ "' doesn't have any targets configured."); |
90 | |
} |
91 | |
} |
92 | 0 | return event; |
93 | |
} |
94 | |
} |