@Override
public void processReplyTo(MuleEvent event, MuleMessage returnMessage, Object replyTo) throws MuleException
{
AbstractBayeux bayeux = ((BayeuxAware)connector).getBayeux();
Channel channel = bayeux.getChannel(replyTo.toString(), false);
if(channel==null)
{
logger.warn("No ajax Channel: " + replyTo + ". Maybe the client unregistered interest.");
return;
}
Object ret;
if(returnMessage.getExceptionPayload()!=null)
{
//If we are using RPC make sure we still send something back to the client so that the subscription is cancelled
ret = returnMessage.getExceptionPayload().getMessage();
}
else
{
EndpointBuilder endpointBuilder = new EndpointURIEndpointBuilder(event.getMessageSourceURI().toString(), muleContext);
endpointBuilder.setConnector(connector);
OutboundEndpoint tempEndpoint = muleContext.getEndpointFactory().getOutboundEndpoint(endpointBuilder);
List<Transformer> defaultTransportTransformers = ((org.mule.transport.AbstractConnector) connector).getDefaultOutboundTransformers(tempEndpoint);
returnMessage.applyTransformers(event, defaultTransportTransformers);
ret = returnMessage.getPayload();
}
//Publish to interested clients
for (Client client : channel.getSubscribers())
{
channel.publish(client, ret, null);
}
}