View Javadoc

1   /*
2    * $Id: ImmutableMuleEndpoint.java 11728 2008-05-13 07:31:11Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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   * <code>ImmutableMuleEndpoint</code> describes a Provider in the Mule Server. A
52   * endpoint is a grouping of an endpoint, an endpointUri and a transformer.
53   */
54  public class ImmutableMuleEndpoint implements UMOImmutableEndpoint
55  {
56      /**
57       * logger used by this class
58       */
59      protected static final Log logger = LogFactory.getLog(ImmutableMuleEndpoint.class);
60  
61      /**
62       * The endpoint used to communicate with the external system
63       */
64      protected UMOConnector connector = null;
65  
66      /**
67       * The endpointUri on which to send or receive information
68       */
69      protected UMOEndpointURI endpointUri = null;
70  
71      /**
72       * The transformer used to transform the incoming or outgoing data
73       */
74      protected UMOTransformer transformer = null;
75  
76      /**
77       * The transformer used to transform the incoming or outgoing data
78       */
79      protected UMOTransformer responseTransformer = null;
80  
81      /**
82       * The name for the endpoint
83       */
84      protected String name = null;
85  
86      /**
87       * Determines whether the endpoint is a receiver or sender or both
88       */
89      protected String type = ENDPOINT_TYPE_SENDER_AND_RECEIVER;
90  
91      /**
92       * Any additional properties for the endpoint
93       */
94      protected Map properties = null;
95  
96      /**
97       * The transaction configuration for this endpoint
98       */
99      protected UMOTransactionConfig transactionConfig = null;
100 
101     /**
102      * event filter for this endpoint
103      */
104     protected UMOFilter filter = null;
105 
106     /**
107      * determines whether unaccepted filtered events should be removed from the
108      * source. If they are not removed its up to the Message receiver to handle
109      * recieving the same message again
110      */
111     protected boolean deleteUnacceptedMessages = false;
112 
113     /**
114      * has this endpoint been initialised
115      */
116     protected AtomicBoolean initialised = new AtomicBoolean(false);
117 
118     /**
119      * The security filter to apply to this endpoint
120      */
121     protected UMOEndpointSecurityFilter securityFilter = null;
122 
123     /**
124      * whether events received by this endpoint should execute in a single thread
125      */
126     protected Boolean synchronous = null;
127 
128     /**
129      * Determines whether a synchronous call should block to obtain a response from a
130      * remote server (if the transport supports it). For example for Jms endpoints,
131      * setting remote sync will cause a temporary destination to be set up as a
132      * replyTo destination and will send the message a wait for a response on the
133      * replyTo destination. If the JMSReplyTo is already set on the message that
134      * destination will be used instead.
135      */
136     protected Boolean remoteSync = null;
137 
138     /**
139      * How long to block when performing a remote synchronisation to a remote host.
140      * This property is optional and will be set to the default Synchonous Event time
141      * out value if not set
142      */
143     protected Integer remoteSyncTimeout = null;
144 
145     /**
146      * Determines whether the endpoint should deal with requests as streams
147      */
148     protected boolean streaming = false;
149 
150     /**
151      * The state that the endpoint is initialised in such as started or stopped
152      */
153     protected String initialState = INITIAL_STATE_STARTED;
154 
155     protected String endpointEncoding = null;
156 
157     /**
158      * determines if a new connector should be created for this endpoint
159      */
160     protected int createConnector = TransportFactory.GET_OR_CREATE_CONNECTOR;
161 
162     /**
163      * Default constructor.
164      */
165     private ImmutableMuleEndpoint()
166     {
167         super();
168     }
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     {
179         this.name = name;
180         this.connector = connector;
181         this.createConnector = createConnector;
182         this.endpointEncoding = endpointEncoding;
183         this.type = type;
184 
185         if (endpointUri != null)
186         {
187             this.endpointUri = new MuleEndpointURI(endpointUri);
188         }
189 
190         if (transformer != null)
191         {
192             transformer.setEndpoint(this);
193             this.transformer = transformer;
194         }
195 
196         this.properties = new ConcurrentHashMap();
197 
198         if (props != null)
199         {
200             this.properties.putAll(props);
201         }
202 
203         if (endpointUri != null)
204         {
205             properties.putAll(endpointUri.getParams());
206         }
207 
208         // seal the properties if we are immutable to avoid
209         // write-through aliasing problems with the exposed Map
210         if (!(this instanceof MuleEndpoint))
211         {
212             this.properties = Collections.unmodifiableMap(this.properties);
213         }
214 
215         // Create a default transaction config
216         transactionConfig = new MuleTransactionConfig();
217     }
218 
219     public ImmutableMuleEndpoint(UMOImmutableEndpoint source)
220     {
221         this();
222         this.initFromDescriptor(source);
223     }
224 
225     public ImmutableMuleEndpoint(String endpointName, boolean receiver) throws UMOException
226     {
227         this();
228         String type = (receiver ? UMOEndpoint.ENDPOINT_TYPE_RECEIVER : UMOEndpoint.ENDPOINT_TYPE_SENDER);
229         UMOEndpoint p = getOrCreateEndpointForUri(new MuleEndpointURI(endpointName), type);
230         this.initFromDescriptor(p);
231     }
232 
233     protected void initFromDescriptor(UMOImmutableEndpoint source)
234     {
235         if (this.name == null)
236         {
237             this.name = source.getName();
238         }
239 
240         if (this.endpointUri == null && source.getEndpointURI() != null)
241         {
242             this.endpointUri = new MuleEndpointURI(source.getEndpointURI());
243         }
244 
245         if (this.endpointEncoding == null)
246         {
247             this.endpointEncoding = source.getEncoding();
248         }
249 
250         if (this.connector == null)
251         {
252             this.connector = source.getConnector();
253         }
254 
255         if (this.transformer == null)
256         {
257             this.transformer = source.getTransformer();
258         }
259 
260         if (this.transformer != null)
261         {
262             this.transformer.setEndpoint(this);
263         }
264 
265         if (this.responseTransformer == null)
266         {
267             this.responseTransformer = source.getResponseTransformer();
268         }
269 
270         if (responseTransformer != null)
271         {
272             this.responseTransformer.setEndpoint(this);
273         }
274 
275         this.properties = new ConcurrentHashMap();
276 
277         if (source.getProperties() != null)
278         {
279             this.properties.putAll(source.getProperties());
280         }
281 
282         if (endpointUri != null && endpointUri.getParams() != null)
283         {
284             this.properties.putAll(endpointUri.getParams());
285         }
286 
287         // seal the properties if we are immutable to avoid
288         // write-through aliasing problems with the exposed Map
289         if (!(this instanceof MuleEndpoint))
290         {
291             this.properties = Collections.unmodifiableMap(this.properties);
292         }
293 
294         this.type = source.getType();
295         this.transactionConfig = source.getTransactionConfig();
296         this.deleteUnacceptedMessages = source.isDeleteUnacceptedMessages();
297         this.initialState = source.getInitialState();
298 
299         remoteSyncTimeout = new Integer(source.getRemoteSyncTimeout());
300         remoteSync = Boolean.valueOf(source.isRemoteSync());
301 
302         filter = source.getFilter();
303         securityFilter = source.getSecurityFilter();
304     }
305 
306     /*
307      * (non-Javadoc)
308      *
309      * @see org.mule.umo.endpoint.UMOEndpoint#getEndpointURI()
310      */
311     public UMOEndpointURI getEndpointURI()
312     {
313         return endpointUri;
314     }
315 
316     public String getEncoding()
317     {
318         return endpointEncoding;
319     }
320 
321     /*
322      * (non-Javadoc)
323      *
324      * @see org.mule.umo.endpoint.UMOImmutableEndpoint#getType()
325      */
326     public String getType()
327     {
328         return type;
329     }
330 
331     /*
332      * (non-Javadoc)
333      *
334      * @see org.mule.umo.endpoint.UMOImmutableEndpoint#getConnectorName()
335      */
336     public UMOConnector getConnector()
337     {
338         return connector;
339     }
340 
341     /*
342      * (non-Javadoc)
343      *
344      * @see org.mule.umo.endpoint.UMOImmutableEndpoint#getName()
345      */
346     public String getName()
347     {
348         return name;
349     }
350 
351     /*
352      * (non-Javadoc)
353      *
354      * @see org.mule.umo.endpoint.UMOEndpoint#getTransformer()
355      */
356     public UMOTransformer getTransformer()
357     {
358         return transformer;
359     }
360 
361     /*
362      * (non-Javadoc)
363      *
364      * @see org.mule.umo.endpoint.UMOImmutableEndpoint#getParams()
365      */
366     public Map getProperties()
367     {
368         return properties;
369     }
370 
371     /*
372      * (non-Javadoc)
373      *
374      * @see java.lang.Object#clone()
375      */
376     // TODO this is the 'old' implementation of the clone() method which returns
377     // a MUTABLE endpoint! We need to clarify what endpoint mutability and
378     // cloning actually means
379     public Object clone()
380     {
381         UMOEndpoint clone = new MuleEndpoint(name, endpointUri, connector, transformer, type,
382             createConnector, endpointEncoding, properties);
383 
384         clone.setTransactionConfig(transactionConfig);
385         clone.setFilter(filter);
386         clone.setSecurityFilter(securityFilter);
387 
388         if (remoteSync != null)
389         {
390             clone.setRemoteSync(isRemoteSync());
391         }
392         if (remoteSyncTimeout != null)
393         {
394             clone.setRemoteSyncTimeout(getRemoteSyncTimeout());
395         }
396 
397         if (synchronous != null)
398         {
399             clone.setSynchronous(synchronous.booleanValue());
400         }
401 
402         clone.setDeleteUnacceptedMessages(deleteUnacceptedMessages);
403 
404         clone.setInitialState(initialState);
405         if (initialised.get())
406         {
407             try
408             {
409                 clone.initialise();
410             }
411             catch (InitialisationException e)
412             {
413                 // this really should never happen as the endpoint is already
414                 // initialised
415                 logger.error(e.getMessage(), e);
416             }
417         }
418 
419         return clone;
420     }
421 
422     /*
423      * (non-Javadoc)
424      *
425      * @see org.mule.umo.endpoint.UMOImmutableEndpoint#isReadOnly()
426      */
427     public boolean isReadOnly()
428     {
429         return true;
430     }
431 
432     public String toString()
433     {
434         // Use the interface to retrieve the string and set
435         // the endpoint uri to a default value
436         String sanitizedEndPointUri = null;
437         URI uri = null;
438         if (endpointUri != null)
439         {
440             sanitizedEndPointUri = endpointUri.toString();
441             uri = endpointUri.getUri();
442         }
443         //
444         // The following will further sanitize the endpointuri by removing
445         // the embedded password. This will only remove the password if the
446         // uri contains all the necessary information to successfully rebuild the url
447         if (uri != null && (uri.getRawUserInfo() != null) && (uri.getScheme() != null) 
448             && (uri.getHost() != null) && (uri.getRawPath() != null)) 
449         {
450             // build a pattern up that matches what we need tp strip out the password
451             Pattern sanitizerPattern = Pattern.compile("(.*):.*");
452             Matcher sanitizerMatcher = sanitizerPattern.matcher(uri.getRawUserInfo());
453             if (sanitizerMatcher.matches()) 
454             {
455                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             if ( uri.getRawQuery() != null)
461             {
462                sanitizedEndPointUri = sanitizedEndPointUri + "?" + uri.getRawQuery();
463             }
464 
465         }
466 
467         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      * (non-Javadoc)
479      *
480      * @see org.mule.umo.endpoint.UMOImmutableEndpoint#getProtocol()
481      */
482     public String getProtocol()
483     {
484         return connector.getProtocol();
485     }
486 
487     /*
488      * (non-Javadoc)
489      *
490      * @see org.mule.umo.endpoint.UMOImmutableEndpoint#canReceive()
491      */
492     public boolean canReceive()
493     {
494         return (getType().equals(ENDPOINT_TYPE_RECEIVER) || getType().equals(
495             ENDPOINT_TYPE_SENDER_AND_RECEIVER));
496     }
497 
498     /*
499      * (non-Javadoc)
500      *
501      * @see org.mule.umo.endpoint.UMOImmutableEndpoint#canSend()
502      */
503     public boolean canSend()
504     {
505         return (getType().equals(ENDPOINT_TYPE_SENDER) || getType().equals(ENDPOINT_TYPE_SENDER_AND_RECEIVER));
506     }
507 
508     /*
509      * (non-Javadoc)
510      *
511      * @see org.mule.umo.endpoint.UMOEndpoint#getTransactionConfig()
512      */
513     public UMOTransactionConfig getTransactionConfig()
514     {
515         return transactionConfig;
516     }
517 
518     public boolean equals(Object o)
519     {
520         if (this == o)
521         {
522             return true;
523         }
524         if (!(o instanceof ImmutableMuleEndpoint))
525         {
526             return false;
527         }
528 
529         final ImmutableMuleEndpoint immutableMuleProviderDescriptor = (ImmutableMuleEndpoint) o;
530 
531         if (!connector.getName().equals(immutableMuleProviderDescriptor.connector.getName()))
532         {
533             return false;
534         }
535         if (endpointUri != null && immutableMuleProviderDescriptor.endpointUri != null
536                         ? !endpointUri.getAddress().equals(
537                             immutableMuleProviderDescriptor.endpointUri.getAddress())
538                         : immutableMuleProviderDescriptor.endpointUri != null)
539         {
540             return false;
541         }
542         if (!name.equals(immutableMuleProviderDescriptor.name))
543         {
544             return false;
545         }
546         // MULE-1551
547 //        if (transformer != null
548 //                        ? !transformer.equals(immutableMuleProviderDescriptor.transformer)
549 //                        : immutableMuleProviderDescriptor.transformer != null)
550 //        {
551 //            return false;
552 //        }
553         if (!type.equals(immutableMuleProviderDescriptor.type))
554         {
555             return false;
556         }
557 
558         return true;
559     }
560 
561     public int hashCode()
562     {
563         int result = appendHash(0, connector);
564         result = appendHash(result, endpointUri);
565         // MULE-1551
566 //        result = appendHash(result, transformer);
567         result = appendHash(result, name);
568         result = appendHash(result, type);
569 //        if (logger.isDebugEnabled())
570 //        {
571 //            logger.debug("hashCode: " + result);
572 //        }
573         return result;
574     }
575 
576     private int appendHash(int hash, Object component)
577     {
578         int delta = component != null ? component.hashCode() : 0;
579 //        if (logger.isDebugEnabled())
580 //        {
581 //            logger.debug(component + ": " + delta);
582 //        }
583         return 29 * hash + delta;
584     }
585 
586     public UMOFilter getFilter()
587     {
588         return filter;
589     }
590 
591     public static UMOEndpoint createEndpointFromUri(UMOEndpointURI uri, String type) throws UMOException
592     {
593         return TransportFactory.createEndpoint(uri, type);
594     }
595 
596     public static UMOEndpoint getEndpointFromUri(String uri)
597     {
598         UMOEndpoint endpoint = null;
599         if (uri != null)
600         {
601             String endpointString = MuleManager.getInstance().lookupEndpointIdentifier(uri, uri);
602             endpoint = MuleManager.getInstance().lookupEndpoint(endpointString);
603         }
604         return endpoint;
605     }
606 
607     public static UMOEndpoint getEndpointFromUri(UMOEndpointURI uri) throws UMOException
608     {
609         String endpointName = uri.getEndpointName();
610         if (endpointName != null)
611         {
612             String endpointString = MuleManager.getInstance().lookupEndpointIdentifier(endpointName,
613                 endpointName);
614             UMOEndpoint endpoint = MuleManager.getInstance().lookupEndpoint(endpointString);
615             if (endpoint != null)
616             {
617                 if (StringUtils.isNotEmpty(uri.getAddress()))
618                 {
619                     endpoint.setEndpointURI(uri);
620                 }
621             }
622             return endpoint;
623         }
624 
625         return null;
626     }
627 
628     public static UMOEndpoint getOrCreateEndpointForUri(String uriIdentifier, String type)
629         throws UMOException
630     {
631         UMOEndpoint endpoint = getEndpointFromUri(uriIdentifier);
632         if (endpoint == null)
633         {
634             endpoint = createEndpointFromUri(new MuleEndpointURI(uriIdentifier), type);
635         }
636         else
637         {
638             if (endpoint.getType().equals(UMOEndpoint.ENDPOINT_TYPE_SENDER_AND_RECEIVER))
639             {
640                 endpoint.setType(type);
641             }
642             else if (!endpoint.getType().equals(type))
643             {
644                 throw new IllegalArgumentException("Endpoint matching: " + uriIdentifier
645                                                    + " is not of type: " + type + ". It is of type: "
646                                                    + endpoint.getType());
647 
648             }
649         }
650         return endpoint;
651     }
652 
653     public static UMOEndpoint getOrCreateEndpointForUri(UMOEndpointURI uri, String type) throws UMOException
654     {
655         UMOEndpoint endpoint = getEndpointFromUri(uri);
656         if (endpoint == null)
657         {
658             endpoint = createEndpointFromUri(uri, type);
659         }
660         return endpoint;
661     }
662 
663     public boolean isDeleteUnacceptedMessages()
664     {
665         return deleteUnacceptedMessages;
666     }
667 
668     public void initialise() throws InitialisationException
669     {
670         if (initialised.get())
671         {
672             logger.debug("Already initialised: " + toString());
673             return;
674         }
675         if (connector == null)
676         {
677             if (endpointUri.getConnectorName() != null)
678             {
679                 connector = MuleManager.getInstance().lookupConnector(endpointUri.getConnectorName());
680                 if (connector == null)
681                 {
682                     throw new IllegalArgumentException("Connector not found: "
683                                                        + endpointUri.getConnectorName());
684                 }
685             }
686             else
687             {
688                 try
689                 {
690                     connector = TransportFactory.getOrCreateConnectorByProtocol(this);
691                     if (connector == null)
692                     {
693                         throw new InitialisationException(
694                             CoreMessages.connectorWithProtocolNotRegistered(endpointUri.getScheme()), this);
695                     }
696                 }
697                 catch (TransportFactoryException e)
698                 {
699                     throw new InitialisationException(
700                         CoreMessages.failedToCreateConnectorFromUri(endpointUri), e, this);
701                 }
702             }
703 
704             if (endpointUri.getEndpointName() != null && name == null)
705             {
706                 name = endpointUri.getEndpointName();
707             }
708         }
709         name = ObjectNameHelper.getEndpointName(this);
710 
711         String sync = endpointUri.getParams().getProperty("synchronous", null);
712         if (sync != null)
713         {
714             synchronous = Boolean.valueOf(sync);
715         }
716         if (properties != null && endpointUri.getParams() != null)
717         {
718             properties.putAll(endpointUri.getParams());
719         }
720 
721         if (endpointUri.getTransformers() != null)
722         {
723             try
724             {
725                 transformer = MuleObjectHelper.getTransformer(endpointUri.getTransformers(), ",");
726             }
727             catch (MuleException e)
728             {
729                 throw new InitialisationException(e, this);
730             }
731         }
732 
733         if (transformer == null)
734         {
735             if (connector instanceof AbstractConnector)
736             {
737                 if (UMOEndpoint.ENDPOINT_TYPE_SENDER.equals(type))
738                 {
739                     transformer = ((AbstractConnector) connector).getDefaultOutboundTransformer();
740                 }
741                 else if (UMOEndpoint.ENDPOINT_TYPE_SENDER_AND_RECEIVER.equals(type))
742                 {
743                     transformer = ((AbstractConnector) connector).getDefaultOutboundTransformer();
744                     responseTransformer = ((AbstractConnector) connector).getDefaultInboundTransformer();
745                 }
746                 else
747                 {
748                     transformer = ((AbstractConnector) connector).getDefaultInboundTransformer();
749                 }
750             }
751         }
752         if (transformer != null)
753         {
754             transformer.setEndpoint(this);
755         }
756 
757         if (endpointUri.getResponseTransformers() != null)
758         {
759             try
760             {
761                 responseTransformer =
762                         MuleObjectHelper.getTransformer(endpointUri.getResponseTransformers(), ",");
763             }
764             catch (MuleException e)
765             {
766                 throw new InitialisationException(e, this);
767             }
768         }
769         // Only set default transport response transformer if inbound endpoint (MULE-2868)
770         if (responseTransformer == null  && ENDPOINT_TYPE_RECEIVER.equals(type))
771         {
772             if (connector instanceof AbstractConnector)
773             {
774                 responseTransformer = ((AbstractConnector) connector).getDefaultResponseTransformer();
775             }
776         }
777         if (responseTransformer != null)
778         {
779             responseTransformer.setEndpoint(this);
780         }
781 
782         if (securityFilter != null)
783         {
784             securityFilter.setEndpoint(this);
785             securityFilter.initialise();
786         }
787 
788         // Allow remote sync values to be set as params on the endpoint URI
789         String rs = (String) endpointUri.getParams().remove("remoteSync");
790         if (rs != null)
791         {
792             remoteSync = Boolean.valueOf(rs);
793         }
794 
795         String rsTimeout = (String) endpointUri.getParams().remove("remoteSyncTimeout");
796         if (rsTimeout != null)
797         {
798             remoteSyncTimeout = Integer.valueOf(rsTimeout);
799         }
800 
801         initialised.set(true);
802     }
803 
804     /**
805      * Returns an UMOEndpointSecurityFilter for this endpoint. If one is not set,
806      * there will be no authentication on events sent via this endpoint
807      *
808      * @return UMOEndpointSecurityFilter responsible for authenticating message flow
809      *         via this endpoint.
810      * @see org.mule.umo.security.UMOEndpointSecurityFilter
811      */
812     public UMOEndpointSecurityFilter getSecurityFilter()
813     {
814         return securityFilter;
815     }
816 
817     /**
818      * Determines if requests originating from this endpoint should be synchronous
819      * i.e. execute in a single thread and possibly return an result. This property
820      * is only used when the endpoint is of type 'receiver'
821      *
822      * @return whether requests on this endpoint should execute in a single thread.
823      *         This property is only used when the endpoint is of type 'receiver'
824      */
825     public boolean isSynchronous()
826     {
827         if (synchronous == null)
828         {
829             return MuleManager.getConfiguration().isSynchronous();
830         }
831         return synchronous.booleanValue();
832     }
833 
834     public boolean isSynchronousSet()
835     {
836         return (synchronous != null);
837     }
838 
839     public int getCreateConnector()
840     {
841         return createConnector;
842     }
843 
844     /**
845      * For certain providers that support the notion of a backchannel such as sockets
846      * (outputStream) or Jms (ReplyTo) Mule can automatically wait for a response
847      * from a backchannel when dispatching over these protocols. This is different
848      * for synchronous as synchronous behavior only applies to in
849      *
850      * @return
851      */
852     public boolean isRemoteSync()
853     {
854         if (remoteSync == null)
855         {
856             if (connector == null || connector.isRemoteSyncEnabled())
857             {
858                 remoteSync = Boolean.valueOf(MuleManager.getConfiguration().isRemoteSync());
859             }
860             else
861             {
862                 remoteSync = Boolean.FALSE;
863             }
864         }
865         return remoteSync.booleanValue();
866     }
867 
868     /**
869      * The timeout value for remoteSync invocations
870      *
871      * @return the timeout in milliseconds
872      */
873     public int getRemoteSyncTimeout()
874     {
875         if (remoteSyncTimeout == null)
876         {
877             remoteSyncTimeout = new Integer(MuleManager.getConfiguration().getSynchronousEventTimeout());
878         }
879         return remoteSyncTimeout.intValue();
880     }
881 
882     /**
883      * Sets the state the endpoint will be loaded in. The States are 'stopped' and
884      * 'started' (default)
885      *
886      * @return the endpoint starting state
887      */
888     public String getInitialState()
889     {
890         return initialState;
891     }
892 
893     public UMOTransformer getResponseTransformer()
894     {
895         return responseTransformer;
896     }
897 
898     /**
899      * Determines whether the endpoint should deal with requests as streams
900      *
901      * @return true if the request should be streamed
902      */
903     public boolean isStreaming()
904     {
905         return streaming;
906     }
907 
908     public Object getProperty(Object key)
909     {
910         Object value = properties.get(key);
911         if (value == null)
912         {
913             value = endpointUri.getParams().get(key);
914         }
915         return value;
916     }
917 
918 
919     // TODO the following methods should most likely be lifecycle-enabled
920 
921     public void dispatch(UMOEvent event) throws DispatchException
922     {
923         if (connector != null)
924         {
925             connector.dispatch(this, event);
926         }
927         else
928         {
929             //TODO: Either remove because this should never happen or i18n the message
930             throw new IllegalStateException("The connector on the endpoint: " + toString() + "is null. Please contact dev@mule.codehaus.org");
931         }
932     }
933 
934     public UMOMessage receive(long timeout) throws Exception
935     {
936         if (connector != null)
937         {
938             return connector.receive(this, timeout);
939         }
940         else
941         {
942             //TODO: Either remove because this should never happen or i18n the message
943             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         if (connector != null)
950         {
951             return connector.send(this, event);
952         }
953         else
954         {
955             //TODO: Either remove because this should never happen or i18n the message
956             throw new IllegalStateException("The connector on the endpoint: " + toString() + "is null. Please contact dev@mule.codehaus.org");
957         }
958     }
959 
960 }