Coverage Report - org.mule.transport.DefaultReplyToHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultReplyToHandler
0%
0/31
0%
0/8
2.2
 
 1  
 /*
 2  
  * $Id: DefaultReplyToHandler.java 11488 2008-03-24 14:38:49Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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  
 
 11  
 package org.mule.transport;
 12  
 
 13  
 import org.mule.DefaultMuleEvent;
 14  
 import org.mule.RegistryContext;
 15  
 import org.mule.api.MuleEvent;
 16  
 import org.mule.api.MuleException;
 17  
 import org.mule.api.MuleMessage;
 18  
 import org.mule.api.config.MuleProperties;
 19  
 import org.mule.api.endpoint.EndpointBuilder;
 20  
 import org.mule.api.endpoint.EndpointFactory;
 21  
 import org.mule.api.endpoint.OutboundEndpoint;
 22  
 import org.mule.api.transport.DispatchException;
 23  
 import org.mule.api.transport.ReplyToHandler;
 24  
 import org.mule.config.i18n.CoreMessages;
 25  
 import org.mule.service.AbstractService;
 26  
 
 27  
 import java.util.HashMap;
 28  
 import java.util.List;
 29  
 import java.util.Map;
 30  
 
 31  
 import org.apache.commons.logging.Log;
 32  
 import org.apache.commons.logging.LogFactory;
 33  
 
 34  
 /**
 35  
  * <code>DefaultReplyToHandler</code> is responsible for processing a message
 36  
  * replyTo header.
 37  
  */
 38  
 
 39  
 public class DefaultReplyToHandler implements ReplyToHandler
 40  
 {
 41  
     /**
 42  
      * logger used by this class
 43  
      */
 44  0
     protected static final Log logger = LogFactory.getLog(DefaultReplyToHandler.class);
 45  
 
 46  
     private volatile List transformers;
 47  0
     private final Map endpointCache = new HashMap();
 48  
 
 49  
     public DefaultReplyToHandler(List transformers)
 50  0
     {
 51  0
         this.transformers = transformers;
 52  0
     }
 53  
 
 54  
     public void processReplyTo(MuleEvent event, MuleMessage returnMessage, Object replyTo) throws MuleException
 55  
     {
 56  0
         if (logger.isDebugEnabled())
 57  
         {
 58  0
             logger.debug("sending reply to: " + returnMessage.getReplyTo());
 59  
         }
 60  
 
 61  0
         String replyToEndpoint = replyTo.toString();
 62  
 
 63  
         // get the endpoint for this url
 64  0
         OutboundEndpoint endpoint = getEndpoint(event, replyToEndpoint);
 65  
 
 66  
         // make sure remove the replyTo property as not cause a a forever
 67  
         // replyto loop
 68  0
         returnMessage.removeProperty(MuleProperties.MULE_REPLY_TO_PROPERTY);
 69  
 
 70  
         // Create the replyTo event asynchronous
 71  0
         MuleEvent replyToEvent = new DefaultMuleEvent(returnMessage, endpoint, event.getSession(), false);
 72  
 
 73  
         // dispatch the event
 74  
         try
 75  
         {
 76  0
             endpoint.dispatch(replyToEvent);
 77  0
             if (logger.isInfoEnabled())
 78  
             {
 79  0
                 logger.info("reply to sent: " + endpoint);
 80  
             }
 81  0
             ((AbstractService) event.getService()).getStatistics().incSentReplyToEvent();
 82  
         }
 83  0
         catch (Exception e)
 84  
         {
 85  0
             throw new DispatchException(
 86  
                 CoreMessages.failedToDispatchToReplyto(endpoint),
 87  
                 replyToEvent.getMessage(), replyToEvent.getEndpoint(), e);
 88  0
         }
 89  
 
 90  0
     }
 91  
 
 92  
     protected synchronized OutboundEndpoint getEndpoint(MuleEvent event, String endpointUri) throws MuleException
 93  
     {
 94  0
         OutboundEndpoint endpoint = (OutboundEndpoint) endpointCache.get(endpointUri);
 95  0
         if (endpoint == null)
 96  
         {
 97  0
             EndpointFactory endpointFactory = RegistryContext.getRegistry().lookupEndpointFactory();
 98  0
             EndpointBuilder endpointBuilder = endpointFactory.getEndpointBuilder(endpointUri);
 99  0
             if (transformers == null)
 100  
             {
 101  0
                 endpointBuilder.setTransformers(event.getEndpoint().getResponseTransformers());
 102  
             }
 103  0
             endpoint = endpointFactory.getOutboundEndpoint(endpointBuilder);
 104  0
             endpointCache.put(endpointUri, endpoint);
 105  
         }
 106  0
         return endpoint;
 107  
     }
 108  
 
 109  
     public List getTransformers()
 110  
     {
 111  0
         return transformers;
 112  
     }
 113  
 
 114  
     public void setTransformers(List transformers)
 115  
     {
 116  0
         this.transformers = transformers;
 117  0
     }
 118  
 
 119  
 }