View Javadoc

1   /*
2    * $Id: AbstractEndpointBuilder.java 19370 2010-09-06 02:51:40Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.endpoint;
12  
13  import org.mule.MessageExchangePattern;
14  import org.mule.api.DefaultMuleException;
15  import org.mule.api.MuleContext;
16  import org.mule.api.MuleRuntimeException;
17  import org.mule.api.config.MuleProperties;
18  import org.mule.api.endpoint.EndpointBuilder;
19  import org.mule.api.endpoint.EndpointException;
20  import org.mule.api.endpoint.EndpointMessageProcessorChainFactory;
21  import org.mule.api.endpoint.EndpointURI;
22  import org.mule.api.endpoint.ImmutableEndpoint;
23  import org.mule.api.endpoint.InboundEndpoint;
24  import org.mule.api.endpoint.MalformedEndpointException;
25  import org.mule.api.endpoint.OutboundEndpoint;
26  import org.mule.api.lifecycle.InitialisationException;
27  import org.mule.api.processor.MessageProcessor;
28  import org.mule.api.registry.ServiceException;
29  import org.mule.api.registry.ServiceType;
30  import org.mule.api.retry.RetryPolicyTemplate;
31  import org.mule.api.security.EndpointSecurityFilter;
32  import org.mule.api.transaction.TransactionConfig;
33  import org.mule.api.transformer.Transformer;
34  import org.mule.api.transport.Connector;
35  import org.mule.config.i18n.CoreMessages;
36  import org.mule.config.i18n.Message;
37  import org.mule.processor.SecurityFilterMessageProcessor;
38  import org.mule.routing.MessageFilter;
39  import org.mule.transaction.MuleTransactionConfig;
40  import org.mule.transformer.TransformerUtils;
41  import org.mule.transport.AbstractConnector;
42  import org.mule.transport.service.TransportFactory;
43  import org.mule.transport.service.TransportFactoryException;
44  import org.mule.transport.service.TransportServiceDescriptor;
45  import org.mule.transport.service.TransportServiceException;
46  import org.mule.util.ClassUtils;
47  import org.mule.util.CollectionUtils;
48  import org.mule.util.MapCombiner;
49  import org.mule.util.ObjectNameHelper;
50  import org.mule.util.StringUtils;
51  
52  import java.util.Collections;
53  import java.util.HashMap;
54  import java.util.LinkedList;
55  import java.util.List;
56  import java.util.Map;
57  import java.util.Properties;
58  
59  import javax.activation.MimeType;
60  import javax.activation.MimeTypeParseException;
61  
62  import org.apache.commons.logging.Log;
63  import org.apache.commons.logging.LogFactory;
64  
65  /**
66   * Abstract endpoint builder used for externalizing the complex creation logic of
67   * endpoints out of the endpoint instance itself. <br/>
68   * The use of a builder allows i) Endpoints to be configured once and created in a
69   * repeatable fashion (global endpoints), ii) Allow for much more extensibility in
70   * endpoint creation for transport specific endpoints, streaming endpoints etc.<br/>
71   */
72  public abstract class AbstractEndpointBuilder implements EndpointBuilder
73  {
74  
75      public static final String PROPERTY_RESPONSE_TIMEOUT = "responseTimeout";
76      public static final String PROPERTY_RESPONSE_PROPERTIES = "responseProperties";
77  
78      protected URIBuilder uriBuilder;
79      protected Connector connector;
80      protected String name;
81      protected Map<Object, Object> properties = new HashMap<Object, Object>();
82      protected TransactionConfig transactionConfig;
83      protected Boolean deleteUnacceptedMessages;
84      protected Boolean synchronous;
85      protected MessageExchangePattern messageExchangePattern;
86      protected Integer responseTimeout;
87      protected String initialState = ImmutableEndpoint.INITIAL_STATE_STARTED;
88      protected String encoding;
89      protected Integer createConnector;
90      protected RetryPolicyTemplate retryPolicyTemplate;
91      protected String responsePropertiesList;
92      protected EndpointMessageProcessorChainFactory messageProcessorsFactory;
93      protected List<MessageProcessor> messageProcessors = new LinkedList<MessageProcessor>();
94      protected List<MessageProcessor> responseMessageProcessors = new LinkedList<MessageProcessor>();
95      protected List<Transformer> transformers = new LinkedList<Transformer>();
96      protected List<Transformer> responseTransformers = new LinkedList<Transformer>();
97      protected Boolean disableTransportTransformer;
98      protected String mimeType;
99  
100     // not included in equality/hash
101     protected String registryId = null;
102     protected MuleContext muleContext;
103 
104     protected transient Log logger = LogFactory.getLog(getClass());
105 
106     public InboundEndpoint buildInboundEndpoint() throws EndpointException, InitialisationException
107     {
108         return doBuildInboundEndpoint();
109     }
110 
111     public OutboundEndpoint buildOutboundEndpoint() throws EndpointException, InitialisationException
112     {
113         return doBuildOutboundEndpoint();
114     }
115 
116     protected void setPropertiesFromProperties(Map<Object, Object> properties)
117     {
118         final Boolean tempSync = getBooleanProperty(properties, MuleProperties.SYNCHRONOUS_PROPERTY,
119             synchronous);
120         if (tempSync != null)
121         {
122             if (uriBuilder != null)
123             {
124                 logger.warn(String.format(
125                     "Deprecated 'synchronous' flag found on endpoint '%s', please replace with "
126                                     + "e.g. 'exchangePattern=request-response", uriBuilder.getEndpoint()));
127             }
128             else
129             {
130                 logger.warn("Deprecated 'synchronous' flag found on endpoint)");
131             }
132         }
133 
134         String mepString = (String) properties.get(MuleProperties.EXCHANGE_PATTERN_CAMEL_CASE);
135         if (StringUtils.isNotEmpty(mepString))
136         {
137             setExchangePattern(MessageExchangePattern.fromString(mepString));
138         }
139 
140         responseTimeout = getIntegerProperty(properties, PROPERTY_RESPONSE_TIMEOUT, responseTimeout);
141         responsePropertiesList = (String)properties.get(PROPERTY_RESPONSE_PROPERTIES);
142     }
143 
144     private static Boolean getBooleanProperty(Map<Object, Object> properties, String name, Boolean dflt)
145     {
146         if (properties.containsKey(name))
147         {
148             return Boolean.valueOf((String)properties.get(name));
149         }
150         else
151         {
152             return dflt;
153         }
154     }
155 
156     private static Integer getIntegerProperty(Map<Object, Object> properties, String name, Integer dflt)
157     {
158         if (properties.containsKey(name))
159         {
160             return Integer.decode((String)properties.get(name));
161         }
162         else
163         {
164             return dflt;
165         }
166     }
167 
168     protected InboundEndpoint doBuildInboundEndpoint() throws InitialisationException, EndpointException
169     {
170         //It does not make sense to allow inbound dynamic endpoints
171         String uri = uriBuilder.getConstructor();
172         if(muleContext.getExpressionManager().isExpression(uri))
173         {
174             throw new MalformedEndpointException(CoreMessages.dynamicEndpointURIsCannotBeUsedOnInbound(), uri);
175         }
176 
177         prepareToBuildEndpoint();
178 
179         EndpointURI endpointURI = uriBuilder.getEndpoint();
180         endpointURI.initialise();
181         
182         List<MessageProcessor> mergedProcessors = addTransformerProcessors(endpointURI);
183         List<MessageProcessor> mergedResponseProcessors = addResponseTransformerProcessors(endpointURI);
184 
185         Connector connector = getConnector();
186         if (connector != null && !connector.supportsProtocol(endpointURI.getFullScheme()))
187         {
188             throw new IllegalArgumentException(CoreMessages.connectorSchemeIncompatibleWithEndpointScheme(
189                 connector.getProtocol(), endpointURI).getMessage());
190         }
191 
192         checkInboundExchangePattern();
193 
194         // Filters on inbound endpoints need to throw exceptions in case the reciever needs to reject the message 
195         for (MessageProcessor mp :messageProcessors)
196         {
197             if (mp instanceof MessageFilter)
198             {
199                 ((MessageFilter) mp).setThrowOnUnaccepted(true);
200             }
201         }
202         
203         return new DefaultInboundEndpoint(connector, endpointURI,
204                 getName(endpointURI), getProperties(), getTransactionConfig(),
205                 getDefaultDeleteUnacceptedMessages(connector),
206                 messageExchangePattern, getResponseTimeout(connector), getInitialState(connector),
207                 getEndpointEncoding(connector), name, muleContext, getRetryPolicyTemplate(connector),
208                 getMessageProcessorsFactory(), mergedProcessors, mergedResponseProcessors,
209                 isDisableTransportTransformer(), mimeType);
210     }
211 
212     protected OutboundEndpoint doBuildOutboundEndpoint() throws InitialisationException, EndpointException
213     {
214 
215         String uri = uriBuilder.getConstructor();
216         if(muleContext.getExpressionManager().isExpression(uri))
217         {
218             if(muleContext.getExpressionManager().isValidExpression(uriBuilder.getConstructor()))
219             {
220                 uriBuilder = new URIBuilder(DynamicOutboundEndpoint.DYNAMIC_URI_PLACEHOLDER, muleContext);
221                 return new DynamicOutboundEndpoint(muleContext, this, uri);
222             }
223             else
224             {
225                 throw new MalformedEndpointException(uri);
226             }
227         }
228 
229         prepareToBuildEndpoint();
230 
231         EndpointURI endpointURI = uriBuilder.getEndpoint();
232         endpointURI.initialise();
233 
234         List<MessageProcessor> mergedProcessors = addTransformerProcessors(endpointURI);
235         List<MessageProcessor> mergedResponseProcessors = addResponseTransformerProcessors(endpointURI);
236 
237         Connector connector = getConnector();
238         if (connector != null && !connector.supportsProtocol(getScheme()))
239         {
240             throw new IllegalArgumentException(CoreMessages.connectorSchemeIncompatibleWithEndpointScheme(
241                 connector.getProtocol(), endpointURI).getMessage());
242         }
243 
244         checkOutboundExchangePattern();
245 
246         return new DefaultOutboundEndpoint(connector, endpointURI,
247                 getName(endpointURI), getProperties(), getTransactionConfig(),
248                 getDefaultDeleteUnacceptedMessages(connector), 
249                 messageExchangePattern, getResponseTimeout(connector), getInitialState(connector),
250                 getEndpointEncoding(connector), name, muleContext, getRetryPolicyTemplate(connector),
251                 responsePropertiesList,  getMessageProcessorsFactory(), mergedProcessors,
252                 mergedResponseProcessors, isDisableTransportTransformer(), mimeType);
253     }
254     
255     protected List<MessageProcessor> addTransformerProcessors(EndpointURI endpointURI)
256         throws TransportFactoryException
257     {
258         List<MessageProcessor> tempProcessors = new LinkedList<MessageProcessor>(messageProcessors);
259         tempProcessors.addAll(getTransformersFromUri(endpointURI));
260         tempProcessors.addAll(transformers);
261         return tempProcessors;
262     }
263 
264     protected List<MessageProcessor> addResponseTransformerProcessors(EndpointURI endpointURI)
265         throws TransportFactoryException
266     {
267         List<MessageProcessor> tempResponseProcessors = new LinkedList<MessageProcessor>(
268             responseMessageProcessors);
269         tempResponseProcessors.addAll(getResponseTransformersFromUri(endpointURI));
270         tempResponseProcessors.addAll(responseTransformers);
271         return tempResponseProcessors;
272     }
273 
274     protected void prepareToBuildEndpoint()
275     {
276         // use an explicit value here to avoid caching
277         Map<Object, Object> props = getProperties();
278         // this sets values used below, if they appear as properties
279         setPropertiesFromProperties(props);
280 
281         if (uriBuilder == null)
282         {
283             throw new MuleRuntimeException(CoreMessages.objectIsNull("uriBuilder"));
284         }
285         uriBuilder.setMuleContext(muleContext);
286     }
287 
288     protected void checkInboundExchangePattern() throws EndpointException
289     {
290         TransportServiceDescriptor serviceDescriptor = getConnectorServiceDescriptor();
291         initExchangePatternFromConnectorDefault(serviceDescriptor);
292 
293         if (!serviceDescriptor.getInboundExchangePatterns().contains(messageExchangePattern))
294         {
295             throw new EndpointException(CoreMessages.exchangePatternForEndpointNotSupported(
296                 messageExchangePattern, "inbound", uriBuilder.getEndpoint()));
297         }
298     }
299 
300     private void checkOutboundExchangePattern() throws EndpointException
301     {
302         TransportServiceDescriptor serviceDescriptor = getConnectorServiceDescriptor();
303         initExchangePatternFromConnectorDefault(serviceDescriptor);
304 
305         if (!serviceDescriptor.getOutboundExchangePatterns().contains(messageExchangePattern))
306         {
307             throw new EndpointException(CoreMessages.exchangePatternForEndpointNotSupported(
308                 messageExchangePattern, "outbound", uriBuilder.getEndpoint()));
309         }
310     }
311 
312     private TransportServiceDescriptor getConnectorServiceDescriptor() throws EndpointException
313     {
314         try
315         {
316             Connector conn = getConnector();
317             return getNonNullServiceDescriptor(conn);
318         }
319         catch (ServiceException e)
320         {
321             throw new EndpointException(e);
322         }
323     }
324 
325     protected void initExchangePatternFromConnectorDefault(TransportServiceDescriptor serviceDescriptor)
326         throws EndpointException
327     {
328         if (messageExchangePattern == null)
329         {
330             try
331             {
332                 messageExchangePattern = serviceDescriptor.getDefaultExchangePattern();
333             }
334             catch (TransportServiceException e)
335             {
336                 throw new EndpointException(e);
337             }
338         }
339     }
340 
341     private Properties getOverrides(Connector connector)
342     {
343         // Get connector specific overrides to set on the descriptor
344         Properties overrides = new Properties();
345         if (connector instanceof AbstractConnector)
346         {
347             Map so = ((AbstractConnector)connector).getServiceOverrides();
348             if (so != null)
349             {
350                 overrides.putAll(so);
351             }
352         }
353         return overrides;
354     }
355 
356     private TransportServiceDescriptor getNonNullServiceDescriptor(Connector conn) throws ServiceException
357     {
358         String scheme = uriBuilder.getEndpoint().getSchemeMetaInfo();
359         Properties overrides = getOverrides(conn);
360         TransportServiceDescriptor sd = (TransportServiceDescriptor) muleContext.getRegistry()
361             .lookupServiceDescriptor(ServiceType.TRANSPORT, scheme, overrides);
362         if (null != sd)
363         {
364             return sd;
365         }
366         else
367         {
368             throw new ServiceException(CoreMessages.noServiceTransportDescriptor(scheme));
369         }
370     }
371 
372     protected RetryPolicyTemplate getRetryPolicyTemplate(Connector conn)
373     {
374         return retryPolicyTemplate != null ? retryPolicyTemplate : conn.getRetryPolicyTemplate();
375     }
376 
377     protected TransactionConfig getTransactionConfig()
378     {
379         return transactionConfig != null ? transactionConfig : getDefaultTransactionConfig();
380     }
381 
382     protected TransactionConfig getDefaultTransactionConfig()
383     {
384         return new MuleTransactionConfig();
385     }
386 
387     protected EndpointSecurityFilter getSecurityFilter()
388     {
389         for (MessageProcessor mp : messageProcessors)
390         {
391             if (mp instanceof SecurityFilterMessageProcessor)
392             {
393                 return ((SecurityFilterMessageProcessor) mp).getFilter();
394             }
395         }
396 
397         return null;
398     }
399 
400     protected EndpointSecurityFilter getDefaultSecurityFilter()
401     {
402         return null;
403     }
404 
405     protected Connector getConnector() throws EndpointException
406     {
407         return connector != null ? connector : getDefaultConnector();
408     }
409 
410     protected Connector getDefaultConnector() throws EndpointException
411     {
412         return getConnector(uriBuilder.getEndpoint());
413     }
414 
415     protected String getName(EndpointURI endpointURI)
416     {
417         return name != null ? name : new ObjectNameHelper(muleContext).getEndpointName(endpointURI);
418     }
419 
420     protected Map<Object, Object> getProperties()
421     {
422         // Add properties from builder, endpointURI and then seal (make unmodifiable)
423         LinkedList<Object> maps = new LinkedList<Object>();
424         // properties from url come first
425         if (null != uriBuilder)
426         {
427             uriBuilder.setMuleContext(muleContext);
428             // properties from the URI itself
429             maps.addLast(uriBuilder.getEndpoint().getParams());
430         }
431         // properties on builder may override url
432         if (properties != null)
433         {
434             maps.addLast(properties);
435         }
436         MapCombiner combiner = new MapCombiner();
437         combiner.setList(maps);
438         return Collections.unmodifiableMap(combiner);
439     }
440 
441     protected boolean getDeleteUnacceptedMessages(Connector connector)
442     {
443         return deleteUnacceptedMessages != null
444                                                ? deleteUnacceptedMessages.booleanValue()
445                                                : getDefaultDeleteUnacceptedMessages(connector);
446     }
447 
448     protected boolean getDefaultDeleteUnacceptedMessages(Connector connector)
449     {
450         return false;
451     }
452 
453     protected String getEndpointEncoding(Connector connector)
454     {
455         return encoding != null ? encoding : getDefaultEndpointEncoding(connector);
456     }
457 
458     protected String getDefaultEndpointEncoding(Connector connector)
459     {
460         return muleContext.getConfiguration().getDefaultEncoding();
461     }
462 
463     protected String getInitialState(Connector connector)
464     {
465         return initialState != null ? initialState : getDefaultInitialState(connector);
466     }
467 
468     protected String getDefaultInitialState(Connector connector)
469     {
470         return ImmutableEndpoint.INITIAL_STATE_STARTED;
471     }
472 
473     protected int getResponseTimeout(Connector connector)
474     {
475         return responseTimeout != null ? responseTimeout.intValue() : getDefaultResponseTimeout(connector);
476 
477     }
478 
479     protected int getDefaultResponseTimeout(Connector connector)
480     {
481         return muleContext.getConfiguration().getDefaultResponseTimeout();
482     }
483 
484     protected List<Transformer> getTransformersFromUri(EndpointURI endpointURI)
485         throws TransportFactoryException
486     {
487         if (endpointURI.getTransformers() != null)
488         {
489             if (!CollectionUtils.containsType(messageProcessors, Transformer.class))
490             {
491                 return getTransformersFromString(endpointURI.getTransformers());
492             }
493             else
494             {
495                 logger.info("Endpoint with uri '"
496                             + endpointURI.toString()
497                             + "' has transformer(s) configured, transformers configured as uri paramaters will be ignored.");
498             }
499         }
500         return Collections.emptyList();
501     }
502 
503     protected List<Transformer> getResponseTransformersFromUri(EndpointURI endpointURI)
504         throws TransportFactoryException
505     {
506         if (endpointURI.getResponseTransformers() != null)
507         {
508             if (!CollectionUtils.containsType(responseMessageProcessors, Transformer.class))
509             {
510                 return getTransformersFromString(endpointURI.getResponseTransformers());
511             }
512             else
513             {
514                 logger.info("Endpoint with uri '"
515                             + endpointURI.toString()
516                             + "' has response transformer(s) configured, response transformers configured as uri paramaters will be ignored.");
517             }
518         }
519         return Collections.emptyList();
520     }
521     
522     protected String getMimeType()
523     {
524         return mimeType;
525     }
526 
527     public void setMimeType(String mimeType)
528     {
529         if (mimeType == null)
530         {
531             this.mimeType = null;
532         }
533         else
534         {
535             MimeType mt;
536             try
537             {
538                 mt = new MimeType(mimeType);
539             }
540             catch (MimeTypeParseException e)
541             {
542                 throw new IllegalArgumentException(e.getMessage(), e);
543             }
544             this.mimeType = mt.getPrimaryType() + "/" + mt.getSubType();
545         }
546     }
547 
548     private List<Transformer> getTransformersFromString(String transformerString) throws TransportFactoryException
549     {
550         try
551         {
552             return TransformerUtils.getTransformers(transformerString, muleContext);
553         }
554         catch (DefaultMuleException e)
555         {
556             throw new TransportFactoryException(e);
557         }
558     }
559 
560     private Connector getConnector(EndpointURI endpointURI) throws EndpointException
561     {
562         String scheme = getScheme();
563         TransportFactory factory = new TransportFactory(muleContext);
564 
565         Connector connector;
566         try
567         {
568             if (uriBuilder.getEndpoint().getConnectorName() != null)
569             {
570                 connector = muleContext.getRegistry().lookupConnector(
571                     uriBuilder.getEndpoint().getConnectorName());
572                 if (connector == null)
573                 {
574                     throw new TransportFactoryException(CoreMessages.objectNotRegistered("Connector",
575                         uriBuilder.getEndpoint().getConnectorName()));
576                 }
577             }
578             else if (isAlwaysCreateConnector())
579             {
580                 connector = factory.createConnector(endpointURI);
581                 muleContext.getRegistry().registerConnector(connector);
582             }
583             else
584             {
585                 connector = factory.getConnectorByProtocol(scheme);
586                 if (connector == null)
587                 {
588                     connector = factory.createConnector(endpointURI);
589                     muleContext.getRegistry().registerConnector(connector);
590                 }
591             }
592         }
593         catch (Exception e)
594         {
595             throw new TransportFactoryException(e);
596         }
597 
598         if (connector == null)
599         {
600             Message m = CoreMessages.failedToCreateObjectWith("Endpoint", "endpointURI: " + endpointURI);
601             m.setNextMessage(CoreMessages.objectIsNull("connector"));
602             throw new TransportFactoryException(m);
603 
604         }
605         return connector;
606     }
607 
608     protected String getScheme()
609     {
610         return uriBuilder.getEndpoint().getFullScheme();
611     }
612 
613     /**
614      * Some endpoint may always require a new connector to be created for every
615      * endpoint
616      *
617      * @return the default if false but cusotm endpoints can override
618      * @since 3.0.0
619      */
620     protected boolean isAlwaysCreateConnector()
621     {
622         return false;
623     }
624 
625     // Builder setters
626 
627     public void setConnector(Connector connector)
628     {
629         this.connector = connector;
630     }
631 
632     /** @deprecated Use addMessageProcessor() */
633     @Deprecated
634     public void addTransformer(Transformer transformer)
635     {
636         this.transformers.add(transformer);
637     }
638 
639     /** @deprecated Use setMessageProcessors() */
640     @Deprecated
641     public void setTransformers(List<Transformer> newTransformers)
642     {
643         if (newTransformers == null)
644         {
645             newTransformers = new LinkedList<Transformer>();
646         }
647         this.transformers = newTransformers;
648     }
649 
650     protected EndpointMessageProcessorChainFactory getMessageProcessorsFactory()
651     {
652         return messageProcessorsFactory != null
653                                                ? messageProcessorsFactory
654                                                : getDefaultMessageProcessorsFactory();
655     }
656 
657     protected EndpointMessageProcessorChainFactory getDefaultMessageProcessorsFactory()
658     {
659         return new DefaultEndpointMessageProcessorChainFactory();
660     }
661 
662     /** @deprecated Use addResponseMessageProcessor() */
663     @Deprecated
664     public void addResponseTransformer(Transformer transformer)
665     {
666         this.responseTransformers.add(transformer);
667     }
668 
669     /** @deprecated Use setResponseMessageProcessors() */
670     @Deprecated
671     public void setResponseTransformers(List<Transformer> newResponseTransformers)
672     {
673         if (newResponseTransformers == null)
674         {
675             newResponseTransformers = new LinkedList<Transformer>();
676         }
677         this.responseTransformers = newResponseTransformers;
678     }
679 
680     public void addMessageProcessor(MessageProcessor messageProcessor)
681     {
682         messageProcessors.add(messageProcessor);
683     }
684 
685     public void setMessageProcessors(List<MessageProcessor> newMessageProcessors)
686     {
687         if (newMessageProcessors == null)
688         {
689             newMessageProcessors = new LinkedList<MessageProcessor>();
690         }
691         this.messageProcessors = newMessageProcessors;
692     }
693 
694     public List<MessageProcessor> getMessageProcessors()
695     {
696         return messageProcessors;
697     }
698 
699     public void addResponseMessageProcessor(MessageProcessor messageProcessor)
700     {
701         responseMessageProcessors.add(messageProcessor);
702     }
703 
704     public void setResponseMessageProcessors(List<MessageProcessor> newResponseMessageProcessors)
705     {
706         if (newResponseMessageProcessors == null)
707         {
708             newResponseMessageProcessors = new LinkedList<MessageProcessor>();
709         }
710         this.responseMessageProcessors = newResponseMessageProcessors;
711     }
712 
713     public List<MessageProcessor> getResponseMessageProcessors()
714     {
715         return responseMessageProcessors;
716     }
717 
718     protected boolean isDisableTransportTransformer()
719     {
720         return disableTransportTransformer != null
721                 ? disableTransportTransformer.booleanValue()
722                 : getDefaultDisableTransportTransformer();
723     }
724 
725     protected boolean getDefaultDisableTransportTransformer()
726     {
727         return false;
728     }
729 
730     public void setName(String name)
731     {
732         this.name = name;
733     }
734 
735     /**
736      * NOTE - this appends properties.
737      */
738     public void setProperties(Map<Object, Object> properties)
739     {
740         if (null == this.properties)
741         {
742             this.properties = new HashMap<Object, Object>();
743         }
744         this.properties.putAll(properties);
745     }
746 
747     /**
748      * Sets a property on the endpoint
749      *
750      * @param key the property key
751      * @param value the value of the property
752      */
753     public void setProperty(Object key, Object value)
754     {
755         properties.put(key, value);
756     }
757 
758     public void setTransactionConfig(TransactionConfig transactionConfig)
759     {
760         this.transactionConfig = transactionConfig;
761     }
762 
763     public void setDeleteUnacceptedMessages(boolean deleteUnacceptedMessages)
764     {
765         this.deleteUnacceptedMessages = Boolean.valueOf(deleteUnacceptedMessages);
766     }
767 
768     public void setExchangePattern(MessageExchangePattern mep)
769     {
770         messageExchangePattern = mep;
771     }
772 
773     public void setResponseTimeout(int responseTimeout)
774     {
775         this.responseTimeout = new Integer(responseTimeout);
776     }
777 
778     public void setInitialState(String initialState)
779     {
780         this.initialState = initialState;
781     }
782 
783     public void setEncoding(String encoding)
784     {
785         this.encoding = encoding;
786     }
787 
788     public void setCreateConnector(int createConnector)
789     {
790         this.createConnector = new Integer(createConnector);
791     }
792 
793     public void setRegistryId(String registryId)
794     {
795         this.registryId = registryId;
796     }
797 
798     public void setMuleContext(MuleContext muleContext)
799     {
800         this.muleContext = muleContext;
801     }
802 
803     public void setRetryPolicyTemplate(RetryPolicyTemplate retryPolicyTemplate)
804     {
805         this.retryPolicyTemplate = retryPolicyTemplate;
806     }
807 
808     public void setDisableTransportTransformer(boolean disableTransportTransformer)
809     {
810         this.disableTransportTransformer = Boolean.valueOf(disableTransportTransformer);
811     }
812 
813     public URIBuilder getEndpointBuilder()
814     {
815         return uriBuilder;
816     }
817 
818     public void setURIBuilder(URIBuilder URIBuilder)
819     {
820         this.uriBuilder = URIBuilder;
821     }
822 
823     @Override
824     public int hashCode()
825     {
826         return ClassUtils.hash(new Object[]{retryPolicyTemplate, connector, createConnector, 
827             deleteUnacceptedMessages, encoding, uriBuilder, initialState, name, properties,
828             responseTimeout, responseMessageProcessors, synchronous,
829             messageExchangePattern, transactionConfig, messageProcessors, disableTransportTransformer, mimeType});
830     }
831 
832     @Override
833     public boolean equals(Object obj)
834     {
835         if (this == obj)
836         {
837             return true;
838         }
839         if (obj == null || getClass() != obj.getClass())
840         {
841             return false;
842         }
843 
844         final AbstractEndpointBuilder other = (AbstractEndpointBuilder)obj;
845         return equal(retryPolicyTemplate, other.retryPolicyTemplate) && equal(connector, other.connector)
846                 && equal(createConnector, other.createConnector)
847                 && equal(deleteUnacceptedMessages, other.deleteUnacceptedMessages) && equal(encoding, other.encoding)
848                 && equal(uriBuilder, other.uriBuilder)
849                 && equal(initialState, other.initialState) && equal(name, other.name)
850                 && equal(properties, other.properties)
851                 && equal(responseTimeout, other.responseTimeout)
852                 && equal(messageProcessors, other.messageProcessors)
853                 && equal(synchronous, other.synchronous)
854                 && equal(messageExchangePattern, other.messageExchangePattern)
855                 && equal(transactionConfig, other.transactionConfig)
856                 && equal(responseMessageProcessors, other.responseMessageProcessors)
857                 && equal(disableTransportTransformer, other.disableTransportTransformer)
858                 && equal(mimeType, other.mimeType);
859     }
860 
861     protected static boolean equal(Object a, Object b)
862     {
863         return ClassUtils.equal(a, b);
864     }
865 
866     @Override
867     public Object clone() throws CloneNotSupportedException
868     {
869         EndpointBuilder builder = (EndpointBuilder)super.clone();
870         builder.setConnector(connector);
871         builder.setURIBuilder(uriBuilder);
872         builder.setMessageProcessors(messageProcessors);
873         builder.setResponseMessageProcessors(responseMessageProcessors);
874         builder.setName(name);
875         builder.setProperties(properties);
876         builder.setTransactionConfig(transactionConfig);
877         builder.setInitialState(initialState);
878         builder.setEncoding(encoding);
879         builder.setRegistryId(registryId);
880         builder.setMuleContext(muleContext);
881         builder.setRetryPolicyTemplate(retryPolicyTemplate);
882         builder.setTransformers(transformers);
883         builder.setResponseTransformers(responseTransformers);
884 
885         if (deleteUnacceptedMessages != null)
886         {
887             builder.setDeleteUnacceptedMessages(deleteUnacceptedMessages.booleanValue());
888         }
889         if (messageExchangePattern != null)
890         {
891             builder.setExchangePattern(messageExchangePattern);
892         }
893 
894         if (responseTimeout != null)
895         {
896             builder.setResponseTimeout(responseTimeout.intValue());
897         }
898         if (disableTransportTransformer != null)
899         {
900             builder.setDisableTransportTransformer(disableTransportTransformer.booleanValue());
901         }
902 
903         return builder;
904     }
905 
906 }