001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel;
018
019import java.util.Date;
020import java.util.List;
021import java.util.Map;
022
023import org.apache.camel.spi.Synchronization;
024import org.apache.camel.spi.UnitOfWork;
025
026/**
027 * An Exchange is the message container holding the information during the entire routing of
028 * a {@link  Message} received by a {@link Consumer}. 
029 * <p/>
030 * During processing down the {@link Processor} chain, the {@link Exchange} provides access to the 
031 * current (not the original) request and response {@link Message} messages. The {@link Exchange} 
032 * also holds meta-data during its entire lifetime stored as properties accessible using the 
033 * various {@link #getProperty(String)} methods. The {@link #setProperty(String, Object)} is 
034 * used to store a property. For example you can use this to store security, SLA related 
035 * data or any other information deemed useful throughout processing. If an {@link Exchange} 
036 * failed during routing the {@link Exception} that caused the failure is stored and accessible 
037 * via the {@link #getException()} method.
038 * <p/>
039 * An Exchange is created when a {@link Consumer} receives a request. A new {@link Message} is
040 * created, the request is set as the body of the {@link Message} and depending on the {@link Consumer}
041 * other {@link Endpoint} and protocol related information is added as headers on the {@link Message}.
042 * Then an Exchange is created and the newly created {@link Message} is set as the in on the Exchange.
043 * Therefore an Exchange starts its life in a {@link Consumer}. The Exchange is then sent down the
044 * {@link Route} for processing along a {@link Processor} chain. The {@link Processor} as the name
045 * suggests is what processes the {@link Message} in the Exchange and Camel, in addition to 
046 * providing out-of-the-box a large number of useful processors, it also allows you to create your own. 
047 * The rule Camel uses is to take the out {@link Message} produced by the previous {@link Processor} 
048 * and set it as the in for the next {@link Processor}. If the previous {@link Processor} did not
049 * produce an out, then the in of the previous {@link Processor} is sent as the next in. At the
050 * end of the processing chain, depending on the {@link ExchangePattern Message Exchange Pattern} (or MEP)
051 * the last out (or in of no out available) is sent by the {@link Consumer} back to the original caller.
052 * <p/>
053 * Camel, in addition to providing out-of-the-box a large number of useful processors, it also allows 
054 * you to implement and use your own. When the Exchange is passed to a {@link Processor}, it always 
055 * contains an in {@link Message} and no out {@link Message}. The {@link Processor} <b>may</b> produce 
056 * an out, depending on the nature of the {@link Processor}. The in {@link Message} can be accessed 
057 * using the {@link #getIn()} method. Since the out message is null when entering the {@link Processor}, 
058 * the {@link #getOut()} method is actually a convenient factory method that will lazily instantiate a 
059 * {@link org.apache.camel.support.DefaultMessage} which you could populate. As an alternative you could
060 * also instantiate your specialized  {@link Message} and set it on the exchange using the 
061 * {@link #setOut(org.apache.camel.Message)} method. Please note that a {@link Message} contains not only 
062 * the body but also headers and attachments. If you are creating a new {@link Message} the headers and 
063 * attachments of the in {@link Message} are not automatically copied to the out by Camel and you'll have 
064 * to set the headers and attachments you need yourself. If your {@link Processor} is not producing a 
065 * different {@link Message} but only needs to slightly  modify the in, you can simply update the in 
066 * {@link Message} returned by {@link #getIn()}. 
067 * <p/>
068 * See this <a href="http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html">FAQ entry</a> 
069 * for more details.
070 */
071public interface Exchange {
072
073    String AUTHENTICATION                   = "CamelAuthentication";
074    String AUTHENTICATION_FAILURE_POLICY_ID = "CamelAuthenticationFailurePolicyId";
075    @Deprecated
076    String ACCEPT_CONTENT_TYPE              = "CamelAcceptContentType";
077    String AGGREGATED_SIZE                  = "CamelAggregatedSize";
078    String AGGREGATED_TIMEOUT               = "CamelAggregatedTimeout";
079    String AGGREGATED_COMPLETED_BY          = "CamelAggregatedCompletedBy";
080    String AGGREGATED_CORRELATION_KEY       = "CamelAggregatedCorrelationKey";
081    String AGGREGATED_COLLECTION_GUARD      = "CamelAggregatedCollectionGuard";
082    String AGGREGATION_STRATEGY             = "CamelAggregationStrategy";
083    String AGGREGATION_COMPLETE_CURRENT_GROUP = "CamelAggregationCompleteCurrentGroup";
084    String AGGREGATION_COMPLETE_ALL_GROUPS  = "CamelAggregationCompleteAllGroups";
085    String AGGREGATION_COMPLETE_ALL_GROUPS_INCLUSIVE  = "CamelAggregationCompleteAllGroupsInclusive";
086    String ASYNC_WAIT                       = "CamelAsyncWait";
087
088    String BATCH_INDEX                = "CamelBatchIndex";
089    String BATCH_SIZE                 = "CamelBatchSize";
090    String BATCH_COMPLETE             = "CamelBatchComplete";
091    String BEAN_METHOD_NAME           = "CamelBeanMethodName";
092    String BINDING                    = "CamelBinding";
093    // do not prefix with Camel and use lower-case starting letter as its a shared key
094    // used across other Apache products such as AMQ, SMX etc.
095    String BREADCRUMB_ID              = "breadcrumbId";
096
097    String CHARSET_NAME           = "CamelCharsetName";
098    String CIRCUIT_BREAKER_STATE  = "CamelCircuitBreakerState";
099    String CREATED_TIMESTAMP      = "CamelCreatedTimestamp";
100    String CLAIM_CHECK_REPOSITORY = "CamelClaimCheckRepository";
101    String CONTENT_ENCODING       = "Content-Encoding";
102    String CONTENT_LENGTH         = "Content-Length";
103    String CONTENT_TYPE           = "Content-Type";
104    String COOKIE_HANDLER         = "CamelCookieHandler";
105    String CORRELATION_ID         = "CamelCorrelationId";
106
107    String DATASET_INDEX             = "CamelDataSetIndex";
108    String DEFAULT_CHARSET_PROPERTY  = "org.apache.camel.default.charset";
109    String DESTINATION_OVERRIDE_URL = "CamelDestinationOverrideUrl";
110    String DISABLE_HTTP_STREAM_CACHE = "CamelDisableHttpStreamCache";
111    String DUPLICATE_MESSAGE         = "CamelDuplicateMessage";
112    
113    String DOCUMENT_BUILDER_FACTORY = "CamelDocumentBuilderFactory";
114
115    String EXCEPTION_CAUGHT              = "CamelExceptionCaught";
116    String EXCEPTION_HANDLED             = "CamelExceptionHandled";
117    String EVALUATE_EXPRESSION_RESULT    = "CamelEvaluateExpressionResult";
118    String ERRORHANDLER_CIRCUIT_DETECTED = "CamelFErrorHandlerCircuitDetected";
119    String ERRORHANDLER_HANDLED          = "CamelErrorHandlerHandled";
120    String EXTERNAL_REDELIVERED          = "CamelExternalRedelivered";
121
122    String FAILURE_HANDLED      = "CamelFailureHandled";
123    String FAILURE_ENDPOINT     = "CamelFailureEndpoint";
124    String FAILURE_ROUTE_ID     = "CamelFailureRouteId";
125    String FATAL_FALLBACK_ERROR_HANDLER  = "CamelFatalFallbackErrorHandler";
126    String FILE_CONTENT_TYPE    = "CamelFileContentType";
127    String FILE_LOCAL_WORK_PATH = "CamelFileLocalWorkPath";
128    String FILE_NAME            = "CamelFileName";
129    String FILE_NAME_ONLY       = "CamelFileNameOnly";
130    String FILE_NAME_PRODUCED   = "CamelFileNameProduced";
131    String FILE_NAME_CONSUMED   = "CamelFileNameConsumed";
132    String FILE_PATH            = "CamelFilePath";
133    String FILE_PARENT          = "CamelFileParent";
134    String FILE_LAST_MODIFIED   = "CamelFileLastModified";
135    String FILE_LENGTH          = "CamelFileLength";
136    String FILE_LOCK_FILE_ACQUIRED = "CamelFileLockFileAcquired";
137    String FILE_LOCK_FILE_NAME  = "CamelFileLockFileName";
138    String FILE_LOCK_EXCLUSIVE_LOCK = "CamelFileLockExclusiveLock";
139    String FILE_LOCK_RANDOM_ACCESS_FILE = "CamelFileLockRandomAccessFile";
140    String FILTER_MATCHED       = "CamelFilterMatched";
141    String FILTER_NON_XML_CHARS = "CamelFilterNonXmlChars";
142
143    String GROUPED_EXCHANGE = "CamelGroupedExchange";
144    
145    String HTTP_BASE_URI           = "CamelHttpBaseUri";
146    String HTTP_CHARACTER_ENCODING = "CamelHttpCharacterEncoding";
147    String HTTP_METHOD             = "CamelHttpMethod";
148    String HTTP_PATH               = "CamelHttpPath";
149    String HTTP_PROTOCOL_VERSION   = "CamelHttpProtocolVersion";
150    String HTTP_QUERY              = "CamelHttpQuery";
151    String HTTP_RAW_QUERY          = "CamelHttpRawQuery";
152    String HTTP_RESPONSE_CODE      = "CamelHttpResponseCode";
153    String HTTP_RESPONSE_TEXT      = "CamelHttpResponseText";
154    String HTTP_URI                = "CamelHttpUri";
155    String HTTP_URL                = "CamelHttpUrl";
156    String HTTP_CHUNKED            = "CamelHttpChunked";
157    String HTTP_SERVLET_REQUEST    = "CamelHttpServletRequest";
158    String HTTP_SERVLET_RESPONSE   = "CamelHttpServletResponse";
159
160    String INTERCEPTED_ENDPOINT = "CamelInterceptedEndpoint";
161    String INTERCEPT_SEND_TO_ENDPOINT_WHEN_MATCHED = "CamelInterceptSendToEndpointWhenMatched";
162    String INTERRUPTED = "CamelInterrupted";
163
164    String LANGUAGE_SCRIPT          = "CamelLanguageScript";
165    String LOG_DEBUG_BODY_MAX_CHARS = "CamelLogDebugBodyMaxChars";
166    String LOG_DEBUG_BODY_STREAMS   = "CamelLogDebugStreams";
167    String LOG_EIP_NAME             = "CamelLogEipName";
168    String LOOP_INDEX               = "CamelLoopIndex";
169    String LOOP_SIZE                = "CamelLoopSize";
170
171    // Long running action (saga): using "Long-Running-Action" as header value allows sagas
172    // to be propagated to any remote system supporting the LRA framework
173    String SAGA_LONG_RUNNING_ACTION = "Long-Running-Action";
174
175    String MAXIMUM_CACHE_POOL_SIZE     = "CamelMaximumCachePoolSize";
176    String MAXIMUM_ENDPOINT_CACHE_SIZE = "CamelMaximumEndpointCacheSize";
177    String MAXIMUM_SIMPLE_CACHE_SIZE = "CamelMaximumSimpleCacheSize";
178    String MAXIMUM_TRANSFORMER_CACHE_SIZE = "CamelMaximumTransformerCacheSize";
179    String MAXIMUM_VALIDATOR_CACHE_SIZE = "CamelMaximumValidatorCacheSize";
180    String MESSAGE_HISTORY             = "CamelMessageHistory";
181    String MESSAGE_HISTORY_HEADER_FORMAT      = "CamelMessageHistoryHeaderFormat";
182    String MESSAGE_HISTORY_OUTPUT_FORMAT      = "CamelMessageHistoryOutputFormat";
183    String MULTICAST_INDEX             = "CamelMulticastIndex";
184    String MULTICAST_COMPLETE          = "CamelMulticastComplete";
185
186    String NOTIFY_EVENT = "CamelNotifyEvent";
187
188    String ON_COMPLETION      = "CamelOnCompletion";
189    String OVERRULE_FILE_NAME = "CamelOverruleFileName";
190
191    String PARENT_UNIT_OF_WORK = "CamelParentUnitOfWork";
192    String STREAM_CACHE_UNIT_OF_WORK = "CamelStreamCacheUnitOfWork";
193    
194    String RECIPIENT_LIST_ENDPOINT = "CamelRecipientListEndpoint";
195    String RECEIVED_TIMESTAMP      = "CamelReceivedTimestamp";
196    String REDELIVERED             = "CamelRedelivered";
197    String REDELIVERY_COUNTER      = "CamelRedeliveryCounter";
198    String REDELIVERY_MAX_COUNTER  = "CamelRedeliveryMaxCounter";
199    String REDELIVERY_EXHAUSTED    = "CamelRedeliveryExhausted";
200    String REDELIVERY_DELAY        = "CamelRedeliveryDelay";
201    String REST_HTTP_URI           = "CamelRestHttpUri";
202    String REST_HTTP_QUERY         = "CamelRestHttpQuery";
203    String ROLLBACK_ONLY           = "CamelRollbackOnly";
204    String ROLLBACK_ONLY_LAST      = "CamelRollbackOnlyLast";
205    String ROUTE_STOP              = "CamelRouteStop";
206
207    String REUSE_SCRIPT_ENGINE = "CamelReuseScripteEngine";
208    String COMPILE_SCRIPT = "CamelCompileScript";
209    
210    String SAXPARSER_FACTORY   = "CamelSAXParserFactory";
211
212    String SCHEDULER_POLLED_MESSAGES = "CamelSchedulerPolledMessages";
213    String SOAP_ACTION        = "CamelSoapAction";
214    String SKIP_GZIP_ENCODING = "CamelSkipGzipEncoding";
215    String SKIP_WWW_FORM_URLENCODED = "CamelSkipWwwFormUrlEncoding"; 
216    String SLIP_ENDPOINT      = "CamelSlipEndpoint";
217    String SLIP_PRODUCER      = "CamelSlipProducer";
218    String SPLIT_INDEX        = "CamelSplitIndex";
219    String SPLIT_COMPLETE     = "CamelSplitComplete";
220    String SPLIT_SIZE         = "CamelSplitSize";
221    String STEP_ID            = "CamelStepId";
222
223    String TIMER_COUNTER         = "CamelTimerCounter";
224    String TIMER_FIRED_TIME      = "CamelTimerFiredTime";
225    String TIMER_NAME            = "CamelTimerName";
226    String TIMER_PERIOD          = "CamelTimerPeriod";
227    String TIMER_TIME            = "CamelTimerTime";
228    String TO_ENDPOINT           = "CamelToEndpoint";
229    String TRACE_EVENT           = "CamelTraceEvent";
230    String TRACE_EVENT_NODE_ID   = "CamelTraceEventNodeId";
231    String TRACE_EVENT_TIMESTAMP = "CamelTraceEventTimestamp";
232    String TRACE_EVENT_EXCHANGE  = "CamelTraceEventExchange";
233    String TRY_ROUTE_BLOCK       = "TryRouteBlock";
234    String TRANSFER_ENCODING     = "Transfer-Encoding";
235
236    String UNIT_OF_WORK_EXHAUSTED    = "CamelUnitOfWorkExhausted";
237    
238    /**
239     * @deprecated UNIT_OF_WORK_PROCESS_SYNC is not in use and will be removed in future Camel release
240     */
241    @Deprecated
242    String UNIT_OF_WORK_PROCESS_SYNC = "CamelUnitOfWorkProcessSync";
243
244    String XSLT_FILE_NAME   = "CamelXsltFileName";
245    String XSLT_ERROR       = "CamelXsltError";
246    String XSLT_FATAL_ERROR = "CamelXsltFatalError";
247    String XSLT_WARNING     = "CamelXsltWarning";
248
249    /**
250     * Returns the {@link ExchangePattern} (MEP) of this exchange.
251     *
252     * @return the message exchange pattern of this exchange
253     */
254    ExchangePattern getPattern();
255
256    /**
257     * Allows the {@link ExchangePattern} (MEP) of this exchange to be customized.
258     *
259     * This typically won't be required as an exchange can be created with a specific MEP
260     * by calling {@link Endpoint#createExchange(ExchangePattern)} but it is here just in case
261     * it is needed.
262     *
263     * @param pattern  the pattern 
264     */
265    void setPattern(ExchangePattern pattern);
266
267    /**
268     * Returns a property associated with this exchange by name
269     *
270     * @param name the name of the property
271     * @return the value of the given property or <tt>null</tt> if there is no property for
272     *         the given name
273     */
274    Object getProperty(String name);
275
276    /**
277     * Returns a property associated with this exchange by name
278     *
279     * @param name the name of the property
280     * @param defaultValue the default value to return if property was absent
281     * @return the value of the given property or <tt>defaultValue</tt> if there is no
282     *         property for the given name
283     */
284    Object getProperty(String name, Object defaultValue);
285
286    /**
287     * Returns a property associated with this exchange by name and specifying
288     * the type required
289     *
290     * @param name the name of the property
291     * @param type the type of the property
292     * @return the value of the given property or <tt>null</tt> if there is no property for
293     *         the given name or <tt>null</tt> if it cannot be converted to the given type
294     */
295    <T> T getProperty(String name, Class<T> type);
296
297    /**
298     * Returns a property associated with this exchange by name and specifying
299     * the type required
300     *
301     * @param name the name of the property
302     * @param defaultValue the default value to return if property was absent
303     * @param type the type of the property
304     * @return the value of the given property or <tt>defaultValue</tt> if there is no property for
305     *         the given name or <tt>null</tt> if it cannot be converted to the given type
306     */
307    <T> T getProperty(String name, Object defaultValue, Class<T> type);
308
309    /**
310     * Sets a property on the exchange
311     *
312     * @param name  of the property
313     * @param value to associate with the name
314     */
315    void setProperty(String name, Object value);
316
317    /**
318     * Removes the given property on the exchange
319     *
320     * @param name of the property
321     * @return the old value of the property
322     */
323    Object removeProperty(String name);
324
325    /**
326     * Remove all of the properties associated with the exchange matching a specific pattern
327     *
328     * @param pattern pattern of names
329     * @return boolean whether any properties matched
330     */
331    boolean removeProperties(String pattern);
332    
333    /**
334     * Removes the properties from this exchange that match the given <tt>pattern</tt>, 
335     * except for the ones matching one ore more <tt>excludePatterns</tt>
336     * 
337     * @param pattern pattern of names that should be removed
338     * @param excludePatterns one or more pattern of properties names that should be excluded (= preserved)
339     * @return boolean whether any properties matched
340     */ 
341    boolean removeProperties(String pattern, String... excludePatterns);
342    
343    /**
344     * Returns all of the properties associated with the exchange
345     *
346     * @return all the headers in a Map
347     */
348    Map<String, Object> getProperties();
349
350    /**
351     * Returns whether any properties has been set
352     *
353     * @return <tt>true</tt> if any properties has been set
354     */
355    boolean hasProperties();
356
357    /**
358     * Returns the inbound request message
359     *
360     * @return the message
361     */
362    Message getIn();
363
364    /**
365     * Returns the current message
366     *
367     * @return the current message
368     */
369    Message getMessage();
370
371    /**
372     * Returns the current message as the given type
373     *
374     * @param type the given type
375     * @return the message as the given type or <tt>null</tt> if not possible to covert to given type
376     */
377    <T> T getMessage(Class<T> type);
378
379    /**
380     * Replace the current message instance.
381     *
382     * @param message the new message
383     */
384    void setMessage(Message message);
385
386    /**
387     * Returns the inbound request message as the given type
388     *
389     * @param type the given type
390     * @return the message as the given type or <tt>null</tt> if not possible to covert to given type
391     */
392    <T> T getIn(Class<T> type);
393
394    /**
395     * Sets the inbound message instance
396     *
397     * @param in the inbound message
398     */
399    void setIn(Message in);
400
401    /**
402     * Returns the outbound message, lazily creating one if one has not already
403     * been associated with this exchange.
404     * <p/>
405     * <br/><b>Important:</b> If you want to change the current message, then use {@link #getIn()} instead as it will
406     * ensure headers etc. is kept and propagated when routing continues. Bottom line end users should rarely use
407     * this method.
408     * <p/>
409     * <br/>If you want to test whether an OUT message have been set or not, use the {@link #hasOut()} method.
410     * <p/>
411     * See also the class java doc for this {@link Exchange} for more details and this
412     * <a href="http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html">FAQ entry</a>.
413     *
414     * @return the response
415     * @see #getIn()
416     */
417    Message getOut();
418
419    /**
420     * Returns the outbound request message as the given type
421     * <p/>
422     * <br/><b>Important:</b> If you want to change the current message, then use {@link #getIn()} instead as it will
423     * ensure headers etc. is kept and propagated when routing continues. Bottom line end users should rarely use
424     * this method.
425     * <p/>
426     * <br/>If you want to test whether an OUT message have been set or not, use the {@link #hasOut()} method.
427     * <p/>
428     * See also the class java doc for this {@link Exchange} for more details and this
429     * <a href="http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html">FAQ entry</a>.
430     *
431     * @param type the given type
432     * @return the message as the given type or <tt>null</tt> if not possible to covert to given type
433     * @see #getIn(Class)
434     */
435    <T> T getOut(Class<T> type);
436
437    /**
438     * Returns whether an OUT message has been set or not.
439     *
440     * @return <tt>true</tt> if an OUT message exists, <tt>false</tt> otherwise.
441     */
442    boolean hasOut();
443
444    /**
445     * Sets the outbound message
446     *
447     * @param out the outbound message
448     */
449    void setOut(Message out);
450
451    /**
452     * Returns the exception associated with this exchange
453     *
454     * @return the exception (or null if no faults)
455     */
456    Exception getException();
457
458    /**
459     * Returns the exception associated with this exchange.
460     * <p/>
461     * Is used to get the caused exception that typically have been wrapped in some sort
462     * of Camel wrapper exception
463     * <p/>
464     * The strategy is to look in the exception hierarchy to find the first given cause that matches the type.
465     * Will start from the bottom (the real cause) and walk upwards.
466     *
467     * @param type the exception type
468     * @return the exception (or <tt>null</tt> if no caused exception matched)
469     */
470    <T> T getException(Class<T> type);
471
472    /**
473     * Sets the exception associated with this exchange
474     * <p/>
475     * Camel will wrap {@link Throwable} into {@link Exception} type to
476     * accommodate for the {@link #getException()} method returning a plain {@link Exception} type.
477     *
478     * @param t  the caused exception
479     */
480    void setException(Throwable t);
481
482    /**
483     * Returns true if this exchange failed due to either an exception or fault
484     *
485     * @return true if this exchange failed due to either an exception or fault
486     * @see Exchange#getException()
487     * @see Message#setFault(boolean)
488     * @see Message#isFault()
489     */
490    boolean isFailed();
491
492    /**
493     * Returns true if this exchange is transacted
494     */
495    boolean isTransacted();
496
497    /**
498     * Returns true if this exchange is an external initiated redelivered message (such as a JMS broker).
499     * <p/>
500     * <b>Important: </b> It is not always possible to determine if the message is a redelivery
501     * or not, and therefore <tt>null</tt> is returned. Such an example would be a JDBC message.
502     * However JMS brokers provides details if a message is redelivered.
503     *
504     * @return <tt>true</tt> if redelivered, <tt>false</tt> if not, <tt>null</tt> if not able to determine
505     */
506    Boolean isExternalRedelivered();
507
508    /**
509     * Returns true if this exchange is marked for rollback
510     */
511    boolean isRollbackOnly();
512
513    /**
514     * Returns the container so that a processor can resolve endpoints from URIs
515     *
516     * @return the container which owns this exchange
517     */
518    CamelContext getContext();
519
520    /**
521     * Creates a copy of the current message exchange so that it can be
522     * forwarded to another destination
523     */
524    Exchange copy();
525
526    /**
527     * Returns the endpoint which originated this message exchange if a consumer on an endpoint
528     * created the message exchange, otherwise this property will be <tt>null</tt>
529     */
530    Endpoint getFromEndpoint();
531
532    /**
533     * Sets the endpoint which originated this message exchange. This method
534     * should typically only be called by {@link org.apache.camel.Endpoint} implementations
535     *
536     * @param fromEndpoint the endpoint which is originating this message exchange
537     */
538    void setFromEndpoint(Endpoint fromEndpoint);
539    
540    /**
541     * Returns the route id which originated this message exchange if a route consumer on an endpoint
542     * created the message exchange, otherwise this property will be <tt>null</tt>
543     */
544    String getFromRouteId();
545
546    /**
547     * Sets the route id which originated this message exchange. This method
548     * should typically only be called by the internal framework.
549     *
550     * @param fromRouteId the from route id
551     */
552    void setFromRouteId(String fromRouteId);
553
554    /**
555     * Returns the unit of work that this exchange belongs to; which may map to
556     * zero, one or more physical transactions
557     */
558    UnitOfWork getUnitOfWork();
559
560    /**
561     * Sets the unit of work that this exchange belongs to; which may map to
562     * zero, one or more physical transactions
563     */
564    void setUnitOfWork(UnitOfWork unitOfWork);
565
566    /**
567     * Returns the exchange id (unique)
568     */
569    String getExchangeId();
570
571    /**
572     * Set the exchange id
573     */
574    void setExchangeId(String id);
575
576    /**
577     * Adds a {@link org.apache.camel.spi.Synchronization} to be invoked as callback when
578     * this exchange is completed.
579     *
580     * @param onCompletion  the callback to invoke on completion of this exchange
581     */
582    void addOnCompletion(Synchronization onCompletion);
583
584    /**
585     * Checks if the passed {@link org.apache.camel.spi.Synchronization} instance is
586     * already contained on this exchange.
587     *
588     * @param onCompletion  the callback instance that is being checked for
589     * @return <tt>true</tt>, if callback instance is already contained on this exchange, else <tt>false</tt>
590     */
591    boolean containsOnCompletion(Synchronization onCompletion);
592
593    /**
594     * Handover all the on completions from this exchange to the target exchange.
595     *
596     * @param target the target exchange
597     */
598    void handoverCompletions(Exchange target);
599
600    /**
601     * Handover all the on completions from this exchange
602     *
603     * @return the on completions
604     */
605    List<Synchronization> handoverCompletions();
606
607    /**
608     * Gets the timestamp when this exchange was created.
609     */
610    Date getCreated();
611
612}