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