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