1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.impl.endpoint; |
12 | |
|
13 | |
import org.mule.MuleManager; |
14 | |
import org.mule.providers.service.TransportFactory; |
15 | |
import org.mule.providers.service.TransportFactoryException; |
16 | |
import org.mule.providers.service.TransportServiceDescriptor; |
17 | |
import org.mule.umo.endpoint.MalformedEndpointException; |
18 | |
import org.mule.umo.endpoint.UMOEndpointURI; |
19 | |
import org.mule.util.PropertiesUtils; |
20 | |
import org.mule.util.StringUtils; |
21 | |
|
22 | |
import java.net.URI; |
23 | |
import java.net.URISyntaxException; |
24 | |
import java.util.Properties; |
25 | |
|
26 | |
import org.apache.commons.logging.Log; |
27 | |
import org.apache.commons.logging.LogFactory; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public class MuleEndpointURI implements UMOEndpointURI |
41 | |
{ |
42 | |
|
43 | |
|
44 | |
|
45 | |
private static final long serialVersionUID = 3906735768171252877L; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | 4 | protected static final Log logger = LogFactory.getLog(MuleEndpointURI.class); |
51 | |
|
52 | |
public static boolean isMuleUri(String url) |
53 | |
{ |
54 | 0 | return url.indexOf(":/") != -1; |
55 | |
} |
56 | |
|
57 | |
private String address; |
58 | |
private String filterAddress; |
59 | |
private String endpointName; |
60 | |
private String connectorName; |
61 | |
private String transformers; |
62 | |
private String responseTransformers; |
63 | 1780 | private int createConnector = TransportFactory.GET_OR_CREATE_CONNECTOR; |
64 | 1780 | private Properties params = new Properties(); |
65 | |
private URI uri; |
66 | |
private String uriString; |
67 | |
private String userInfo; |
68 | |
private String schemeMetaInfo; |
69 | |
private String resourceInfo; |
70 | |
|
71 | |
MuleEndpointURI(String address, |
72 | |
String endpointName, |
73 | |
String connectorName, |
74 | |
String transformers, |
75 | |
String responseTransformers, |
76 | |
int createConnector, |
77 | |
Properties properties, |
78 | |
URI uri, |
79 | |
String userInfo) |
80 | |
{ |
81 | 860 | this(address, endpointName, connectorName, transformers, responseTransformers, createConnector, |
82 | |
properties, uri); |
83 | 860 | if (userInfo != null) |
84 | |
{ |
85 | 8 | this.userInfo = userInfo; |
86 | |
} |
87 | 860 | } |
88 | |
|
89 | |
public MuleEndpointURI(String address, |
90 | |
String endpointName, |
91 | |
String connectorName, |
92 | |
String transformers, |
93 | |
String responseTransformers, |
94 | |
int createConnector, |
95 | |
Properties properties, |
96 | |
URI uri) |
97 | 860 | { |
98 | 860 | this.address = address; |
99 | 860 | this.endpointName = endpointName; |
100 | 860 | this.connectorName = connectorName; |
101 | 860 | this.transformers = transformers; |
102 | 860 | this.responseTransformers = responseTransformers; |
103 | 860 | this.createConnector = createConnector; |
104 | 860 | this.params = properties; |
105 | 860 | this.uri = uri; |
106 | 860 | this.uriString = uri.toASCIIString(); |
107 | 860 | this.userInfo = uri.getUserInfo(); |
108 | 860 | if (properties != null) |
109 | |
{ |
110 | 860 | resourceInfo = (String) properties.remove("resourceInfo"); |
111 | |
} |
112 | 860 | } |
113 | |
|
114 | |
public MuleEndpointURI(UMOEndpointURI endpointUri) |
115 | 58 | { |
116 | 58 | initialise(endpointUri); |
117 | 58 | } |
118 | |
|
119 | |
public MuleEndpointURI(UMOEndpointURI endpointUri, String filterAddress) |
120 | 0 | { |
121 | 0 | initialise(endpointUri); |
122 | 0 | this.filterAddress = filterAddress; |
123 | 0 | } |
124 | |
|
125 | |
public MuleEndpointURI(String uri) throws MalformedEndpointException |
126 | 862 | { |
127 | 862 | String uriIdentifier = MuleManager.getInstance().lookupEndpointIdentifier(uri, uri); |
128 | 862 | if (!uriIdentifier.equals(uri)) |
129 | |
{ |
130 | 0 | endpointName = uri; |
131 | 0 | uri = uriIdentifier; |
132 | |
} |
133 | |
|
134 | 862 | uri = uri.trim().replaceAll(" ", "%20"); |
135 | |
|
136 | 862 | if (!validateUrl(uri)) |
137 | |
{ |
138 | 2 | throw new MalformedEndpointException(uri); |
139 | |
} |
140 | |
try |
141 | |
{ |
142 | 860 | schemeMetaInfo = retrieveSchemeMetaInfo(uri); |
143 | 860 | if (schemeMetaInfo != null) |
144 | |
{ |
145 | 0 | uri = uri.replaceFirst(schemeMetaInfo + ":", ""); |
146 | |
} |
147 | 860 | this.uri = new URI(uri); |
148 | 860 | this.userInfo = this.uri.getRawUserInfo(); |
149 | |
} |
150 | 0 | catch (URISyntaxException e) |
151 | |
{ |
152 | 0 | throw new MalformedEndpointException(uri, e); |
153 | 860 | } |
154 | |
|
155 | |
try |
156 | |
{ |
157 | 860 | String scheme = (schemeMetaInfo == null ? this.uri.getScheme() : schemeMetaInfo); |
158 | 860 | TransportServiceDescriptor csd = TransportFactory.getServiceDescriptor(scheme); |
159 | 860 | EndpointBuilder builder = csd.createEndpointBuilder(); |
160 | 860 | UMOEndpointURI built = builder.build(this.uri); |
161 | 860 | initialise(built); |
162 | |
} |
163 | 0 | catch (TransportFactoryException e) |
164 | |
{ |
165 | 0 | throw new MalformedEndpointException(e); |
166 | 860 | } |
167 | 860 | } |
168 | |
|
169 | |
private String retrieveSchemeMetaInfo(String url) |
170 | |
{ |
171 | 860 | int i = url.indexOf(':'); |
172 | 860 | if (i == -1) |
173 | |
{ |
174 | 0 | return null; |
175 | |
} |
176 | 860 | if (url.charAt(i + 1) == '/') |
177 | |
{ |
178 | 860 | return null; |
179 | |
} |
180 | |
else |
181 | |
{ |
182 | 0 | return url.substring(0, i); |
183 | |
} |
184 | |
} |
185 | |
|
186 | |
protected boolean validateUrl(String url) |
187 | |
{ |
188 | 862 | return (url.indexOf(":/") > 0); |
189 | |
} |
190 | |
|
191 | |
private void initialise(UMOEndpointURI endpointUri) |
192 | |
{ |
193 | 918 | this.address = endpointUri.getAddress(); |
194 | 918 | if (this.endpointName == null) |
195 | |
{ |
196 | 918 | this.endpointName = endpointUri.getEndpointName(); |
197 | |
} |
198 | 918 | this.connectorName = endpointUri.getConnectorName(); |
199 | 918 | this.transformers = endpointUri.getTransformers(); |
200 | 918 | this.responseTransformers = endpointUri.getResponseTransformers(); |
201 | 918 | this.createConnector = endpointUri.getCreateConnector(); |
202 | 918 | this.params = endpointUri.getParams(); |
203 | 918 | this.uri = endpointUri.getUri(); |
204 | 918 | this.uriString = this.uri.toASCIIString(); |
205 | 918 | this.resourceInfo = endpointUri.getResourceInfo(); |
206 | 918 | this.userInfo = endpointUri.getUserInfo(); |
207 | 918 | } |
208 | |
|
209 | |
public String getAddress() |
210 | |
{ |
211 | 1520 | return address; |
212 | |
} |
213 | |
|
214 | |
public String getEndpointName() |
215 | |
{ |
216 | 1066 | return (StringUtils.isEmpty(endpointName) ? null : endpointName); |
217 | |
} |
218 | |
|
219 | |
public Properties getParams() |
220 | |
{ |
221 | |
|
222 | |
|
223 | 3956 | if (params.size() == 0 && getQuery() != null) |
224 | |
{ |
225 | 0 | params = PropertiesUtils.getPropertiesFromQueryString(getQuery()); |
226 | |
} |
227 | 3956 | return params; |
228 | |
} |
229 | |
|
230 | |
public Properties getUserParams() |
231 | |
{ |
232 | 0 | Properties p = new Properties(); |
233 | 0 | p.putAll(params); |
234 | 0 | p.remove(PROPERTY_ENDPOINT_NAME); |
235 | 0 | p.remove(PROPERTY_ENDPOINT_URI); |
236 | 0 | p.remove(PROPERTY_CREATE_CONNECTOR); |
237 | 0 | p.remove(PROPERTY_TRANSFORMERS); |
238 | 0 | return p; |
239 | |
} |
240 | |
|
241 | |
public URI parseServerAuthority() throws URISyntaxException |
242 | |
{ |
243 | 0 | return uri.parseServerAuthority(); |
244 | |
} |
245 | |
|
246 | |
public URI normalize() |
247 | |
{ |
248 | 0 | return uri.normalize(); |
249 | |
} |
250 | |
|
251 | |
public URI resolve(URI uri) |
252 | |
{ |
253 | 0 | return uri.resolve(uri); |
254 | |
} |
255 | |
|
256 | |
public URI resolve(String str) |
257 | |
{ |
258 | 0 | return uri.resolve(str); |
259 | |
} |
260 | |
|
261 | |
public URI relativize(URI uri) |
262 | |
{ |
263 | 0 | return uri.relativize(uri); |
264 | |
} |
265 | |
|
266 | |
public String getScheme() |
267 | |
{ |
268 | 120 | return uri.getScheme(); |
269 | |
} |
270 | |
|
271 | |
public String getFullScheme() |
272 | |
{ |
273 | 964 | return (schemeMetaInfo == null ? uri.getScheme() : schemeMetaInfo + ':' + uri.getScheme()); |
274 | |
|
275 | |
} |
276 | |
|
277 | |
public boolean isAbsolute() |
278 | |
{ |
279 | 0 | return uri.isAbsolute(); |
280 | |
} |
281 | |
|
282 | |
public boolean isOpaque() |
283 | |
{ |
284 | 0 | return uri.isOpaque(); |
285 | |
} |
286 | |
|
287 | |
public String getRawSchemeSpecificPart() |
288 | |
{ |
289 | 0 | return uri.getRawSchemeSpecificPart(); |
290 | |
} |
291 | |
|
292 | |
public String getSchemeSpecificPart() |
293 | |
{ |
294 | 0 | return uri.getSchemeSpecificPart(); |
295 | |
} |
296 | |
|
297 | |
public String getRawAuthority() |
298 | |
{ |
299 | 0 | return uri.getRawAuthority(); |
300 | |
} |
301 | |
|
302 | |
public String getAuthority() |
303 | |
{ |
304 | 0 | return uri.getAuthority(); |
305 | |
} |
306 | |
|
307 | |
public String getRawUserInfo() |
308 | |
{ |
309 | 0 | return uri.getRawUserInfo(); |
310 | |
} |
311 | |
|
312 | |
public String getUserInfo() |
313 | |
{ |
314 | 1494 | return userInfo; |
315 | |
} |
316 | |
|
317 | |
public String getHost() |
318 | |
{ |
319 | 42 | return uri.getHost(); |
320 | |
} |
321 | |
|
322 | |
public int getPort() |
323 | |
{ |
324 | 42 | return uri.getPort(); |
325 | |
} |
326 | |
|
327 | |
public String getRawPath() |
328 | |
{ |
329 | 0 | return uri.getRawPath(); |
330 | |
} |
331 | |
|
332 | |
public String getPath() |
333 | |
{ |
334 | 0 | return uri.getPath(); |
335 | |
} |
336 | |
|
337 | |
public String getRawQuery() |
338 | |
{ |
339 | 0 | return uri.getRawQuery(); |
340 | |
} |
341 | |
|
342 | |
public String getQuery() |
343 | |
{ |
344 | 3924 | return uri.getQuery(); |
345 | |
} |
346 | |
|
347 | |
public String getRawFragment() |
348 | |
{ |
349 | 0 | return uri.getRawFragment(); |
350 | |
} |
351 | |
|
352 | |
public String getFragment() |
353 | |
{ |
354 | 0 | return uri.getFragment(); |
355 | |
} |
356 | |
|
357 | |
public String toString() |
358 | |
{ |
359 | 742 | return uriString; |
360 | |
} |
361 | |
|
362 | |
public String getTransformers() |
363 | |
{ |
364 | 1394 | return transformers; |
365 | |
} |
366 | |
|
367 | |
public int getCreateConnector() |
368 | |
{ |
369 | 994 | return createConnector; |
370 | |
} |
371 | |
|
372 | |
public URI getUri() |
373 | |
{ |
374 | 986 | return uri; |
375 | |
} |
376 | |
|
377 | |
public String getConnectorName() |
378 | |
{ |
379 | 994 | return connectorName; |
380 | |
} |
381 | |
|
382 | |
public String getSchemeMetaInfo() |
383 | |
{ |
384 | 166 | return (schemeMetaInfo == null ? uri.getScheme() : schemeMetaInfo); |
385 | |
} |
386 | |
|
387 | |
public String getResourceInfo() |
388 | |
{ |
389 | 918 | return resourceInfo; |
390 | |
} |
391 | |
|
392 | |
public String getFilterAddress() |
393 | |
{ |
394 | 90 | return filterAddress; |
395 | |
} |
396 | |
|
397 | |
public void setEndpointName(String name) |
398 | |
{ |
399 | 0 | endpointName = name; |
400 | 0 | } |
401 | |
|
402 | |
public String getUsername() |
403 | |
{ |
404 | 2 | if (StringUtils.isNotBlank(userInfo)) |
405 | |
{ |
406 | 2 | int i = userInfo.indexOf(':'); |
407 | 2 | if (i == -1) |
408 | |
{ |
409 | 2 | return userInfo; |
410 | |
} |
411 | |
else |
412 | |
{ |
413 | 0 | return userInfo.substring(0, i); |
414 | |
} |
415 | |
} |
416 | 0 | return null; |
417 | |
} |
418 | |
|
419 | |
public String getResponseTransformers() |
420 | |
{ |
421 | 1370 | return responseTransformers; |
422 | |
} |
423 | |
|
424 | |
public String getPassword() |
425 | |
{ |
426 | 2 | if (StringUtils.isNotBlank(userInfo)) |
427 | |
{ |
428 | 2 | int i = userInfo.indexOf(':'); |
429 | 2 | if (i > -1) |
430 | |
{ |
431 | 0 | return userInfo.substring(i + 1); |
432 | |
} |
433 | |
} |
434 | 2 | return null; |
435 | |
} |
436 | |
|
437 | |
public boolean equals(Object o) |
438 | |
{ |
439 | 12 | if (this == o) |
440 | |
{ |
441 | 0 | return true; |
442 | |
} |
443 | 12 | if (!(o instanceof MuleEndpointURI)) |
444 | |
{ |
445 | 0 | return false; |
446 | |
} |
447 | |
|
448 | 12 | final MuleEndpointURI muleEndpointURI = (MuleEndpointURI) o; |
449 | |
|
450 | 12 | if (createConnector != muleEndpointURI.createConnector) |
451 | |
{ |
452 | 0 | return false; |
453 | |
} |
454 | 12 | if (address != null ? !address.equals(muleEndpointURI.address) : muleEndpointURI.address != null) |
455 | |
{ |
456 | 0 | return false; |
457 | |
} |
458 | 12 | if (connectorName != null |
459 | |
? !connectorName.equals(muleEndpointURI.connectorName) |
460 | |
: muleEndpointURI.connectorName != null) |
461 | |
{ |
462 | 0 | return false; |
463 | |
} |
464 | 12 | if (endpointName != null |
465 | |
? !endpointName.equals(muleEndpointURI.endpointName) |
466 | |
: muleEndpointURI.endpointName != null) |
467 | |
{ |
468 | 0 | return false; |
469 | |
} |
470 | 12 | if (filterAddress != null |
471 | |
? !filterAddress.equals(muleEndpointURI.filterAddress) |
472 | |
: muleEndpointURI.filterAddress != null) |
473 | |
{ |
474 | 0 | return false; |
475 | |
} |
476 | 12 | if (params != null ? !params.equals(muleEndpointURI.params) : muleEndpointURI.params != null) |
477 | |
{ |
478 | 0 | return false; |
479 | |
} |
480 | 12 | if (resourceInfo != null |
481 | |
? !resourceInfo.equals(muleEndpointURI.resourceInfo) |
482 | |
: muleEndpointURI.resourceInfo != null) |
483 | |
{ |
484 | 0 | return false; |
485 | |
} |
486 | 12 | if (schemeMetaInfo != null |
487 | |
? !schemeMetaInfo.equals(muleEndpointURI.schemeMetaInfo) |
488 | |
: muleEndpointURI.schemeMetaInfo != null) |
489 | |
{ |
490 | 0 | return false; |
491 | |
} |
492 | 12 | if (transformers != null |
493 | |
? !transformers.equals(muleEndpointURI.transformers) |
494 | |
: muleEndpointURI.transformers != null) |
495 | |
{ |
496 | 0 | return false; |
497 | |
} |
498 | 12 | if (responseTransformers != null |
499 | |
? !responseTransformers.equals(muleEndpointURI.responseTransformers) |
500 | |
: muleEndpointURI.responseTransformers != null) |
501 | |
{ |
502 | 0 | return false; |
503 | |
} |
504 | 12 | if (uri != null ? !uri.equals(muleEndpointURI.uri) : muleEndpointURI.uri != null) |
505 | |
{ |
506 | 0 | return false; |
507 | |
} |
508 | |
|
509 | 12 | return true; |
510 | |
} |
511 | |
|
512 | |
public int hashCode() |
513 | |
{ |
514 | 40 | int result = (address != null ? address.hashCode() : 0); |
515 | 40 | result = 29 * result + (filterAddress != null ? filterAddress.hashCode() : 0); |
516 | 40 | result = 29 * result + (endpointName != null ? endpointName.hashCode() : 0); |
517 | 40 | result = 29 * result + (connectorName != null ? connectorName.hashCode() : 0); |
518 | 40 | result = 29 * result + (transformers != null ? transformers.hashCode() : 0); |
519 | 40 | result = 29 * result + (responseTransformers != null ? responseTransformers.hashCode() : 0); |
520 | 40 | result = 29 * result + createConnector; |
521 | 40 | result = 29 * result + (params != null ? params.hashCode() : 0); |
522 | 40 | result = 29 * result + (uri != null ? uri.hashCode() : 0); |
523 | 40 | result = 29 * result + (schemeMetaInfo != null ? schemeMetaInfo.hashCode() : 0); |
524 | 40 | return 29 * result + (resourceInfo != null ? resourceInfo.hashCode() : 0); |
525 | |
} |
526 | |
} |