Coverage Report - org.mule.transport.ajax.AjaxReplyToHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
AjaxReplyToHandler
0%
0/15
0%
0/6
0
 
 1  
 /*
 2  
  * $Id: AjaxReplyToHandler.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 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  
  * Handles the sending of sending result messages back to the client when the a replyTo 
 27  
  * channel is specified in the client request.
 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  
             //If we are using RPC make sure we still send something back to the client so that the subscription is cancelled
 54  0
             ret = returnMessage.getExceptionPayload().getMessage();
 55  
         }
 56  
         else
 57  
         {
 58  0
             returnMessage.applyTransformers(event, getTransformers());
 59  0
             ret = returnMessage.getPayload();
 60  
         }
 61  
         //Publish to interested clients
 62  0
         for (Client client : channel.getSubscribers())
 63  
         {
 64  0
             channel.publish(client, ret, null);
 65  
         }
 66  0
     }
 67  
 }