Coverage Report - org.mule.config.endpoint.ConfigurableTransportFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
ConfigurableTransportFactory
0%
0/28
0%
0/8
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.config.endpoint;
 8  
 
 9  
 import org.mule.api.DefaultMuleException;
 10  
 import org.mule.api.MuleContext;
 11  
 import org.mule.api.MuleException;
 12  
 import org.mule.api.endpoint.EndpointURI;
 13  
 import org.mule.api.transport.Connector;
 14  
 import org.mule.transport.service.TransportFactory;
 15  
 import org.mule.transport.service.TransportFactoryException;
 16  
 import org.mule.util.BeanUtils;
 17  
 import org.mule.util.ClassUtils;
 18  
 import org.mule.util.PropertiesUtils;
 19  
 
 20  
 import java.io.IOException;
 21  
 import java.net.URL;
 22  
 import java.util.Enumeration;
 23  
 import java.util.Map;
 24  
 import java.util.Properties;
 25  
 
 26  
 /**
 27  
  * TODO
 28  
  */
 29  
 public class ConfigurableTransportFactory extends TransportFactory
 30  
 {
 31  
     public static final String CHANNEL_OVERRIDES = "_configuredConnectorOverrides";
 32  
     public static final String CHANNEL_OVERRIDES_FILE = "META-INF/services/org/mule/config/channel-overrides.properties";
 33  
     public static final String SINGLETON_PROPERTY = "singleton";
 34  
     public static final String TRUE = "TRUE";
 35  
 
 36  
     private Properties overrides;
 37  
 
 38  
     public ConfigurableTransportFactory(MuleContext muleContext) throws MuleException
 39  
     {
 40  0
         super(muleContext);
 41  0
         overrides = (Properties) muleContext.getRegistry().lookupObject(CHANNEL_OVERRIDES);
 42  0
         if (overrides == null)
 43  
         {
 44  0
             overrides = loadOverrides();
 45  0
             muleContext.getRegistry().registerObject(CHANNEL_OVERRIDES, overrides);
 46  
         }
 47  0
     }
 48  
 
 49  
     @Override
 50  
     public Connector createConnector(EndpointURI endpointURI) throws TransportFactoryException
 51  
     {
 52  
         Connector c;
 53  0
         String scheme = endpointURI.getScheme();
 54  0
         Map temp = new Properties();
 55  0
         PropertiesUtils.getPropertiesWithPrefix(overrides, scheme, temp);
 56  0
         temp = PropertiesUtils.removeNamespaces(temp);
 57  0
         String singleton = (String) temp.remove(SINGLETON_PROPERTY);
 58  0
         if (TRUE.equalsIgnoreCase(singleton))
 59  
         {
 60  0
             c = this.getConnectorByProtocol(scheme);
 61  0
             if (c != null)
 62  
             {
 63  0
                 return c;
 64  
             }
 65  
         }
 66  0
         c = super.createConnector(endpointURI);
 67  0
         BeanUtils.populateWithoutFail(c, temp, true);
 68  0
         return c;
 69  
     }
 70  
 
 71  
     protected Properties loadOverrides() throws MuleException
 72  
     {
 73  0
         Properties props = new Properties();
 74  0
         Enumeration e = ClassUtils.getResources(CHANNEL_OVERRIDES_FILE, getClass());
 75  0
         while (e.hasMoreElements())
 76  
         {
 77  0
             URL url = (URL) e.nextElement();
 78  
             try
 79  
             {
 80  0
                 props.load(url.openStream());
 81  
             }
 82  0
             catch (IOException e1)
 83  
             {
 84  0
                 throw new DefaultMuleException("failed to read channel overrides from URL: " + url.toExternalForm());
 85  0
             }
 86  0
         }
 87  0
         return props;
 88  
     }
 89  
 }