1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.providers.jbi; |
12 | |
|
13 | |
import org.mule.impl.MuleMessage; |
14 | |
import org.mule.providers.AbstractMessageDispatcher; |
15 | |
import org.mule.umo.UMOEvent; |
16 | |
import org.mule.umo.UMOMessage; |
17 | |
import org.mule.umo.endpoint.UMOImmutableEndpoint; |
18 | |
|
19 | |
import javax.jbi.messaging.ExchangeStatus; |
20 | |
import javax.jbi.messaging.Fault; |
21 | |
import javax.jbi.messaging.InOnly; |
22 | |
import javax.jbi.messaging.InOut; |
23 | |
import javax.jbi.messaging.MessageExchange; |
24 | |
import javax.jbi.messaging.MessagingException; |
25 | |
import javax.jbi.messaging.NormalizedMessage; |
26 | |
|
27 | |
public class JbiMessageDispatcher extends AbstractMessageDispatcher |
28 | |
{ |
29 | |
private JbiConnector connector; |
30 | |
|
31 | |
public JbiMessageDispatcher(UMOImmutableEndpoint endpoint) |
32 | |
{ |
33 | 0 | super(endpoint); |
34 | 0 | this.connector = (JbiConnector)endpoint.getConnector(); |
35 | 0 | } |
36 | |
|
37 | |
protected void doDispose() |
38 | |
{ |
39 | |
|
40 | 0 | } |
41 | |
|
42 | |
protected void doDispatch(UMOEvent event) throws Exception |
43 | |
{ |
44 | 0 | InOnly exchange = connector.getExchangeFactory().createInOnlyExchange(); |
45 | 0 | NormalizedMessage message = exchange.createMessage(); |
46 | 0 | exchange.setInMessage(message); |
47 | 0 | JbiUtils.populateNormalizedMessage(event.getMessage(), message); |
48 | 0 | done(exchange); |
49 | 0 | } |
50 | |
|
51 | |
protected UMOMessage doSend(UMOEvent event) throws Exception |
52 | |
{ |
53 | 0 | InOut exchange = connector.getExchangeFactory().createInOutExchange(); |
54 | 0 | NormalizedMessage message = exchange.createMessage(); |
55 | 0 | exchange.setInMessage(message); |
56 | 0 | JbiUtils.populateNormalizedMessage(event.getMessage(), message); |
57 | 0 | NormalizedMessage nm = exchange.getOutMessage(); |
58 | 0 | UMOMessage response = null; |
59 | 0 | if (nm != null) |
60 | |
{ |
61 | 0 | response = new MuleMessage(connector.getMessageAdapter(nm)); |
62 | |
} |
63 | 0 | done(exchange); |
64 | 0 | return response; |
65 | |
} |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
protected UMOMessage doReceive(long timeout) throws Exception |
80 | |
{ |
81 | 0 | throw new UnsupportedOperationException("doReceive"); |
82 | |
} |
83 | |
|
84 | |
protected void error(MessageExchange me, Fault fault) throws MessagingException |
85 | |
{ |
86 | 0 | me.setFault(fault); |
87 | 0 | me.setStatus(ExchangeStatus.ERROR); |
88 | 0 | connector.getDeliveryChannel().send(me); |
89 | 0 | } |
90 | |
|
91 | |
protected void done(MessageExchange me) throws MessagingException |
92 | |
{ |
93 | 0 | me.setStatus(ExchangeStatus.DONE); |
94 | 0 | connector.getDeliveryChannel().send(me); |
95 | 0 | } |
96 | |
|
97 | |
protected void doConnect() throws Exception |
98 | |
{ |
99 | |
|
100 | 0 | } |
101 | |
|
102 | |
protected void doDisconnect() throws Exception |
103 | |
{ |
104 | |
|
105 | 0 | } |
106 | |
|
107 | |
} |