1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
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 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | protected List<MessageProcessor> messageProcessors = new LinkedList<MessageProcessor>(); |
94 | 0 | protected List<MessageProcessor> responseMessageProcessors = new LinkedList<MessageProcessor>(); |
95 | 0 | protected List<Transformer> transformers = new LinkedList<Transformer>(); |
96 | 0 | protected List<Transformer> responseTransformers = new LinkedList<Transformer>(); |
97 | |
protected Boolean disableTransportTransformer; |
98 | |
protected String mimeType; |
99 | |
|
100 | |
|
101 | 0 | protected String registryId = null; |
102 | |
protected MuleContext muleContext; |
103 | |
|
104 | 0 | protected transient Log logger = LogFactory.getLog(getClass()); |
105 | |
|
106 | |
public InboundEndpoint buildInboundEndpoint() throws EndpointException, InitialisationException |
107 | |
{ |
108 | 0 | return doBuildInboundEndpoint(); |
109 | |
} |
110 | |
|
111 | |
public OutboundEndpoint buildOutboundEndpoint() throws EndpointException, InitialisationException |
112 | |
{ |
113 | 0 | return doBuildOutboundEndpoint(); |
114 | |
} |
115 | |
|
116 | |
protected void setPropertiesFromProperties(Map<Object, Object> properties) |
117 | |
{ |
118 | 0 | final Boolean tempSync = getBooleanProperty(properties, MuleProperties.SYNCHRONOUS_PROPERTY, |
119 | |
synchronous); |
120 | 0 | if (tempSync != null) |
121 | |
{ |
122 | 0 | if (uriBuilder != null) |
123 | |
{ |
124 | 0 | 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 | 0 | logger.warn("Deprecated 'synchronous' flag found on endpoint)"); |
131 | |
} |
132 | |
} |
133 | |
|
134 | 0 | String mepString = (String) properties.get(MuleProperties.EXCHANGE_PATTERN_CAMEL_CASE); |
135 | 0 | if (StringUtils.isNotEmpty(mepString)) |
136 | |
{ |
137 | 0 | setExchangePattern(MessageExchangePattern.fromString(mepString)); |
138 | |
} |
139 | |
|
140 | 0 | responseTimeout = getIntegerProperty(properties, PROPERTY_RESPONSE_TIMEOUT, responseTimeout); |
141 | 0 | responsePropertiesList = (String)properties.get(PROPERTY_RESPONSE_PROPERTIES); |
142 | 0 | } |
143 | |
|
144 | |
private static Boolean getBooleanProperty(Map<Object, Object> properties, String name, Boolean dflt) |
145 | |
{ |
146 | 0 | if (properties.containsKey(name)) |
147 | |
{ |
148 | 0 | return Boolean.valueOf((String)properties.get(name)); |
149 | |
} |
150 | |
else |
151 | |
{ |
152 | 0 | return dflt; |
153 | |
} |
154 | |
} |
155 | |
|
156 | |
private static Integer getIntegerProperty(Map<Object, Object> properties, String name, Integer dflt) |
157 | |
{ |
158 | 0 | if (properties.containsKey(name)) |
159 | |
{ |
160 | 0 | return Integer.decode((String)properties.get(name)); |
161 | |
} |
162 | |
else |
163 | |
{ |
164 | 0 | return dflt; |
165 | |
} |
166 | |
} |
167 | |
|
168 | |
protected InboundEndpoint doBuildInboundEndpoint() throws InitialisationException, EndpointException |
169 | |
{ |
170 | |
|
171 | 0 | String uri = uriBuilder.getConstructor(); |
172 | 0 | if(muleContext.getExpressionManager().isExpression(uri)) |
173 | |
{ |
174 | 0 | throw new MalformedEndpointException(CoreMessages.dynamicEndpointURIsCannotBeUsedOnInbound(), uri); |
175 | |
} |
176 | |
|
177 | 0 | prepareToBuildEndpoint(); |
178 | |
|
179 | 0 | EndpointURI endpointURI = uriBuilder.getEndpoint(); |
180 | 0 | endpointURI.initialise(); |
181 | |
|
182 | 0 | List<MessageProcessor> mergedProcessors = addTransformerProcessors(endpointURI); |
183 | 0 | List<MessageProcessor> mergedResponseProcessors = addResponseTransformerProcessors(endpointURI); |
184 | |
|
185 | 0 | Connector connector = getConnector(); |
186 | 0 | if (connector != null && !connector.supportsProtocol(endpointURI.getFullScheme())) |
187 | |
{ |
188 | 0 | throw new IllegalArgumentException(CoreMessages.connectorSchemeIncompatibleWithEndpointScheme( |
189 | |
connector.getProtocol(), endpointURI).getMessage()); |
190 | |
} |
191 | |
|
192 | 0 | checkInboundExchangePattern(); |
193 | |
|
194 | |
|
195 | 0 | for (MessageProcessor mp :messageProcessors) |
196 | |
{ |
197 | 0 | if (mp instanceof MessageFilter) |
198 | |
{ |
199 | 0 | ((MessageFilter) mp).setThrowOnUnaccepted(true); |
200 | |
} |
201 | |
} |
202 | |
|
203 | 0 | 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 | 0 | String uri = uriBuilder.getConstructor(); |
216 | 0 | if(muleContext.getExpressionManager().isExpression(uri)) |
217 | |
{ |
218 | 0 | if(muleContext.getExpressionManager().isValidExpression(uriBuilder.getConstructor())) |
219 | |
{ |
220 | 0 | uriBuilder = new URIBuilder(DynamicOutboundEndpoint.DYNAMIC_URI_PLACEHOLDER, muleContext); |
221 | 0 | return new DynamicOutboundEndpoint(muleContext, this, uri); |
222 | |
} |
223 | |
else |
224 | |
{ |
225 | 0 | throw new MalformedEndpointException(uri); |
226 | |
} |
227 | |
} |
228 | |
|
229 | 0 | prepareToBuildEndpoint(); |
230 | |
|
231 | 0 | EndpointURI endpointURI = uriBuilder.getEndpoint(); |
232 | 0 | endpointURI.initialise(); |
233 | |
|
234 | 0 | List<MessageProcessor> mergedProcessors = addTransformerProcessors(endpointURI); |
235 | 0 | List<MessageProcessor> mergedResponseProcessors = addResponseTransformerProcessors(endpointURI); |
236 | |
|
237 | 0 | Connector connector = getConnector(); |
238 | 0 | if (connector != null && !connector.supportsProtocol(getScheme())) |
239 | |
{ |
240 | 0 | throw new IllegalArgumentException(CoreMessages.connectorSchemeIncompatibleWithEndpointScheme( |
241 | |
connector.getProtocol(), endpointURI).getMessage()); |
242 | |
} |
243 | |
|
244 | 0 | checkOutboundExchangePattern(); |
245 | |
|
246 | 0 | 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 | 0 | List<MessageProcessor> tempProcessors = new LinkedList<MessageProcessor>(messageProcessors); |
259 | 0 | tempProcessors.addAll(getTransformersFromUri(endpointURI)); |
260 | 0 | tempProcessors.addAll(transformers); |
261 | 0 | return tempProcessors; |
262 | |
} |
263 | |
|
264 | |
protected List<MessageProcessor> addResponseTransformerProcessors(EndpointURI endpointURI) |
265 | |
throws TransportFactoryException |
266 | |
{ |
267 | 0 | List<MessageProcessor> tempResponseProcessors = new LinkedList<MessageProcessor>( |
268 | |
responseMessageProcessors); |
269 | 0 | tempResponseProcessors.addAll(getResponseTransformersFromUri(endpointURI)); |
270 | 0 | tempResponseProcessors.addAll(responseTransformers); |
271 | 0 | return tempResponseProcessors; |
272 | |
} |
273 | |
|
274 | |
protected void prepareToBuildEndpoint() |
275 | |
{ |
276 | |
|
277 | 0 | Map<Object, Object> props = getProperties(); |
278 | |
|
279 | 0 | setPropertiesFromProperties(props); |
280 | |
|
281 | 0 | if (uriBuilder == null) |
282 | |
{ |
283 | 0 | throw new MuleRuntimeException(CoreMessages.objectIsNull("uriBuilder")); |
284 | |
} |
285 | 0 | uriBuilder.setMuleContext(muleContext); |
286 | 0 | } |
287 | |
|
288 | |
protected void checkInboundExchangePattern() throws EndpointException |
289 | |
{ |
290 | 0 | TransportServiceDescriptor serviceDescriptor = getConnectorServiceDescriptor(); |
291 | 0 | initExchangePatternFromConnectorDefault(serviceDescriptor); |
292 | |
|
293 | 0 | if (!serviceDescriptor.getInboundExchangePatterns().contains(messageExchangePattern)) |
294 | |
{ |
295 | 0 | throw new EndpointException(CoreMessages.exchangePatternForEndpointNotSupported( |
296 | |
messageExchangePattern, "inbound", uriBuilder.getEndpoint())); |
297 | |
} |
298 | 0 | } |
299 | |
|
300 | |
private void checkOutboundExchangePattern() throws EndpointException |
301 | |
{ |
302 | 0 | TransportServiceDescriptor serviceDescriptor = getConnectorServiceDescriptor(); |
303 | 0 | initExchangePatternFromConnectorDefault(serviceDescriptor); |
304 | |
|
305 | 0 | if (!serviceDescriptor.getOutboundExchangePatterns().contains(messageExchangePattern)) |
306 | |
{ |
307 | 0 | throw new EndpointException(CoreMessages.exchangePatternForEndpointNotSupported( |
308 | |
messageExchangePattern, "outbound", uriBuilder.getEndpoint())); |
309 | |
} |
310 | 0 | } |
311 | |
|
312 | |
private TransportServiceDescriptor getConnectorServiceDescriptor() throws EndpointException |
313 | |
{ |
314 | |
try |
315 | |
{ |
316 | 0 | Connector conn = getConnector(); |
317 | 0 | return getNonNullServiceDescriptor(conn); |
318 | |
} |
319 | 0 | catch (ServiceException e) |
320 | |
{ |
321 | 0 | throw new EndpointException(e); |
322 | |
} |
323 | |
} |
324 | |
|
325 | |
protected void initExchangePatternFromConnectorDefault(TransportServiceDescriptor serviceDescriptor) |
326 | |
throws EndpointException |
327 | |
{ |
328 | 0 | if (messageExchangePattern == null) |
329 | |
{ |
330 | |
try |
331 | |
{ |
332 | 0 | messageExchangePattern = serviceDescriptor.getDefaultExchangePattern(); |
333 | |
} |
334 | 0 | catch (TransportServiceException e) |
335 | |
{ |
336 | 0 | throw new EndpointException(e); |
337 | 0 | } |
338 | |
} |
339 | 0 | } |
340 | |
|
341 | |
private Properties getOverrides(Connector connector) |
342 | |
{ |
343 | |
|
344 | 0 | Properties overrides = new Properties(); |
345 | 0 | if (connector instanceof AbstractConnector) |
346 | |
{ |
347 | 0 | Map so = ((AbstractConnector)connector).getServiceOverrides(); |
348 | 0 | if (so != null) |
349 | |
{ |
350 | 0 | overrides.putAll(so); |
351 | |
} |
352 | |
} |
353 | 0 | return overrides; |
354 | |
} |
355 | |
|
356 | |
private TransportServiceDescriptor getNonNullServiceDescriptor(Connector conn) throws ServiceException |
357 | |
{ |
358 | 0 | String scheme = uriBuilder.getEndpoint().getSchemeMetaInfo(); |
359 | 0 | Properties overrides = getOverrides(conn); |
360 | 0 | TransportServiceDescriptor sd = (TransportServiceDescriptor) muleContext.getRegistry() |
361 | |
.lookupServiceDescriptor(ServiceType.TRANSPORT, scheme, overrides); |
362 | 0 | if (null != sd) |
363 | |
{ |
364 | 0 | return sd; |
365 | |
} |
366 | |
else |
367 | |
{ |
368 | 0 | throw new ServiceException(CoreMessages.noServiceTransportDescriptor(scheme)); |
369 | |
} |
370 | |
} |
371 | |
|
372 | |
protected RetryPolicyTemplate getRetryPolicyTemplate(Connector conn) |
373 | |
{ |
374 | 0 | return retryPolicyTemplate != null ? retryPolicyTemplate : conn.getRetryPolicyTemplate(); |
375 | |
} |
376 | |
|
377 | |
protected TransactionConfig getTransactionConfig() |
378 | |
{ |
379 | 0 | return transactionConfig != null ? transactionConfig : getDefaultTransactionConfig(); |
380 | |
} |
381 | |
|
382 | |
protected TransactionConfig getDefaultTransactionConfig() |
383 | |
{ |
384 | 0 | return new MuleTransactionConfig(); |
385 | |
} |
386 | |
|
387 | |
protected EndpointSecurityFilter getSecurityFilter() |
388 | |
{ |
389 | 0 | for (MessageProcessor mp : messageProcessors) |
390 | |
{ |
391 | 0 | if (mp instanceof SecurityFilterMessageProcessor) |
392 | |
{ |
393 | 0 | return ((SecurityFilterMessageProcessor) mp).getFilter(); |
394 | |
} |
395 | |
} |
396 | |
|
397 | 0 | return null; |
398 | |
} |
399 | |
|
400 | |
protected EndpointSecurityFilter getDefaultSecurityFilter() |
401 | |
{ |
402 | 0 | return null; |
403 | |
} |
404 | |
|
405 | |
protected Connector getConnector() throws EndpointException |
406 | |
{ |
407 | 0 | return connector != null ? connector : getDefaultConnector(); |
408 | |
} |
409 | |
|
410 | |
protected Connector getDefaultConnector() throws EndpointException |
411 | |
{ |
412 | 0 | return getConnector(uriBuilder.getEndpoint()); |
413 | |
} |
414 | |
|
415 | |
protected String getName(EndpointURI endpointURI) |
416 | |
{ |
417 | 0 | return name != null ? name : new ObjectNameHelper(muleContext).getEndpointName(endpointURI); |
418 | |
} |
419 | |
|
420 | |
protected Map<Object, Object> getProperties() |
421 | |
{ |
422 | |
|
423 | 0 | LinkedList<Object> maps = new LinkedList<Object>(); |
424 | |
|
425 | 0 | if (null != uriBuilder) |
426 | |
{ |
427 | 0 | uriBuilder.setMuleContext(muleContext); |
428 | |
|
429 | 0 | maps.addLast(uriBuilder.getEndpoint().getParams()); |
430 | |
} |
431 | |
|
432 | 0 | if (properties != null) |
433 | |
{ |
434 | 0 | maps.addLast(properties); |
435 | |
} |
436 | 0 | MapCombiner combiner = new MapCombiner(); |
437 | 0 | combiner.setList(maps); |
438 | 0 | return Collections.unmodifiableMap(combiner); |
439 | |
} |
440 | |
|
441 | |
protected boolean getDeleteUnacceptedMessages(Connector connector) |
442 | |
{ |
443 | 0 | return deleteUnacceptedMessages != null |
444 | |
? deleteUnacceptedMessages.booleanValue() |
445 | |
: getDefaultDeleteUnacceptedMessages(connector); |
446 | |
} |
447 | |
|
448 | |
protected boolean getDefaultDeleteUnacceptedMessages(Connector connector) |
449 | |
{ |
450 | 0 | return false; |
451 | |
} |
452 | |
|
453 | |
protected String getEndpointEncoding(Connector connector) |
454 | |
{ |
455 | 0 | return encoding != null ? encoding : getDefaultEndpointEncoding(connector); |
456 | |
} |
457 | |
|
458 | |
protected String getDefaultEndpointEncoding(Connector connector) |
459 | |
{ |
460 | 0 | return muleContext.getConfiguration().getDefaultEncoding(); |
461 | |
} |
462 | |
|
463 | |
protected String getInitialState(Connector connector) |
464 | |
{ |
465 | 0 | return initialState != null ? initialState : getDefaultInitialState(connector); |
466 | |
} |
467 | |
|
468 | |
protected String getDefaultInitialState(Connector connector) |
469 | |
{ |
470 | 0 | return ImmutableEndpoint.INITIAL_STATE_STARTED; |
471 | |
} |
472 | |
|
473 | |
protected int getResponseTimeout(Connector connector) |
474 | |
{ |
475 | 0 | return responseTimeout != null ? responseTimeout.intValue() : getDefaultResponseTimeout(connector); |
476 | |
|
477 | |
} |
478 | |
|
479 | |
protected int getDefaultResponseTimeout(Connector connector) |
480 | |
{ |
481 | 0 | return muleContext.getConfiguration().getDefaultResponseTimeout(); |
482 | |
} |
483 | |
|
484 | |
protected List<Transformer> getTransformersFromUri(EndpointURI endpointURI) |
485 | |
throws TransportFactoryException |
486 | |
{ |
487 | 0 | if (endpointURI.getTransformers() != null) |
488 | |
{ |
489 | 0 | if (!CollectionUtils.containsType(messageProcessors, Transformer.class)) |
490 | |
{ |
491 | 0 | return getTransformersFromString(endpointURI.getTransformers()); |
492 | |
} |
493 | |
else |
494 | |
{ |
495 | 0 | logger.info("Endpoint with uri '" |
496 | |
+ endpointURI.toString() |
497 | |
+ "' has transformer(s) configured, transformers configured as uri paramaters will be ignored."); |
498 | |
} |
499 | |
} |
500 | 0 | return Collections.emptyList(); |
501 | |
} |
502 | |
|
503 | |
protected List<Transformer> getResponseTransformersFromUri(EndpointURI endpointURI) |
504 | |
throws TransportFactoryException |
505 | |
{ |
506 | 0 | if (endpointURI.getResponseTransformers() != null) |
507 | |
{ |
508 | 0 | if (!CollectionUtils.containsType(responseMessageProcessors, Transformer.class)) |
509 | |
{ |
510 | 0 | return getTransformersFromString(endpointURI.getResponseTransformers()); |
511 | |
} |
512 | |
else |
513 | |
{ |
514 | 0 | 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 | 0 | return Collections.emptyList(); |
520 | |
} |
521 | |
|
522 | |
protected String getMimeType() |
523 | |
{ |
524 | 0 | return mimeType; |
525 | |
} |
526 | |
|
527 | |
public void setMimeType(String mimeType) |
528 | |
{ |
529 | 0 | if (mimeType == null) |
530 | |
{ |
531 | 0 | this.mimeType = null; |
532 | |
} |
533 | |
else |
534 | |
{ |
535 | |
MimeType mt; |
536 | |
try |
537 | |
{ |
538 | 0 | mt = new MimeType(mimeType); |
539 | |
} |
540 | 0 | catch (MimeTypeParseException e) |
541 | |
{ |
542 | 0 | throw new IllegalArgumentException(e.getMessage(), e); |
543 | 0 | } |
544 | 0 | this.mimeType = mt.getPrimaryType() + "/" + mt.getSubType(); |
545 | |
} |
546 | 0 | } |
547 | |
|
548 | |
private List<Transformer> getTransformersFromString(String transformerString) throws TransportFactoryException |
549 | |
{ |
550 | |
try |
551 | |
{ |
552 | 0 | return TransformerUtils.getTransformers(transformerString, muleContext); |
553 | |
} |
554 | 0 | catch (DefaultMuleException e) |
555 | |
{ |
556 | 0 | throw new TransportFactoryException(e); |
557 | |
} |
558 | |
} |
559 | |
|
560 | |
private Connector getConnector(EndpointURI endpointURI) throws EndpointException |
561 | |
{ |
562 | 0 | String scheme = getScheme(); |
563 | 0 | TransportFactory factory = new TransportFactory(muleContext); |
564 | |
|
565 | |
Connector connector; |
566 | |
try |
567 | |
{ |
568 | 0 | if (uriBuilder.getEndpoint().getConnectorName() != null) |
569 | |
{ |
570 | 0 | connector = muleContext.getRegistry().lookupConnector( |
571 | |
uriBuilder.getEndpoint().getConnectorName()); |
572 | 0 | if (connector == null) |
573 | |
{ |
574 | 0 | throw new TransportFactoryException(CoreMessages.objectNotRegistered("Connector", |
575 | |
uriBuilder.getEndpoint().getConnectorName())); |
576 | |
} |
577 | |
} |
578 | 0 | else if (isAlwaysCreateConnector()) |
579 | |
{ |
580 | 0 | connector = factory.createConnector(endpointURI); |
581 | 0 | muleContext.getRegistry().registerConnector(connector); |
582 | |
} |
583 | |
else |
584 | |
{ |
585 | 0 | connector = factory.getConnectorByProtocol(scheme); |
586 | 0 | if (connector == null) |
587 | |
{ |
588 | 0 | connector = factory.createConnector(endpointURI); |
589 | 0 | muleContext.getRegistry().registerConnector(connector); |
590 | |
} |
591 | |
} |
592 | |
} |
593 | 0 | catch (Exception e) |
594 | |
{ |
595 | 0 | throw new TransportFactoryException(e); |
596 | 0 | } |
597 | |
|
598 | 0 | if (connector == null) |
599 | |
{ |
600 | 0 | Message m = CoreMessages.failedToCreateObjectWith("Endpoint", "endpointURI: " + endpointURI); |
601 | 0 | m.setNextMessage(CoreMessages.objectIsNull("connector")); |
602 | 0 | throw new TransportFactoryException(m); |
603 | |
|
604 | |
} |
605 | 0 | return connector; |
606 | |
} |
607 | |
|
608 | |
protected String getScheme() |
609 | |
{ |
610 | 0 | return uriBuilder.getEndpoint().getFullScheme(); |
611 | |
} |
612 | |
|
613 | |
|
614 | |
|
615 | |
|
616 | |
|
617 | |
|
618 | |
|
619 | |
|
620 | |
protected boolean isAlwaysCreateConnector() |
621 | |
{ |
622 | 0 | return false; |
623 | |
} |
624 | |
|
625 | |
|
626 | |
|
627 | |
public void setConnector(Connector connector) |
628 | |
{ |
629 | 0 | this.connector = connector; |
630 | 0 | } |
631 | |
|
632 | |
|
633 | |
@Deprecated |
634 | |
public void addTransformer(Transformer transformer) |
635 | |
{ |
636 | 0 | this.transformers.add(transformer); |
637 | 0 | } |
638 | |
|
639 | |
|
640 | |
@Deprecated |
641 | |
public void setTransformers(List<Transformer> newTransformers) |
642 | |
{ |
643 | 0 | if (newTransformers == null) |
644 | |
{ |
645 | 0 | newTransformers = new LinkedList<Transformer>(); |
646 | |
} |
647 | 0 | this.transformers = newTransformers; |
648 | 0 | } |
649 | |
|
650 | |
protected EndpointMessageProcessorChainFactory getMessageProcessorsFactory() |
651 | |
{ |
652 | 0 | return messageProcessorsFactory != null |
653 | |
? messageProcessorsFactory |
654 | |
: getDefaultMessageProcessorsFactory(); |
655 | |
} |
656 | |
|
657 | |
protected EndpointMessageProcessorChainFactory getDefaultMessageProcessorsFactory() |
658 | |
{ |
659 | 0 | return new DefaultEndpointMessageProcessorChainFactory(); |
660 | |
} |
661 | |
|
662 | |
|
663 | |
@Deprecated |
664 | |
public void addResponseTransformer(Transformer transformer) |
665 | |
{ |
666 | 0 | this.responseTransformers.add(transformer); |
667 | 0 | } |
668 | |
|
669 | |
|
670 | |
@Deprecated |
671 | |
public void setResponseTransformers(List<Transformer> newResponseTransformers) |
672 | |
{ |
673 | 0 | if (newResponseTransformers == null) |
674 | |
{ |
675 | 0 | newResponseTransformers = new LinkedList<Transformer>(); |
676 | |
} |
677 | 0 | this.responseTransformers = newResponseTransformers; |
678 | 0 | } |
679 | |
|
680 | |
public void addMessageProcessor(MessageProcessor messageProcessor) |
681 | |
{ |
682 | 0 | messageProcessors.add(messageProcessor); |
683 | 0 | } |
684 | |
|
685 | |
public void setMessageProcessors(List<MessageProcessor> newMessageProcessors) |
686 | |
{ |
687 | 0 | if (newMessageProcessors == null) |
688 | |
{ |
689 | 0 | newMessageProcessors = new LinkedList<MessageProcessor>(); |
690 | |
} |
691 | 0 | this.messageProcessors = newMessageProcessors; |
692 | 0 | } |
693 | |
|
694 | |
public List<MessageProcessor> getMessageProcessors() |
695 | |
{ |
696 | 0 | return messageProcessors; |
697 | |
} |
698 | |
|
699 | |
public void addResponseMessageProcessor(MessageProcessor messageProcessor) |
700 | |
{ |
701 | 0 | responseMessageProcessors.add(messageProcessor); |
702 | 0 | } |
703 | |
|
704 | |
public void setResponseMessageProcessors(List<MessageProcessor> newResponseMessageProcessors) |
705 | |
{ |
706 | 0 | if (newResponseMessageProcessors == null) |
707 | |
{ |
708 | 0 | newResponseMessageProcessors = new LinkedList<MessageProcessor>(); |
709 | |
} |
710 | 0 | this.responseMessageProcessors = newResponseMessageProcessors; |
711 | 0 | } |
712 | |
|
713 | |
public List<MessageProcessor> getResponseMessageProcessors() |
714 | |
{ |
715 | 0 | return responseMessageProcessors; |
716 | |
} |
717 | |
|
718 | |
protected boolean isDisableTransportTransformer() |
719 | |
{ |
720 | 0 | return disableTransportTransformer != null |
721 | |
? disableTransportTransformer.booleanValue() |
722 | |
: getDefaultDisableTransportTransformer(); |
723 | |
} |
724 | |
|
725 | |
protected boolean getDefaultDisableTransportTransformer() |
726 | |
{ |
727 | 0 | return false; |
728 | |
} |
729 | |
|
730 | |
public void setName(String name) |
731 | |
{ |
732 | 0 | this.name = name; |
733 | 0 | } |
734 | |
|
735 | |
|
736 | |
|
737 | |
|
738 | |
public void setProperties(Map<Object, Object> properties) |
739 | |
{ |
740 | 0 | if (null == this.properties) |
741 | |
{ |
742 | 0 | this.properties = new HashMap<Object, Object>(); |
743 | |
} |
744 | 0 | this.properties.putAll(properties); |
745 | 0 | } |
746 | |
|
747 | |
|
748 | |
|
749 | |
|
750 | |
|
751 | |
|
752 | |
|
753 | |
public void setProperty(Object key, Object value) |
754 | |
{ |
755 | 0 | properties.put(key, value); |
756 | 0 | } |
757 | |
|
758 | |
public void setTransactionConfig(TransactionConfig transactionConfig) |
759 | |
{ |
760 | 0 | this.transactionConfig = transactionConfig; |
761 | 0 | } |
762 | |
|
763 | |
public void setDeleteUnacceptedMessages(boolean deleteUnacceptedMessages) |
764 | |
{ |
765 | 0 | this.deleteUnacceptedMessages = Boolean.valueOf(deleteUnacceptedMessages); |
766 | 0 | } |
767 | |
|
768 | |
public void setExchangePattern(MessageExchangePattern mep) |
769 | |
{ |
770 | 0 | messageExchangePattern = mep; |
771 | 0 | } |
772 | |
|
773 | |
public void setResponseTimeout(int responseTimeout) |
774 | |
{ |
775 | 0 | this.responseTimeout = new Integer(responseTimeout); |
776 | 0 | } |
777 | |
|
778 | |
public void setInitialState(String initialState) |
779 | |
{ |
780 | 0 | this.initialState = initialState; |
781 | 0 | } |
782 | |
|
783 | |
public void setEncoding(String encoding) |
784 | |
{ |
785 | 0 | this.encoding = encoding; |
786 | 0 | } |
787 | |
|
788 | |
public void setCreateConnector(int createConnector) |
789 | |
{ |
790 | 0 | this.createConnector = new Integer(createConnector); |
791 | 0 | } |
792 | |
|
793 | |
public void setRegistryId(String registryId) |
794 | |
{ |
795 | 0 | this.registryId = registryId; |
796 | 0 | } |
797 | |
|
798 | |
public void setMuleContext(MuleContext muleContext) |
799 | |
{ |
800 | 0 | this.muleContext = muleContext; |
801 | 0 | } |
802 | |
|
803 | |
public void setRetryPolicyTemplate(RetryPolicyTemplate retryPolicyTemplate) |
804 | |
{ |
805 | 0 | this.retryPolicyTemplate = retryPolicyTemplate; |
806 | 0 | } |
807 | |
|
808 | |
public void setDisableTransportTransformer(boolean disableTransportTransformer) |
809 | |
{ |
810 | 0 | this.disableTransportTransformer = Boolean.valueOf(disableTransportTransformer); |
811 | 0 | } |
812 | |
|
813 | |
public URIBuilder getEndpointBuilder() |
814 | |
{ |
815 | 0 | return uriBuilder; |
816 | |
} |
817 | |
|
818 | |
public void setURIBuilder(URIBuilder URIBuilder) |
819 | |
{ |
820 | 0 | this.uriBuilder = URIBuilder; |
821 | 0 | } |
822 | |
|
823 | |
@Override |
824 | |
public int hashCode() |
825 | |
{ |
826 | 0 | 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 | 0 | if (this == obj) |
836 | |
{ |
837 | 0 | return true; |
838 | |
} |
839 | 0 | if (obj == null || getClass() != obj.getClass()) |
840 | |
{ |
841 | 0 | return false; |
842 | |
} |
843 | |
|
844 | 0 | final AbstractEndpointBuilder other = (AbstractEndpointBuilder)obj; |
845 | 0 | 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 | 0 | return ClassUtils.equal(a, b); |
864 | |
} |
865 | |
|
866 | |
@Override |
867 | |
public Object clone() throws CloneNotSupportedException |
868 | |
{ |
869 | 0 | EndpointBuilder builder = (EndpointBuilder)super.clone(); |
870 | 0 | builder.setConnector(connector); |
871 | 0 | builder.setURIBuilder(uriBuilder); |
872 | 0 | builder.setMessageProcessors(messageProcessors); |
873 | 0 | builder.setResponseMessageProcessors(responseMessageProcessors); |
874 | 0 | builder.setName(name); |
875 | 0 | builder.setProperties(properties); |
876 | 0 | builder.setTransactionConfig(transactionConfig); |
877 | 0 | builder.setInitialState(initialState); |
878 | 0 | builder.setEncoding(encoding); |
879 | 0 | builder.setRegistryId(registryId); |
880 | 0 | builder.setMuleContext(muleContext); |
881 | 0 | builder.setRetryPolicyTemplate(retryPolicyTemplate); |
882 | 0 | builder.setTransformers(transformers); |
883 | 0 | builder.setResponseTransformers(responseTransformers); |
884 | |
|
885 | 0 | if (deleteUnacceptedMessages != null) |
886 | |
{ |
887 | 0 | builder.setDeleteUnacceptedMessages(deleteUnacceptedMessages.booleanValue()); |
888 | |
} |
889 | 0 | if (messageExchangePattern != null) |
890 | |
{ |
891 | 0 | builder.setExchangePattern(messageExchangePattern); |
892 | |
} |
893 | |
|
894 | 0 | if (responseTimeout != null) |
895 | |
{ |
896 | 0 | builder.setResponseTimeout(responseTimeout.intValue()); |
897 | |
} |
898 | 0 | if (disableTransportTransformer != null) |
899 | |
{ |
900 | 0 | builder.setDisableTransportTransformer(disableTransportTransformer.booleanValue()); |
901 | |
} |
902 | |
|
903 | 0 | return builder; |
904 | |
} |
905 | |
|
906 | |
} |