Coverage Report - org.mule.providers.DefaultReplyToHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultReplyToHandler
0%
0/34
0%
0/12
2.6
 
 1  
 /*
 2  
  * $Id: DefaultReplyToHandler.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 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.providers;
 12  
 
 13  
 import org.mule.MuleManager;
 14  
 import org.mule.config.MuleProperties;
 15  
 import org.mule.config.i18n.CoreMessages;
 16  
 import org.mule.impl.MuleEvent;
 17  
 import org.mule.impl.endpoint.MuleEndpoint;
 18  
 import org.mule.impl.endpoint.MuleEndpointURI;
 19  
 import org.mule.impl.model.AbstractComponent;
 20  
 import org.mule.umo.UMOEvent;
 21  
 import org.mule.umo.UMOException;
 22  
 import org.mule.umo.UMOMessage;
 23  
 import org.mule.umo.endpoint.UMOEndpoint;
 24  
 import org.mule.umo.endpoint.UMOEndpointURI;
 25  
 import org.mule.umo.provider.DispatchException;
 26  
 import org.mule.umo.transformer.UMOTransformer;
 27  
 
 28  
 import java.util.HashMap;
 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 UMOTransformer transformer;
 47  0
     private final Map endpointCache = new HashMap();
 48  
 
 49  
     public DefaultReplyToHandler(UMOTransformer transformer)
 50  0
     {
 51  0
         this.transformer = transformer;
 52  0
     }
 53  
 
 54  
     public void processReplyTo(UMOEvent event, UMOMessage returnMessage, Object replyTo) throws UMOException
 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
         UMOEndpoint endpoint = getEndpoint(event, replyToEndpoint);
 65  
 
 66  0
         if (transformer == null)
 67  
         {
 68  0
             transformer = event.getEndpoint().getResponseTransformer();
 69  
         }
 70  
 
 71  0
         if (transformer != null)
 72  
         {
 73  0
             endpoint.setTransformer(transformer);
 74  
         }
 75  
 
 76  
         // make sure remove the replyTo property as not cause a a forever
 77  
         // replyto loop
 78  0
         returnMessage.removeProperty(MuleProperties.MULE_REPLY_TO_PROPERTY);
 79  
 
 80  
         // Create the replyTo event asynchronous
 81  0
         UMOEvent replyToEvent = new MuleEvent(returnMessage, endpoint, event.getSession(), false);
 82  
 
 83  
         // dispatch the event
 84  
         try
 85  
         {
 86  0
             endpoint.dispatch(replyToEvent);
 87  0
             if (logger.isInfoEnabled())
 88  
             {
 89  0
                 logger.info("reply to sent: " + endpoint);
 90  
             }
 91  0
             ((AbstractComponent) event.getComponent()).getStatistics().incSentReplyToEvent();
 92  
         }
 93  0
         catch (Exception e)
 94  
         {
 95  0
             throw new DispatchException(
 96  
                 CoreMessages.failedToDispatchToReplyto(endpoint),
 97  
                 replyToEvent.getMessage(), replyToEvent.getEndpoint(), e);
 98  0
         }
 99  
 
 100  0
     }
 101  
 
 102  
     protected synchronized UMOEndpoint getEndpoint(UMOEvent event, String endpointUri) throws UMOException
 103  
     {
 104  0
         UMOEndpoint endpoint = (UMOEndpoint) endpointCache.get(endpointUri);
 105  0
         if (endpoint == null)
 106  
         {
 107  0
             endpoint = MuleManager.getInstance().lookupEndpoint(endpointUri);
 108  0
             if (endpoint == null)
 109  
             {
 110  0
                 UMOEndpointURI ep = new MuleEndpointURI(endpointUri);
 111  0
                 endpoint = MuleEndpoint.getOrCreateEndpointForUri(ep, UMOEndpoint.ENDPOINT_TYPE_SENDER);
 112  0
                 endpointCache.put(endpointUri, endpoint);
 113  
             }
 114  
         }
 115  0
         return endpoint;
 116  
     }
 117  
 
 118  
     public UMOTransformer getTransformer()
 119  
     {
 120  0
         return transformer;
 121  
     }
 122  
 
 123  
     public void setTransformer(UMOTransformer transformer)
 124  
     {
 125  0
         this.transformer = transformer;
 126  0
     }
 127  
 
 128  
 }