1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.impl; |
12 | |
|
13 | |
import org.mule.MuleException; |
14 | |
import org.mule.MuleManager; |
15 | |
import org.mule.config.i18n.CoreMessages; |
16 | |
import org.mule.impl.endpoint.MuleEndpoint; |
17 | |
import org.mule.impl.endpoint.MuleEndpointURI; |
18 | |
import org.mule.providers.AbstractConnector; |
19 | |
import org.mule.providers.service.TransportFactory; |
20 | |
import org.mule.providers.service.TransportFactoryException; |
21 | |
import org.mule.umo.UMOEvent; |
22 | |
import org.mule.umo.UMOException; |
23 | |
import org.mule.umo.UMOFilter; |
24 | |
import org.mule.umo.UMOMessage; |
25 | |
import org.mule.umo.UMOTransactionConfig; |
26 | |
import org.mule.umo.endpoint.UMOEndpoint; |
27 | |
import org.mule.umo.endpoint.UMOEndpointURI; |
28 | |
import org.mule.umo.endpoint.UMOImmutableEndpoint; |
29 | |
import org.mule.umo.lifecycle.InitialisationException; |
30 | |
import org.mule.umo.provider.DispatchException; |
31 | |
import org.mule.umo.provider.UMOConnector; |
32 | |
import org.mule.umo.security.UMOEndpointSecurityFilter; |
33 | |
import org.mule.umo.transformer.UMOTransformer; |
34 | |
import org.mule.util.ClassUtils; |
35 | |
import org.mule.util.MuleObjectHelper; |
36 | |
import org.mule.util.ObjectNameHelper; |
37 | |
import org.mule.util.StringUtils; |
38 | |
|
39 | |
import java.net.URI; |
40 | |
import java.util.Collections; |
41 | |
import java.util.Map; |
42 | |
import java.util.regex.Matcher; |
43 | |
import java.util.regex.Pattern; |
44 | |
|
45 | |
import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap; |
46 | |
import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean; |
47 | |
import org.apache.commons.logging.Log; |
48 | |
import org.apache.commons.logging.LogFactory; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
public class ImmutableMuleEndpoint implements UMOImmutableEndpoint |
55 | |
{ |
56 | |
|
57 | |
|
58 | |
|
59 | |
private static final long serialVersionUID = -2431378111247771909L; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | 0 | protected static final Log logger = LogFactory.getLog(ImmutableMuleEndpoint.class); |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | 0 | protected UMOConnector connector = null; |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | 0 | protected UMOEndpointURI endpointUri = null; |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | 0 | protected UMOTransformer transformer = null; |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | 0 | protected UMOTransformer responseTransformer = null; |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | 0 | protected String name = null; |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | 0 | protected String type = ENDPOINT_TYPE_SENDER_AND_RECEIVER; |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | 0 | protected Map properties = null; |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | 0 | protected UMOTransactionConfig transactionConfig = null; |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | 0 | protected UMOFilter filter = null; |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | 0 | protected boolean deleteUnacceptedMessages = false; |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | 0 | protected AtomicBoolean initialised = new AtomicBoolean(false); |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | 0 | protected UMOEndpointSecurityFilter securityFilter = null; |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | 0 | protected Boolean synchronous = null; |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | 0 | protected Boolean remoteSync = null; |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | 0 | protected Integer remoteSyncTimeout = null; |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | 0 | protected boolean streaming = false; |
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | 0 | protected String initialState = INITIAL_STATE_STARTED; |
159 | |
|
160 | 0 | protected String endpointEncoding = null; |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | 0 | protected int createConnector = TransportFactory.GET_OR_CREATE_CONNECTOR; |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
private ImmutableMuleEndpoint() |
171 | |
{ |
172 | 0 | super(); |
173 | 0 | } |
174 | |
|
175 | |
public ImmutableMuleEndpoint(String name, |
176 | |
UMOEndpointURI endpointUri, |
177 | |
UMOConnector connector, |
178 | |
UMOTransformer transformer, |
179 | |
String type, |
180 | |
int createConnector, |
181 | |
String endpointEncoding, |
182 | |
Map props) |
183 | 0 | { |
184 | 0 | this.name = name; |
185 | 0 | this.connector = connector; |
186 | 0 | this.createConnector = createConnector; |
187 | 0 | this.endpointEncoding = endpointEncoding; |
188 | 0 | this.type = type; |
189 | |
|
190 | 0 | if (endpointUri != null) |
191 | |
{ |
192 | 0 | this.endpointUri = new MuleEndpointURI(endpointUri); |
193 | |
} |
194 | |
|
195 | 0 | if (transformer != null) |
196 | |
{ |
197 | 0 | transformer.setEndpoint(this); |
198 | 0 | this.transformer = transformer; |
199 | |
} |
200 | |
|
201 | 0 | this.properties = new ConcurrentHashMap(); |
202 | |
|
203 | 0 | if (props != null) |
204 | |
{ |
205 | 0 | this.properties.putAll(props); |
206 | |
} |
207 | |
|
208 | 0 | if (endpointUri != null) |
209 | |
{ |
210 | 0 | properties.putAll(endpointUri.getParams()); |
211 | |
} |
212 | |
|
213 | |
|
214 | |
|
215 | 0 | if (!(this instanceof MuleEndpoint)) |
216 | |
{ |
217 | 0 | this.properties = Collections.unmodifiableMap(this.properties); |
218 | |
} |
219 | |
|
220 | |
|
221 | 0 | transactionConfig = new MuleTransactionConfig(); |
222 | 0 | } |
223 | |
|
224 | |
public ImmutableMuleEndpoint(UMOImmutableEndpoint source) |
225 | |
{ |
226 | 0 | this(); |
227 | 0 | this.initFromDescriptor(source); |
228 | 0 | } |
229 | |
|
230 | |
public ImmutableMuleEndpoint(String endpointName, boolean receiver) throws UMOException |
231 | |
{ |
232 | 0 | this(); |
233 | 0 | String type = (receiver ? UMOEndpoint.ENDPOINT_TYPE_RECEIVER : UMOEndpoint.ENDPOINT_TYPE_SENDER); |
234 | 0 | UMOEndpoint p = getOrCreateEndpointForUri(new MuleEndpointURI(endpointName), type); |
235 | 0 | this.initFromDescriptor(p); |
236 | 0 | } |
237 | |
|
238 | |
protected void initFromDescriptor(UMOImmutableEndpoint source) |
239 | |
{ |
240 | 0 | if (this.name == null) |
241 | |
{ |
242 | 0 | this.name = source.getName(); |
243 | |
} |
244 | |
|
245 | 0 | if (this.endpointUri == null && source.getEndpointURI() != null) |
246 | |
{ |
247 | 0 | this.endpointUri = new MuleEndpointURI(source.getEndpointURI()); |
248 | |
} |
249 | |
|
250 | 0 | if (this.endpointEncoding == null) |
251 | |
{ |
252 | 0 | this.endpointEncoding = source.getEncoding(); |
253 | |
} |
254 | |
|
255 | 0 | if (this.connector == null) |
256 | |
{ |
257 | 0 | this.connector = source.getConnector(); |
258 | |
} |
259 | |
|
260 | 0 | if (this.transformer == null) |
261 | |
{ |
262 | 0 | this.transformer = source.getTransformer(); |
263 | |
} |
264 | |
|
265 | 0 | if (this.transformer != null) |
266 | |
{ |
267 | 0 | this.transformer.setEndpoint(this); |
268 | |
} |
269 | |
|
270 | 0 | if (this.responseTransformer == null) |
271 | |
{ |
272 | 0 | this.responseTransformer = source.getResponseTransformer(); |
273 | |
} |
274 | |
|
275 | 0 | if (responseTransformer != null) |
276 | |
{ |
277 | 0 | this.responseTransformer.setEndpoint(this); |
278 | |
} |
279 | |
|
280 | 0 | this.properties = new ConcurrentHashMap(); |
281 | |
|
282 | 0 | if (source.getProperties() != null) |
283 | |
{ |
284 | 0 | this.properties.putAll(source.getProperties()); |
285 | |
} |
286 | |
|
287 | 0 | if (endpointUri != null && endpointUri.getParams() != null) |
288 | |
{ |
289 | 0 | this.properties.putAll(endpointUri.getParams()); |
290 | |
} |
291 | |
|
292 | |
|
293 | |
|
294 | 0 | if (!(this instanceof MuleEndpoint)) |
295 | |
{ |
296 | 0 | this.properties = Collections.unmodifiableMap(this.properties); |
297 | |
} |
298 | |
|
299 | 0 | this.type = source.getType(); |
300 | 0 | this.transactionConfig = source.getTransactionConfig(); |
301 | 0 | this.deleteUnacceptedMessages = source.isDeleteUnacceptedMessages(); |
302 | 0 | this.initialState = source.getInitialState(); |
303 | |
|
304 | 0 | remoteSyncTimeout = new Integer(source.getRemoteSyncTimeout()); |
305 | 0 | remoteSync = Boolean.valueOf(source.isRemoteSync()); |
306 | |
|
307 | 0 | filter = source.getFilter(); |
308 | 0 | securityFilter = source.getSecurityFilter(); |
309 | 0 | } |
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
public UMOEndpointURI getEndpointURI() |
317 | |
{ |
318 | 0 | return endpointUri; |
319 | |
} |
320 | |
|
321 | |
public String getEncoding() |
322 | |
{ |
323 | 0 | return endpointEncoding; |
324 | |
} |
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
public String getType() |
332 | |
{ |
333 | 0 | return type; |
334 | |
} |
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
public UMOConnector getConnector() |
342 | |
{ |
343 | 0 | return connector; |
344 | |
} |
345 | |
|
346 | |
|
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
public String getName() |
352 | |
{ |
353 | 0 | return name; |
354 | |
} |
355 | |
|
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
public UMOTransformer getTransformer() |
362 | |
{ |
363 | 0 | return transformer; |
364 | |
} |
365 | |
|
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | |
|
371 | |
public Map getProperties() |
372 | |
{ |
373 | 0 | return properties; |
374 | |
} |
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
public Object clone() |
385 | |
{ |
386 | 0 | UMOEndpoint clone = new MuleEndpoint(name, endpointUri, connector, transformer, type, |
387 | |
createConnector, endpointEncoding, properties); |
388 | |
|
389 | 0 | clone.setTransactionConfig(transactionConfig); |
390 | 0 | clone.setFilter(filter); |
391 | 0 | clone.setSecurityFilter(securityFilter); |
392 | |
|
393 | 0 | if (remoteSync != null) |
394 | |
{ |
395 | 0 | clone.setRemoteSync(isRemoteSync()); |
396 | |
} |
397 | 0 | if (remoteSyncTimeout != null) |
398 | |
{ |
399 | 0 | clone.setRemoteSyncTimeout(getRemoteSyncTimeout()); |
400 | |
} |
401 | |
|
402 | 0 | if (synchronous != null) |
403 | |
{ |
404 | 0 | clone.setSynchronous(synchronous.booleanValue()); |
405 | |
} |
406 | |
|
407 | 0 | clone.setDeleteUnacceptedMessages(deleteUnacceptedMessages); |
408 | |
|
409 | 0 | clone.setInitialState(initialState); |
410 | 0 | if (initialised.get()) |
411 | |
{ |
412 | |
try |
413 | |
{ |
414 | 0 | clone.initialise(); |
415 | |
} |
416 | 0 | catch (InitialisationException e) |
417 | |
{ |
418 | |
|
419 | |
|
420 | 0 | logger.error(e.getMessage(), e); |
421 | 0 | } |
422 | |
} |
423 | |
|
424 | 0 | return clone; |
425 | |
} |
426 | |
|
427 | |
|
428 | |
|
429 | |
|
430 | |
|
431 | |
|
432 | |
public boolean isReadOnly() |
433 | |
{ |
434 | 0 | return true; |
435 | |
} |
436 | |
|
437 | |
public String toString() |
438 | |
{ |
439 | |
|
440 | |
|
441 | 0 | String sanitizedEndPointUri = null; |
442 | 0 | URI uri = null; |
443 | 0 | if (endpointUri != null) |
444 | |
{ |
445 | 0 | sanitizedEndPointUri = endpointUri.toString(); |
446 | 0 | uri = endpointUri.getUri(); |
447 | |
} |
448 | |
|
449 | |
|
450 | |
|
451 | |
|
452 | 0 | if (uri != null && (uri.getRawUserInfo() != null) && (uri.getScheme() != null) |
453 | |
&& (uri.getHost() != null) && (uri.getRawPath() != null)) |
454 | |
{ |
455 | |
|
456 | 0 | Pattern sanitizerPattern = Pattern.compile("(.*):.*"); |
457 | 0 | Matcher sanitizerMatcher = sanitizerPattern.matcher(uri.getRawUserInfo()); |
458 | 0 | if (sanitizerMatcher.matches()) |
459 | |
{ |
460 | 0 | sanitizedEndPointUri = new StringBuffer(uri.getScheme()) |
461 | |
.append("://").append(sanitizerMatcher.group(1)) |
462 | |
.append(":<password>").append("@") |
463 | |
.append(uri.getHost()).append(uri.getRawPath()).toString(); |
464 | |
} |
465 | 0 | if ( uri.getRawQuery() != null) |
466 | |
{ |
467 | 0 | sanitizedEndPointUri = sanitizedEndPointUri + "?" + uri.getRawQuery(); |
468 | |
} |
469 | |
|
470 | |
} |
471 | |
|
472 | 0 | return ClassUtils.getClassName(this.getClass()) + "{endpointUri=" + sanitizedEndPointUri |
473 | |
+ ", connector=" + connector + ", transformer=" + transformer + ", name='" + name + "'" |
474 | |
+ ", type='" + type + "'" + ", properties=" + properties + ", transactionConfig=" |
475 | |
+ transactionConfig + ", filter=" + filter + ", deleteUnacceptedMessages=" |
476 | |
+ deleteUnacceptedMessages + ", initialised=" + initialised + ", securityFilter=" |
477 | |
+ securityFilter + ", synchronous=" + synchronous + ", initialState=" + initialState |
478 | |
+ ", createConnector=" + createConnector + ", remoteSync=" + remoteSync |
479 | |
+ ", remoteSyncTimeout=" + remoteSyncTimeout + ", endpointEncoding=" + endpointEncoding + "}"; |
480 | |
} |
481 | |
|
482 | |
|
483 | |
|
484 | |
|
485 | |
|
486 | |
|
487 | |
public String getProtocol() |
488 | |
{ |
489 | 0 | return connector.getProtocol(); |
490 | |
} |
491 | |
|
492 | |
|
493 | |
|
494 | |
|
495 | |
|
496 | |
|
497 | |
public boolean canReceive() |
498 | |
{ |
499 | 0 | return (getType().equals(ENDPOINT_TYPE_RECEIVER) || getType().equals( |
500 | |
ENDPOINT_TYPE_SENDER_AND_RECEIVER)); |
501 | |
} |
502 | |
|
503 | |
|
504 | |
|
505 | |
|
506 | |
|
507 | |
|
508 | |
public boolean canSend() |
509 | |
{ |
510 | 0 | return (getType().equals(ENDPOINT_TYPE_SENDER) || getType().equals(ENDPOINT_TYPE_SENDER_AND_RECEIVER)); |
511 | |
} |
512 | |
|
513 | |
|
514 | |
|
515 | |
|
516 | |
|
517 | |
|
518 | |
public UMOTransactionConfig getTransactionConfig() |
519 | |
{ |
520 | 0 | return transactionConfig; |
521 | |
} |
522 | |
|
523 | |
public boolean equals(Object o) |
524 | |
{ |
525 | 0 | if (this == o) |
526 | |
{ |
527 | 0 | return true; |
528 | |
} |
529 | 0 | if (!(o instanceof ImmutableMuleEndpoint)) |
530 | |
{ |
531 | 0 | return false; |
532 | |
} |
533 | |
|
534 | 0 | final ImmutableMuleEndpoint immutableMuleProviderDescriptor = (ImmutableMuleEndpoint) o; |
535 | |
|
536 | 0 | if (!connector.getName().equals(immutableMuleProviderDescriptor.connector.getName())) |
537 | |
{ |
538 | 0 | return false; |
539 | |
} |
540 | 0 | if (endpointUri != null && immutableMuleProviderDescriptor.endpointUri != null |
541 | |
? !endpointUri.getAddress().equals( |
542 | |
immutableMuleProviderDescriptor.endpointUri.getAddress()) |
543 | |
: immutableMuleProviderDescriptor.endpointUri != null) |
544 | |
{ |
545 | 0 | return false; |
546 | |
} |
547 | 0 | if (!name.equals(immutableMuleProviderDescriptor.name)) |
548 | |
{ |
549 | 0 | return false; |
550 | |
} |
551 | |
|
552 | |
|
553 | |
|
554 | |
|
555 | |
|
556 | |
|
557 | |
|
558 | 0 | if (!type.equals(immutableMuleProviderDescriptor.type)) |
559 | |
{ |
560 | 0 | return false; |
561 | |
} |
562 | |
|
563 | 0 | return true; |
564 | |
} |
565 | |
|
566 | |
public int hashCode() |
567 | |
{ |
568 | 0 | int result = appendHash(0, connector); |
569 | 0 | result = appendHash(result, endpointUri); |
570 | |
|
571 | |
|
572 | 0 | result = appendHash(result, name); |
573 | 0 | result = appendHash(result, type); |
574 | |
|
575 | |
|
576 | |
|
577 | |
|
578 | 0 | return result; |
579 | |
} |
580 | |
|
581 | |
private int appendHash(int hash, Object component) |
582 | |
{ |
583 | 0 | int delta = component != null ? component.hashCode() : 0; |
584 | |
|
585 | |
|
586 | |
|
587 | |
|
588 | 0 | return 29 * hash + delta; |
589 | |
} |
590 | |
|
591 | |
public UMOFilter getFilter() |
592 | |
{ |
593 | 0 | return filter; |
594 | |
} |
595 | |
|
596 | |
public static UMOEndpoint createEndpointFromUri(UMOEndpointURI uri, String type) throws UMOException |
597 | |
{ |
598 | 0 | return TransportFactory.createEndpoint(uri, type); |
599 | |
} |
600 | |
|
601 | |
public static UMOEndpoint getEndpointFromUri(String uri) |
602 | |
{ |
603 | 0 | UMOEndpoint endpoint = null; |
604 | 0 | if (uri != null) |
605 | |
{ |
606 | 0 | String endpointString = MuleManager.getInstance().lookupEndpointIdentifier(uri, uri); |
607 | 0 | endpoint = MuleManager.getInstance().lookupEndpoint(endpointString); |
608 | |
} |
609 | 0 | return endpoint; |
610 | |
} |
611 | |
|
612 | |
public static UMOEndpoint getEndpointFromUri(UMOEndpointURI uri) throws UMOException |
613 | |
{ |
614 | 0 | String endpointName = uri.getEndpointName(); |
615 | 0 | if (endpointName != null) |
616 | |
{ |
617 | 0 | String endpointString = MuleManager.getInstance().lookupEndpointIdentifier(endpointName, |
618 | |
endpointName); |
619 | 0 | UMOEndpoint endpoint = MuleManager.getInstance().lookupEndpoint(endpointString); |
620 | 0 | if (endpoint != null) |
621 | |
{ |
622 | 0 | if (StringUtils.isNotEmpty(uri.getAddress())) |
623 | |
{ |
624 | 0 | endpoint.setEndpointURI(uri); |
625 | |
} |
626 | |
} |
627 | 0 | return endpoint; |
628 | |
} |
629 | |
|
630 | 0 | return null; |
631 | |
} |
632 | |
|
633 | |
public static UMOEndpoint getOrCreateEndpointForUri(String uriIdentifier, String type) |
634 | |
throws UMOException |
635 | |
{ |
636 | 0 | UMOEndpoint endpoint = getEndpointFromUri(uriIdentifier); |
637 | 0 | if (endpoint == null) |
638 | |
{ |
639 | 0 | endpoint = createEndpointFromUri(new MuleEndpointURI(uriIdentifier), type); |
640 | |
} |
641 | |
else |
642 | |
{ |
643 | 0 | if (endpoint.getType().equals(UMOEndpoint.ENDPOINT_TYPE_SENDER_AND_RECEIVER)) |
644 | |
{ |
645 | 0 | endpoint.setType(type); |
646 | |
} |
647 | 0 | else if (!endpoint.getType().equals(type)) |
648 | |
{ |
649 | 0 | throw new IllegalArgumentException("Endpoint matching: " + uriIdentifier |
650 | |
+ " is not of type: " + type + ". It is of type: " |
651 | |
+ endpoint.getType()); |
652 | |
|
653 | |
} |
654 | |
} |
655 | 0 | return endpoint; |
656 | |
} |
657 | |
|
658 | |
public static UMOEndpoint getOrCreateEndpointForUri(UMOEndpointURI uri, String type) throws UMOException |
659 | |
{ |
660 | 0 | UMOEndpoint endpoint = getEndpointFromUri(uri); |
661 | 0 | if (endpoint == null) |
662 | |
{ |
663 | 0 | endpoint = createEndpointFromUri(uri, type); |
664 | |
} |
665 | 0 | return endpoint; |
666 | |
} |
667 | |
|
668 | |
public boolean isDeleteUnacceptedMessages() |
669 | |
{ |
670 | 0 | return deleteUnacceptedMessages; |
671 | |
} |
672 | |
|
673 | |
public void initialise() throws InitialisationException |
674 | |
{ |
675 | 0 | if (initialised.get()) |
676 | |
{ |
677 | 0 | logger.debug("Already initialised: " + toString()); |
678 | 0 | return; |
679 | |
} |
680 | 0 | if (connector == null) |
681 | |
{ |
682 | 0 | if (endpointUri.getConnectorName() != null) |
683 | |
{ |
684 | 0 | connector = MuleManager.getInstance().lookupConnector(endpointUri.getConnectorName()); |
685 | 0 | if (connector == null) |
686 | |
{ |
687 | 0 | throw new IllegalArgumentException("Connector not found: " |
688 | |
+ endpointUri.getConnectorName()); |
689 | |
} |
690 | |
} |
691 | |
else |
692 | |
{ |
693 | |
try |
694 | |
{ |
695 | 0 | connector = TransportFactory.getOrCreateConnectorByProtocol(this); |
696 | 0 | if (connector == null) |
697 | |
{ |
698 | 0 | throw new InitialisationException( |
699 | |
CoreMessages.connectorWithProtocolNotRegistered(endpointUri.getScheme()), this); |
700 | |
} |
701 | |
} |
702 | 0 | catch (TransportFactoryException e) |
703 | |
{ |
704 | 0 | throw new InitialisationException( |
705 | |
CoreMessages.failedToCreateConnectorFromUri(endpointUri), e, this); |
706 | 0 | } |
707 | |
} |
708 | |
|
709 | 0 | if (endpointUri.getEndpointName() != null && name == null) |
710 | |
{ |
711 | 0 | name = endpointUri.getEndpointName(); |
712 | |
} |
713 | |
} |
714 | 0 | name = ObjectNameHelper.getEndpointName(this); |
715 | |
|
716 | 0 | String sync = endpointUri.getParams().getProperty("synchronous", null); |
717 | 0 | if (sync != null) |
718 | |
{ |
719 | 0 | synchronous = Boolean.valueOf(sync); |
720 | |
} |
721 | 0 | if (properties != null && endpointUri.getParams() != null) |
722 | |
{ |
723 | 0 | properties.putAll(endpointUri.getParams()); |
724 | |
} |
725 | |
|
726 | 0 | if (endpointUri.getTransformers() != null) |
727 | |
{ |
728 | |
try |
729 | |
{ |
730 | 0 | transformer = MuleObjectHelper.getTransformer(endpointUri.getTransformers(), ","); |
731 | |
} |
732 | 0 | catch (MuleException e) |
733 | |
{ |
734 | 0 | throw new InitialisationException(e, this); |
735 | 0 | } |
736 | |
} |
737 | |
|
738 | 0 | if (transformer == null) |
739 | |
{ |
740 | 0 | if (connector instanceof AbstractConnector) |
741 | |
{ |
742 | 0 | if (UMOEndpoint.ENDPOINT_TYPE_SENDER.equals(type)) |
743 | |
{ |
744 | 0 | transformer = ((AbstractConnector) connector).getDefaultOutboundTransformer(); |
745 | |
} |
746 | 0 | else if (UMOEndpoint.ENDPOINT_TYPE_SENDER_AND_RECEIVER.equals(type)) |
747 | |
{ |
748 | 0 | transformer = ((AbstractConnector) connector).getDefaultOutboundTransformer(); |
749 | 0 | responseTransformer = ((AbstractConnector) connector).getDefaultInboundTransformer(); |
750 | |
} |
751 | |
else |
752 | |
{ |
753 | 0 | transformer = ((AbstractConnector) connector).getDefaultInboundTransformer(); |
754 | |
} |
755 | |
} |
756 | |
} |
757 | 0 | if (transformer != null) |
758 | |
{ |
759 | 0 | transformer.setEndpoint(this); |
760 | |
} |
761 | |
|
762 | 0 | if (endpointUri.getResponseTransformers() != null) |
763 | |
{ |
764 | |
try |
765 | |
{ |
766 | 0 | responseTransformer = |
767 | |
MuleObjectHelper.getTransformer(endpointUri.getResponseTransformers(), ","); |
768 | |
} |
769 | 0 | catch (MuleException e) |
770 | |
{ |
771 | 0 | throw new InitialisationException(e, this); |
772 | 0 | } |
773 | |
} |
774 | 0 | if (responseTransformer == null) |
775 | |
{ |
776 | 0 | if (connector instanceof AbstractConnector) |
777 | |
{ |
778 | 0 | responseTransformer = ((AbstractConnector) connector).getDefaultResponseTransformer(); |
779 | |
} |
780 | |
} |
781 | 0 | if (responseTransformer != null) |
782 | |
{ |
783 | 0 | responseTransformer.setEndpoint(this); |
784 | |
} |
785 | |
|
786 | 0 | if (securityFilter != null) |
787 | |
{ |
788 | 0 | securityFilter.setEndpoint(this); |
789 | 0 | securityFilter.initialise(); |
790 | |
} |
791 | |
|
792 | |
|
793 | 0 | String rs = (String) endpointUri.getParams().remove("remoteSync"); |
794 | 0 | if (rs != null) |
795 | |
{ |
796 | 0 | remoteSync = Boolean.valueOf(rs); |
797 | |
} |
798 | |
|
799 | 0 | String rsTimeout = (String) endpointUri.getParams().remove("remoteSyncTimeout"); |
800 | 0 | if (rsTimeout != null) |
801 | |
{ |
802 | 0 | remoteSyncTimeout = Integer.valueOf(rsTimeout); |
803 | |
} |
804 | |
|
805 | 0 | initialised.set(true); |
806 | 0 | } |
807 | |
|
808 | |
|
809 | |
|
810 | |
|
811 | |
|
812 | |
|
813 | |
|
814 | |
|
815 | |
|
816 | |
public UMOEndpointSecurityFilter getSecurityFilter() |
817 | |
{ |
818 | 0 | return securityFilter; |
819 | |
} |
820 | |
|
821 | |
|
822 | |
|
823 | |
|
824 | |
|
825 | |
|
826 | |
|
827 | |
|
828 | |
|
829 | |
public boolean isSynchronous() |
830 | |
{ |
831 | 0 | if (synchronous == null) |
832 | |
{ |
833 | 0 | return MuleManager.getConfiguration().isSynchronous(); |
834 | |
} |
835 | 0 | return synchronous.booleanValue(); |
836 | |
} |
837 | |
|
838 | |
public boolean isSynchronousSet() |
839 | |
{ |
840 | 0 | return (synchronous != null); |
841 | |
} |
842 | |
|
843 | |
public int getCreateConnector() |
844 | |
{ |
845 | 0 | return createConnector; |
846 | |
} |
847 | |
|
848 | |
|
849 | |
|
850 | |
|
851 | |
|
852 | |
|
853 | |
|
854 | |
|
855 | |
|
856 | |
public boolean isRemoteSync() |
857 | |
{ |
858 | 0 | if (remoteSync == null) |
859 | |
{ |
860 | 0 | if (connector == null || connector.isRemoteSyncEnabled()) |
861 | |
{ |
862 | 0 | remoteSync = Boolean.valueOf(MuleManager.getConfiguration().isRemoteSync()); |
863 | |
} |
864 | |
else |
865 | |
{ |
866 | 0 | remoteSync = Boolean.FALSE; |
867 | |
} |
868 | |
} |
869 | 0 | return remoteSync.booleanValue(); |
870 | |
} |
871 | |
|
872 | |
|
873 | |
|
874 | |
|
875 | |
|
876 | |
|
877 | |
public int getRemoteSyncTimeout() |
878 | |
{ |
879 | 0 | if (remoteSyncTimeout == null) |
880 | |
{ |
881 | 0 | remoteSyncTimeout = new Integer(MuleManager.getConfiguration().getSynchronousEventTimeout()); |
882 | |
} |
883 | 0 | return remoteSyncTimeout.intValue(); |
884 | |
} |
885 | |
|
886 | |
|
887 | |
|
888 | |
|
889 | |
|
890 | |
|
891 | |
|
892 | |
public String getInitialState() |
893 | |
{ |
894 | 0 | return initialState; |
895 | |
} |
896 | |
|
897 | |
public UMOTransformer getResponseTransformer() |
898 | |
{ |
899 | 0 | return responseTransformer; |
900 | |
} |
901 | |
|
902 | |
|
903 | |
|
904 | |
|
905 | |
|
906 | |
|
907 | |
public boolean isStreaming() |
908 | |
{ |
909 | 0 | return streaming; |
910 | |
} |
911 | |
|
912 | |
public Object getProperty(Object key) |
913 | |
{ |
914 | 0 | Object value = properties.get(key); |
915 | 0 | if (value == null) |
916 | |
{ |
917 | 0 | value = endpointUri.getParams().get(key); |
918 | |
} |
919 | 0 | return value; |
920 | |
} |
921 | |
|
922 | |
|
923 | |
|
924 | |
|
925 | |
public void dispatch(UMOEvent event) throws DispatchException |
926 | |
{ |
927 | 0 | if (connector != null) |
928 | |
{ |
929 | 0 | connector.dispatch(this, event); |
930 | |
} |
931 | |
else |
932 | |
{ |
933 | |
|
934 | 0 | throw new IllegalStateException("The connector on the endpoint: " + toString() + "is null. Please contact dev@mule.codehaus.org"); |
935 | |
} |
936 | 0 | } |
937 | |
|
938 | |
public UMOMessage receive(long timeout) throws Exception |
939 | |
{ |
940 | 0 | if (connector != null) |
941 | |
{ |
942 | 0 | return connector.receive(this, timeout); |
943 | |
} |
944 | |
else |
945 | |
{ |
946 | |
|
947 | 0 | throw new IllegalStateException("The connector on the endpoint: " + toString() + "is null. Please contact dev@mule.codehaus.org"); |
948 | |
} |
949 | |
} |
950 | |
|
951 | |
public UMOMessage send(UMOEvent event) throws DispatchException |
952 | |
{ |
953 | 0 | if (connector != null) |
954 | |
{ |
955 | 0 | return connector.send(this, event); |
956 | |
} |
957 | |
else |
958 | |
{ |
959 | |
|
960 | 0 | throw new IllegalStateException("The connector on the endpoint: " + toString() + "is null. Please contact dev@mule.codehaus.org"); |
961 | |
} |
962 | |
} |
963 | |
|
964 | |
} |