1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.module.cxf.transport; |
8 | |
|
9 | |
import org.mule.module.cxf.CxfConfiguration; |
10 | |
|
11 | |
import java.io.IOException; |
12 | |
import java.util.ArrayList; |
13 | |
import java.util.HashMap; |
14 | |
import java.util.HashSet; |
15 | |
import java.util.Iterator; |
16 | |
import java.util.List; |
17 | |
import java.util.Map; |
18 | |
import java.util.Set; |
19 | |
|
20 | |
import javax.wsdl.Port; |
21 | |
import javax.wsdl.extensions.http.HTTPAddress; |
22 | |
import javax.wsdl.extensions.soap.SOAPAddress; |
23 | |
import javax.xml.namespace.QName; |
24 | |
|
25 | |
import org.apache.cxf.Bus; |
26 | |
import org.apache.cxf.service.Service; |
27 | |
import org.apache.cxf.service.model.BindingInfo; |
28 | |
import org.apache.cxf.service.model.EndpointInfo; |
29 | |
import org.apache.cxf.service.model.ServiceInfo; |
30 | |
import org.apache.cxf.transport.AbstractTransportFactory; |
31 | |
import org.apache.cxf.transport.Conduit; |
32 | |
import org.apache.cxf.transport.ConduitInitiator; |
33 | |
import org.apache.cxf.transport.Destination; |
34 | |
import org.apache.cxf.transport.DestinationFactory; |
35 | |
import org.apache.cxf.ws.addressing.AttributedURIType; |
36 | |
import org.apache.cxf.ws.addressing.EndpointReferenceType; |
37 | |
import org.apache.cxf.wsdl.http.AddressType; |
38 | |
import org.apache.cxf.wsdl11.WSDLEndpointFactory; |
39 | |
|
40 | |
public class MuleUniversalTransport extends AbstractTransportFactory |
41 | |
implements ConduitInitiator, DestinationFactory, WSDLEndpointFactory |
42 | |
{ |
43 | |
|
44 | |
public static final String TRANSPORT_ID = "http://mule.codehaus.org/cxf"; |
45 | |
|
46 | 0 | private static Set<String> PREFIXES = new HashSet<String>(); |
47 | |
static |
48 | |
{ |
49 | 0 | PREFIXES.add("http://"); |
50 | 0 | PREFIXES.add("https://"); |
51 | 0 | PREFIXES.add("jms://"); |
52 | 0 | PREFIXES.add("vm://"); |
53 | 0 | PREFIXES.add("xmpp://"); |
54 | 0 | PREFIXES.add("smtp://"); |
55 | 0 | PREFIXES.add("tcp://"); |
56 | 0 | } |
57 | |
|
58 | 0 | private Map<String, Destination> destinations = new HashMap<String, Destination>(); |
59 | |
|
60 | |
private Bus bus; |
61 | |
|
62 | |
private CxfConfiguration connector; |
63 | |
|
64 | |
public MuleUniversalTransport(CxfConfiguration connector) |
65 | |
{ |
66 | 0 | super(); |
67 | |
|
68 | 0 | ArrayList<String> tids = new ArrayList<String>(); |
69 | 0 | tids.add("http://schemas.xmlsoap.org/soap/http"); |
70 | 0 | setTransportIds(tids); |
71 | |
|
72 | 0 | this.connector = connector; |
73 | 0 | } |
74 | |
|
75 | |
public Destination getDestination(EndpointInfo ei) throws IOException |
76 | |
{ |
77 | 0 | return getDestination(ei, createReference(ei)); |
78 | |
} |
79 | |
|
80 | |
protected Destination getDestination(EndpointInfo ei, EndpointReferenceType reference) throws IOException |
81 | |
{ |
82 | 0 | String uri = reference.getAddress().getValue(); |
83 | 0 | int idx = uri.indexOf('?'); |
84 | 0 | if (idx != -1) |
85 | |
{ |
86 | 0 | uri = uri.substring(0, idx); |
87 | |
} |
88 | |
|
89 | 0 | synchronized (this) |
90 | |
{ |
91 | 0 | Destination d = destinations.get(uri); |
92 | 0 | if (d == null) |
93 | |
{ |
94 | 0 | d = createDestination(ei, reference); |
95 | 0 | destinations.put(uri, d); |
96 | |
} |
97 | 0 | return d; |
98 | 0 | } |
99 | |
} |
100 | |
|
101 | |
private Destination createDestination(EndpointInfo ei, EndpointReferenceType reference) |
102 | |
{ |
103 | 0 | return new MuleUniversalDestination(this, reference, ei); |
104 | |
} |
105 | |
|
106 | |
public Conduit getConduit(EndpointInfo ei) throws IOException |
107 | |
{ |
108 | 0 | return new MuleUniversalConduit(this, connector, ei, null); |
109 | |
} |
110 | |
|
111 | |
public Conduit getConduit(EndpointInfo ei, EndpointReferenceType target) throws IOException |
112 | |
{ |
113 | 0 | return new MuleUniversalConduit(this, connector, ei, target); |
114 | |
} |
115 | |
|
116 | |
EndpointReferenceType createReference(EndpointInfo ei) |
117 | |
{ |
118 | 0 | EndpointReferenceType epr = new EndpointReferenceType(); |
119 | 0 | AttributedURIType address = new AttributedURIType(); |
120 | 0 | address.setValue(ei.getAddress()); |
121 | 0 | epr.setAddress(address); |
122 | 0 | return epr; |
123 | |
} |
124 | |
|
125 | |
@Override |
126 | |
public Set<String> getUriPrefixes() |
127 | |
{ |
128 | 0 | return PREFIXES; |
129 | |
} |
130 | |
|
131 | |
public Bus getBus() |
132 | |
{ |
133 | 0 | return bus; |
134 | |
} |
135 | |
|
136 | |
public void setBus(Bus bus) |
137 | |
{ |
138 | 0 | this.bus = bus; |
139 | 0 | } |
140 | |
|
141 | |
void remove(MuleUniversalDestination destination) |
142 | |
{ |
143 | 0 | destinations.remove(destination.getAddress().getAddress().getValue()); |
144 | 0 | } |
145 | |
|
146 | |
public CxfConfiguration getConnector() |
147 | |
{ |
148 | 0 | return connector; |
149 | |
} |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
public void createPortExtensors(EndpointInfo ei, Service service) |
155 | |
{ |
156 | |
|
157 | 0 | } |
158 | |
|
159 | |
@SuppressWarnings("unchecked") |
160 | |
public EndpointInfo createEndpointInfo(ServiceInfo serviceInfo, BindingInfo b, Port port) |
161 | |
{ |
162 | 0 | if (port != null) |
163 | |
{ |
164 | 0 | List ees = port.getExtensibilityElements(); |
165 | 0 | for (Iterator itr = ees.iterator(); itr.hasNext();) |
166 | |
{ |
167 | 0 | Object extensor = itr.next(); |
168 | |
|
169 | 0 | if (extensor instanceof HTTPAddress) |
170 | |
{ |
171 | 0 | final HTTPAddress httpAdd = (HTTPAddress) extensor; |
172 | |
|
173 | 0 | EndpointInfo info = new HttpEndpointInfo(serviceInfo, |
174 | |
"http://schemas.xmlsoap.org/wsdl/http/"); |
175 | 0 | info.setAddress(httpAdd.getLocationURI()); |
176 | 0 | info.addExtensor(httpAdd); |
177 | 0 | return info; |
178 | |
} |
179 | 0 | else if (extensor instanceof AddressType) |
180 | |
{ |
181 | 0 | final AddressType httpAdd = (AddressType) extensor; |
182 | |
|
183 | 0 | EndpointInfo info = new HttpEndpointInfo(serviceInfo, |
184 | |
"http://schemas.xmlsoap.org/wsdl/http/"); |
185 | 0 | info.setAddress(httpAdd.getLocation()); |
186 | 0 | info.addExtensor(httpAdd); |
187 | 0 | return info; |
188 | |
} |
189 | 0 | } |
190 | |
} |
191 | 0 | HttpEndpointInfo hei = new HttpEndpointInfo(serviceInfo, "http://schemas.xmlsoap.org/wsdl/http/"); |
192 | 0 | AddressType at = new HttpAddressType(); |
193 | 0 | hei.addExtensor(at); |
194 | |
|
195 | 0 | return hei; |
196 | |
} |
197 | |
|
198 | |
private static class HttpEndpointInfo extends EndpointInfo |
199 | |
{ |
200 | |
AddressType saddress; |
201 | |
|
202 | |
HttpEndpointInfo(ServiceInfo serv, String trans) |
203 | |
{ |
204 | 0 | super(serv, trans); |
205 | 0 | } |
206 | |
|
207 | |
public void setAddress(String s) |
208 | |
{ |
209 | 0 | super.setAddress(s); |
210 | 0 | if (saddress != null) |
211 | |
{ |
212 | 0 | saddress.setLocation(s); |
213 | |
} |
214 | 0 | } |
215 | |
|
216 | |
public void addExtensor(Object el) |
217 | |
{ |
218 | 0 | super.addExtensor(el); |
219 | 0 | if (el instanceof AddressType) |
220 | |
{ |
221 | 0 | saddress = (AddressType) el; |
222 | |
} |
223 | 0 | } |
224 | |
} |
225 | |
|
226 | |
private static class HttpAddressType extends AddressType implements HTTPAddress, SOAPAddress |
227 | |
{ |
228 | |
public HttpAddressType() |
229 | |
{ |
230 | 0 | super(); |
231 | 0 | setElementType(new QName("http://schemas.xmlsoap.org/wsdl/soap/", "address")); |
232 | 0 | } |
233 | |
|
234 | |
public String getLocationURI() |
235 | |
{ |
236 | 0 | return getLocation(); |
237 | |
} |
238 | |
|
239 | |
public void setLocationURI(String locationURI) |
240 | |
{ |
241 | 0 | setLocation(locationURI); |
242 | 0 | } |
243 | |
|
244 | |
} |
245 | |
} |