1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.module.cxf.support; |
8 | |
|
9 | |
import org.mule.module.cxf.i18n.CxfMessages; |
10 | |
|
11 | |
import java.util.Iterator; |
12 | |
import java.util.LinkedList; |
13 | |
import java.util.List; |
14 | |
import java.util.Map; |
15 | |
import java.util.logging.Logger; |
16 | |
|
17 | |
import javax.wsdl.Definition; |
18 | |
import javax.wsdl.Port; |
19 | |
import javax.wsdl.Service; |
20 | |
import javax.wsdl.WSDLException; |
21 | |
import javax.xml.namespace.QName; |
22 | |
|
23 | |
import org.apache.commons.collections.CollectionUtils; |
24 | |
import org.apache.commons.collections.Predicate; |
25 | |
import org.apache.cxf.common.i18n.Message; |
26 | |
import org.apache.cxf.common.logging.LogUtils; |
27 | |
import org.apache.cxf.service.factory.DefaultServiceConfiguration; |
28 | |
import org.apache.cxf.service.factory.ServiceConstructionException; |
29 | |
import org.apache.cxf.wsdl.WSDLManager; |
30 | |
|
31 | 0 | public class ProxyServiceConfiguration extends DefaultServiceConfiguration |
32 | |
{ |
33 | |
|
34 | 0 | private static final Logger LOG = LogUtils.getLogger(ProxyServiceFactoryBean.class); |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
@Override |
44 | |
public QName getEndpointName() |
45 | |
{ |
46 | |
try |
47 | |
{ |
48 | 0 | if (getServiceFactory().getWsdlURL() != null) |
49 | |
{ |
50 | 0 | Definition definition = getServiceFactory().getBus() |
51 | |
.getExtension(WSDLManager.class) |
52 | |
.getDefinition(getServiceFactory().getWsdlURL()); |
53 | 0 | Service service = getServiceFromDefinition(definition); |
54 | 0 | setServiceNamespace(service.getQName().getNamespaceURI()); |
55 | 0 | return new QName(getServiceNamespace(), ((Port) service.getPorts().values().iterator().next()).getName()); |
56 | |
} |
57 | |
else |
58 | |
{ |
59 | 0 | return super.getEndpointName(); |
60 | |
} |
61 | |
|
62 | |
} |
63 | 0 | catch (WSDLException e) |
64 | |
{ |
65 | 0 | throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), e); |
66 | |
} |
67 | |
} |
68 | |
|
69 | |
protected Service getServiceFromDefinition(Definition definition) |
70 | |
{ |
71 | 0 | Service service = definition.getService(getServiceFactory().getServiceQName()); |
72 | 0 | if (service == null) |
73 | |
{ |
74 | 0 | List<QName> probableServices = getProbableServices(definition); |
75 | 0 | List<QName> allServices = getAllServices(definition); |
76 | 0 | throw new ComponentNotFoundRuntimeException(CxfMessages.invalidOrMissingNamespace( |
77 | |
getServiceFactory().getServiceQName(), probableServices, allServices)); |
78 | |
} |
79 | 0 | return service; |
80 | |
} |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
@SuppressWarnings("unchecked") |
88 | |
protected List<QName> getAllServices(Definition definition) |
89 | |
{ |
90 | 0 | return new LinkedList<QName>(CollectionUtils.select(definition.getServices().keySet(), |
91 | |
new Predicate() |
92 | 0 | { |
93 | |
public boolean evaluate(Object object) |
94 | |
{ |
95 | 0 | return object instanceof QName; |
96 | |
} |
97 | |
})); |
98 | |
} |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
protected List<QName> getProbableServices(Definition definition) |
106 | |
{ |
107 | 0 | QName serviceQName = getServiceFactory().getServiceQName(); |
108 | 0 | List<QName> probableServices = new LinkedList<QName>(); |
109 | 0 | Map<?, ?> services = definition.getServices(); |
110 | 0 | for (Iterator<?> iterator = services.keySet().iterator(); iterator.hasNext();) |
111 | |
{ |
112 | 0 | Object key = iterator.next(); |
113 | 0 | if (key instanceof QName) |
114 | |
{ |
115 | 0 | QName qNameKey = (QName) key; |
116 | 0 | if (qNameKey.getLocalPart() != null |
117 | |
&& qNameKey.getLocalPart().equals(serviceQName.getLocalPart())) |
118 | |
{ |
119 | 0 | probableServices.add(qNameKey); |
120 | |
} |
121 | |
} |
122 | 0 | } |
123 | 0 | return probableServices; |
124 | |
} |
125 | |
} |