1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.transport.ajax; |
11 | |
|
12 | |
import org.mule.api.MuleEvent; |
13 | |
import org.mule.api.MuleException; |
14 | |
import org.mule.api.MuleMessage; |
15 | |
import org.mule.api.transformer.Transformer; |
16 | |
import org.mule.api.transport.Connector; |
17 | |
import org.mule.transport.DefaultReplyToHandler; |
18 | |
|
19 | |
import java.util.List; |
20 | |
|
21 | |
import org.cometd.Channel; |
22 | |
import org.cometd.Client; |
23 | |
import org.mortbay.cometd.AbstractBayeux; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class AjaxReplyToHandler extends DefaultReplyToHandler |
30 | |
{ |
31 | |
private Connector connector; |
32 | |
|
33 | |
public AjaxReplyToHandler(List<Transformer> transformers, Connector connector) |
34 | |
{ |
35 | 0 | super(transformers, connector.getMuleContext()); |
36 | 0 | this.connector = connector; |
37 | 0 | } |
38 | |
|
39 | |
@Override |
40 | |
public void processReplyTo(MuleEvent event, MuleMessage returnMessage, Object replyTo) throws MuleException |
41 | |
{ |
42 | 0 | AbstractBayeux bayeux = ((BayeuxAware)connector).getBayeux(); |
43 | 0 | Channel channel = bayeux.getChannel(replyTo.toString(), false); |
44 | 0 | if(channel==null) |
45 | |
{ |
46 | 0 | logger.warn("No ajax Channel: " + replyTo + ". Maybe the client unregistered interest."); |
47 | 0 | return; |
48 | |
} |
49 | |
|
50 | |
Object ret; |
51 | 0 | if(returnMessage.getExceptionPayload()!=null) |
52 | |
{ |
53 | |
|
54 | 0 | ret = returnMessage.getExceptionPayload().getMessage(); |
55 | |
} |
56 | |
else |
57 | |
{ |
58 | 0 | returnMessage.applyTransformers(event, getTransformers()); |
59 | 0 | ret = returnMessage.getPayload(); |
60 | |
} |
61 | |
|
62 | 0 | for (Client client : channel.getSubscribers()) |
63 | |
{ |
64 | 0 | channel.publish(client, ret, null); |
65 | |
} |
66 | 0 | } |
67 | |
} |