1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.cxf.wsdl; |
12 | |
|
13 | |
import org.mule.api.endpoint.OutboundEndpoint; |
14 | |
import org.mule.transport.cxf.ClientWrapper; |
15 | |
import org.mule.transport.cxf.CxfMessageDispatcher; |
16 | |
import org.mule.util.StringUtils; |
17 | |
|
18 | |
import java.io.IOException; |
19 | |
|
20 | |
import javax.xml.namespace.QName; |
21 | |
|
22 | |
import org.apache.cxf.Bus; |
23 | |
import org.apache.cxf.endpoint.Client; |
24 | |
import org.apache.cxf.endpoint.dynamic.DynamicClientFactory; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class CxfWsdlMessageDispatcher extends CxfMessageDispatcher |
30 | |
{ |
31 | 0 | private final static Object CLIENT_CREATION_LOCK = new Object(); |
32 | |
|
33 | |
public CxfWsdlMessageDispatcher(OutboundEndpoint endpoint) |
34 | |
{ |
35 | 0 | super(endpoint); |
36 | 0 | } |
37 | |
|
38 | |
|
39 | |
protected void doConnect() throws Exception |
40 | |
{ |
41 | |
try |
42 | |
{ |
43 | 0 | wrapper = new ClientWrapper() { |
44 | |
|
45 | |
@Override |
46 | 0 | public void initialize() throws Exception, IOException |
47 | |
{ |
48 | 0 | String wsdlUrl = endpoint.getEndpointURI().getAddress(); |
49 | 0 | String serviceName = null; |
50 | 0 | String portName = null; |
51 | |
|
52 | |
|
53 | 0 | if (endpoint.getProperty("wsdlLocation") != null && StringUtils.isNotBlank(endpoint.getProperty("wsdlLocation").toString())) |
54 | |
{ |
55 | 0 | wsdlUrl = (String) endpoint.getProperty("wsdlLocation"); |
56 | |
} |
57 | |
|
58 | |
|
59 | 0 | if (endpoint.getProperty("service") != null && StringUtils.isNotBlank(endpoint.getProperty("service").toString())) |
60 | |
{ |
61 | 0 | serviceName = (String) endpoint.getProperty("service"); |
62 | |
} |
63 | |
|
64 | |
|
65 | 0 | if (endpoint.getProperty("port") != null && StringUtils.isNotBlank(endpoint.getProperty("port").toString())) |
66 | |
{ |
67 | 0 | portName = (String) endpoint.getProperty("port"); |
68 | |
} |
69 | |
|
70 | |
try |
71 | |
{ |
72 | 0 | this.client = createClient(bus, wsdlUrl, serviceName, portName); |
73 | |
|
74 | 0 | addMuleInterceptors(); |
75 | |
} |
76 | 0 | catch (Exception ex) |
77 | |
{ |
78 | 0 | disconnect(); |
79 | 0 | throw ex; |
80 | 0 | } |
81 | 0 | } |
82 | |
}; |
83 | 0 | wrapper.setBus(connector.getCxfBus()); |
84 | 0 | wrapper.setEndpoint(endpoint); |
85 | 0 | wrapper.initialize(); |
86 | |
} |
87 | 0 | catch (Exception ex) |
88 | |
{ |
89 | 0 | disconnect(); |
90 | 0 | throw ex; |
91 | 0 | } |
92 | 0 | } |
93 | |
|
94 | |
protected Client createClient(Bus bus, String wsdlUrl, String serviceName, String portName) throws Exception |
95 | |
{ |
96 | 0 | synchronized (CLIENT_CREATION_LOCK) |
97 | |
{ |
98 | 0 | DynamicClientFactory cf = DynamicClientFactory.newInstance(bus); |
99 | 0 | return cf.createClient(wsdlUrl, |
100 | |
(serviceName == null ? null : QName.valueOf(serviceName)), |
101 | |
(portName == null ? null : QName.valueOf(portName))); |
102 | 0 | } |
103 | |
} |
104 | |
} |