1
2
3
4
5
6
7
8
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 public class ProxyServiceConfiguration extends DefaultServiceConfiguration
36 {
37
38 private static final Logger LOG = LogUtils.getLogger(ProxyServiceFactoryBean.class);
39
40
41
42
43
44
45
46
47 @Override
48 public QName getEndpointName()
49 {
50 try
51 {
52 if (getServiceFactory().getWsdlURL() != null)
53 {
54 Definition definition = getServiceFactory().getBus()
55 .getExtension(WSDLManager.class)
56 .getDefinition(getServiceFactory().getWsdlURL());
57 Service service = getServiceFromDefinition(definition);
58 setServiceNamespace(service.getQName().getNamespaceURI());
59 return new QName(getServiceNamespace(), ((Port) service.getPorts().values().iterator().next()).getName());
60 }
61 else
62 {
63 return super.getEndpointName();
64 }
65
66 }
67 catch (WSDLException e)
68 {
69 throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), e);
70 }
71 }
72
73 protected Service getServiceFromDefinition(Definition definition)
74 {
75 Service service = definition.getService(getServiceFactory().getServiceQName());
76 if (service == null)
77 {
78 List<QName> probableServices = getProbableServices(definition);
79 List<QName> allServices = getAllServices(definition);
80 throw new ComponentNotFoundRuntimeException(CxfMessages.invalidOrMissingNamespace(
81 getServiceFactory().getServiceQName(), probableServices, allServices));
82 }
83 return service;
84 }
85
86
87
88
89
90
91 @SuppressWarnings("unchecked")
92 protected List<QName> getAllServices(Definition definition)
93 {
94 return new LinkedList<QName>(CollectionUtils.select(definition.getServices().keySet(),
95 new Predicate()
96 {
97 public boolean evaluate(Object object)
98 {
99 return object instanceof QName;
100 }
101 }));
102 }
103
104
105
106
107
108
109 protected List<QName> getProbableServices(Definition definition)
110 {
111 QName serviceQName = getServiceFactory().getServiceQName();
112 List<QName> probableServices = new LinkedList<QName>();
113 Map<?, ?> services = definition.getServices();
114 for (Iterator<?> iterator = services.keySet().iterator(); iterator.hasNext();)
115 {
116 Object key = iterator.next();
117 if (key instanceof QName)
118 {
119 QName qNameKey = (QName) key;
120 if (qNameKey.getLocalPart() != null
121 && qNameKey.getLocalPart().equals(serviceQName.getLocalPart()))
122 {
123 probableServices.add(qNameKey);
124 }
125 }
126 }
127 return probableServices;
128 }
129 }