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