1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.service.processor; |
8 | |
|
9 | |
import org.mule.api.MessagingException; |
10 | |
import org.mule.api.MuleEvent; |
11 | |
import org.mule.api.MuleException; |
12 | |
import org.mule.api.MuleMessage; |
13 | |
import org.mule.api.config.MuleProperties; |
14 | |
import org.mule.api.endpoint.ImmutableEndpoint; |
15 | |
import org.mule.api.processor.MessageProcessor; |
16 | |
import org.mule.api.service.Service; |
17 | |
import org.mule.api.transport.ReplyToHandler; |
18 | |
import org.mule.processor.AbstractInterceptingMessageProcessor; |
19 | |
import org.mule.transport.AbstractConnector; |
20 | |
|
21 | |
import java.util.concurrent.atomic.AtomicReference; |
22 | |
|
23 | |
import org.apache.commons.lang.BooleanUtils; |
24 | |
|
25 | |
public class ServiceInternalMessageProcessor extends AbstractInterceptingMessageProcessor |
26 | |
{ |
27 | |
|
28 | |
protected Service service; |
29 | |
|
30 | |
public ServiceInternalMessageProcessor(Service service) |
31 | 0 | { |
32 | 0 | this.service = service; |
33 | 0 | } |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public MuleEvent process(MuleEvent event) throws MuleException |
40 | |
{ |
41 | |
MuleEvent resultEvent; |
42 | |
try |
43 | |
{ |
44 | 0 | Object replyTo = event.getReplyToDestination(); |
45 | 0 | ReplyToHandler replyToHandler = event.getReplyToHandler(); |
46 | |
|
47 | 0 | resultEvent = service.getComponent().process(event); |
48 | 0 | resultEvent = processNext(resultEvent); |
49 | |
|
50 | |
|
51 | |
|
52 | 0 | if (resultEvent != null && replyTo != null) |
53 | |
{ |
54 | 0 | String replyToStop = resultEvent.getMessage().getInvocationProperty(MuleProperties.MULE_REPLY_TO_STOP_PROPERTY); |
55 | 0 | if (!event.getEndpoint().getExchangePattern().hasResponse() || !BooleanUtils.toBoolean(replyToStop)) |
56 | |
{ |
57 | 0 | processReplyTo(event, resultEvent, replyToHandler, replyTo); |
58 | |
} |
59 | |
} |
60 | 0 | return resultEvent; |
61 | |
} |
62 | 0 | catch (Exception e) |
63 | |
{ |
64 | 0 | event.getSession().setValid(false); |
65 | 0 | if (e instanceof MuleException) |
66 | |
{ |
67 | 0 | throw (MuleException) e; |
68 | |
} |
69 | |
else |
70 | |
{ |
71 | 0 | throw new MessagingException(event, e); |
72 | |
} |
73 | |
} |
74 | |
} |
75 | |
|
76 | |
protected void processReplyTo(MuleEvent event, |
77 | |
MuleEvent result, |
78 | |
ReplyToHandler replyToHandler, |
79 | |
Object replyTo) throws MuleException |
80 | |
{ |
81 | 0 | if (result != null && replyToHandler != null) |
82 | |
{ |
83 | 0 | String requestor = result.getMessage().getOutboundProperty(MuleProperties.MULE_REPLY_TO_REQUESTOR_PROPERTY); |
84 | 0 | if ((requestor != null && !requestor.equals(service.getName())) || requestor == null) |
85 | |
{ |
86 | 0 | replyToHandler.processReplyTo(event, result.getMessage(), replyTo); |
87 | |
} |
88 | |
} |
89 | 0 | } |
90 | |
|
91 | |
} |