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 private final static Object CLIENT_CREATION_LOCK = new Object();
32
33 public CxfWsdlMessageDispatcher(OutboundEndpoint endpoint)
34 {
35 super(endpoint);
36 }
37
38
39 protected void doConnect() throws Exception
40 {
41 try
42 {
43 wrapper = new ClientWrapper() {
44
45 @Override
46 public void initialize() throws Exception, IOException
47 {
48 String wsdlUrl = endpoint.getEndpointURI().getAddress();
49 String serviceName = null;
50 String portName = null;
51
52
53 if (endpoint.getProperty("wsdlLocation") != null && StringUtils.isNotBlank(endpoint.getProperty("wsdlLocation").toString()))
54 {
55 wsdlUrl = (String) endpoint.getProperty("wsdlLocation");
56 }
57
58
59 if (endpoint.getProperty("service") != null && StringUtils.isNotBlank(endpoint.getProperty("service").toString()))
60 {
61 serviceName = (String) endpoint.getProperty("service");
62 }
63
64
65 if (endpoint.getProperty("port") != null && StringUtils.isNotBlank(endpoint.getProperty("port").toString()))
66 {
67 portName = (String) endpoint.getProperty("port");
68 }
69
70 try
71 {
72 this.client = createClient(bus, wsdlUrl, serviceName, portName);
73
74 addMuleInterceptors();
75 }
76 catch (Exception ex)
77 {
78 disconnect();
79 throw ex;
80 }
81 }
82 };
83 wrapper.setBus(connector.getCxfBus());
84 wrapper.setEndpoint(endpoint);
85 wrapper.initialize();
86 }
87 catch (Exception ex)
88 {
89 disconnect();
90 throw ex;
91 }
92 }
93
94 protected Client createClient(Bus bus, String wsdlUrl, String serviceName, String portName) throws Exception
95 {
96 synchronized (CLIENT_CREATION_LOCK)
97 {
98 DynamicClientFactory cf = DynamicClientFactory.newInstance(bus);
99 return cf.createClient(wsdlUrl,
100 (serviceName == null ? null : QName.valueOf(serviceName)),
101 (portName == null ? null : QName.valueOf(portName)));
102 }
103 }
104 }