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 | 0 | public class ProxyServiceConfiguration extends DefaultServiceConfiguration |
36 | |
{ |
37 | |
|
38 | 0 | 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 | 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 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
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 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
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 | |
} |