Coverage Report - org.mule.module.cxf.support.ProxyServiceConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
ProxyServiceConfiguration
0%
0/28
0%
0/12
0
ProxyServiceConfiguration$1
0%
0/2
N/A
0
 
 1  
 /*
 2  
  * $Id: ProxyServiceConfiguration.java 19383 2010-09-06 20:37:51Z epere4 $
 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  
 
 11  
 package org.mule.module.cxf.support;
 12  
 
 13  
 import org.mule.module.cxf.i18n.CxfMessages;
 14  
 
 15  
 import java.util.Iterator;
 16  
 import java.util.LinkedList;
 17  
 import java.util.List;
 18  
 import java.util.Map;
 19  
 import java.util.logging.Logger;
 20  
 
 21  
 import javax.wsdl.Definition;
 22  
 import javax.wsdl.Port;
 23  
 import javax.wsdl.Service;
 24  
 import javax.wsdl.WSDLException;
 25  
 import javax.xml.namespace.QName;
 26  
 
 27  
 import org.apache.commons.collections.CollectionUtils;
 28  
 import org.apache.commons.collections.Predicate;
 29  
 import org.apache.cxf.common.i18n.Message;
 30  
 import org.apache.cxf.common.logging.LogUtils;
 31  
 import org.apache.cxf.service.factory.DefaultServiceConfiguration;
 32  
 import org.apache.cxf.service.factory.ServiceConstructionException;
 33  
 import org.apache.cxf.wsdl.WSDLManager;
 34  
 
 35  0
 public class ProxyServiceConfiguration extends DefaultServiceConfiguration
 36  
 {
 37  
 
 38  0
     private static final Logger LOG = LogUtils.getLogger(ProxyServiceFactoryBean.class);
 39  
 
 40  
     /**
 41  
      * Override to use port name from service definition in WSDL when we are doing
 42  
      * WSDL-first. This is required so that CXF's internal endpointName and port name
 43  
      * match and a CXF Service gets created. See:
 44  
      * https://issues.apache.org/jira/browse/CXF-1920
 45  
      * http://fisheye6.atlassian.com/changelog/cxf?cs=737994
 46  
      * 
 47  
      * @Override
 48  
      */
 49  
     @Override
 50  
     public QName getEndpointName()
 51  
     {
 52  
         try
 53  
         {
 54  0
             if (getServiceFactory().getWsdlURL() != null)
 55  
             {
 56  0
                 Definition definition = getServiceFactory().getBus()
 57  
                     .getExtension(WSDLManager.class)
 58  
                     .getDefinition(getServiceFactory().getWsdlURL());
 59  0
                 Service service = getServiceFromDefinition(definition);
 60  0
                 setServiceNamespace(service.getQName().getNamespaceURI());
 61  0
                 return new QName(getServiceNamespace(), ((Port) service.getPorts().values().iterator().next()).getName());
 62  
             }
 63  
             else
 64  
             {
 65  0
                 return super.getEndpointName();
 66  
             }
 67  
 
 68  
         }
 69  0
         catch (WSDLException e)
 70  
         {
 71  0
             throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), e);
 72  
         }
 73  
     }
 74  
 
 75  
     protected Service getServiceFromDefinition(Definition definition)
 76  
     {
 77  0
         Service service = definition.getService(getServiceFactory().getServiceQName());
 78  0
         if (service == null)
 79  
         {
 80  0
             List<QName> probableServices = getProbableServices(definition);
 81  0
             List<QName> allServices = getAllServices(definition);
 82  0
             throw new ComponentNotFoundRuntimeException(CxfMessages.invalidOrMissingNamespace(
 83  
                 getServiceFactory().getServiceQName(), probableServices, allServices));
 84  
         }
 85  0
         return service;
 86  
     }
 87  
 
 88  
     /**
 89  
      * This method returns a list of all the services defined in the definition. Its
 90  
      * current purpose is only for generating a better error message when the service
 91  
      * cannot be found.
 92  
      * 
 93  
      * @param definition
 94  
      * @return
 95  
      */
 96  
     @SuppressWarnings("unchecked")
 97  
     protected List<QName> getAllServices(Definition definition)
 98  
     {
 99  0
         return new LinkedList<QName>(CollectionUtils.select(definition.getServices().keySet(),
 100  
             new Predicate()
 101  0
             {
 102  
                 public boolean evaluate(Object object)
 103  
                 {
 104  0
                     return object instanceof QName;
 105  
                 }
 106  
             }));
 107  
     }
 108  
 
 109  
     /**
 110  
      * This method returns the list of services that matches with the local part of
 111  
      * the service QName. Its current purpose is only for generating a better error
 112  
      * message when the service cannot be found.
 113  
      * 
 114  
      * @param definition
 115  
      * @return
 116  
      */
 117  
     protected List<QName> getProbableServices(Definition definition)
 118  
     {
 119  0
         QName serviceQName = getServiceFactory().getServiceQName();
 120  0
         List<QName> probableServices = new LinkedList<QName>();
 121  0
         Map<?, ?> services = definition.getServices();
 122  0
         for (Iterator<?> iterator = services.keySet().iterator(); iterator.hasNext();)
 123  
         {
 124  0
             Object key = iterator.next();
 125  0
             if (key instanceof QName)
 126  
             {
 127  0
                 QName qNameKey = (QName) key;
 128  0
                 if (qNameKey.getLocalPart() != null
 129  
                     && qNameKey.getLocalPart().equals(serviceQName.getLocalPart()))
 130  
                 {
 131  0
                     probableServices.add(qNameKey);
 132  
                 }
 133  
             }
 134  0
         }
 135  0
         return probableServices;
 136  
     }
 137  
 }