@ConstantProvider(value="org.apache.camel.ExchangeConstantProvider") public interface Exchange
Message
received
by a Consumer
.
During processing down the Processor
chain, the Exchange
provides access to the current (not the
original) request and response Message
messages. The Exchange
also holds meta-data during its entire
lifetime stored as properties accessible using the various getProperty(String)
methods. The
setProperty(String, Object)
is used to store a property. For example you can use this to store security, SLA
related data or any other information deemed useful throughout processing. If an Exchange
failed during
routing the Exception
that caused the failure is stored and accessible via the getException()
method.
An Exchange is created when a Consumer
receives a request. A new Message
is created, the request is
set as the body of the Message
and depending on the Consumer
other Endpoint
and protocol
related information is added as headers on the Message
. Then an Exchange is created and the newly created
Message
is set as the in on the Exchange. Therefore an Exchange starts its life in a Consumer
. The
Exchange is then sent down the Route
for processing along a Processor
chain. The Processor
as
the name suggests is what processes the Message
in the Exchange and Camel, in addition to providing
out-of-the-box a large number of useful processors, it also allows you to create your own. The rule Camel uses is to
take the out Message
produced by the previous Processor
and set it as the in for the next
Processor
. If the previous Processor
did not produce an out, then the in of the previous
Processor
is sent as the next in. At the end of the processing chain, depending on the Message Exchange Pattern
(or MEP) the last out (or in of no out available) is sent by the Consumer
back to
the original caller.
Camel, in addition to providing out-of-the-box a large number of useful processors, it also allows you to implement
and use your own. When the Exchange is passed to a Processor
, it always contains an in Message
and no
out Message
. The Processor
may produce an out, depending on the nature of the
Processor
. The in Message
can be accessed using the getIn()
method. Since the out message is
null when entering the Processor
, the getOut()
method is actually a convenient factory method that
will lazily instantiate a org.apache.camel.support.DefaultMessage
which you could populate. As an alternative
you could also instantiate your specialized Message
and set it on the exchange using the
setOut(org.apache.camel.Message)
method. Please note that a Message
contains not only the body but
also headers and attachments. If you are creating a new Message
the headers and attachments of the in
Message
are not automatically copied to the out by Camel and you'll have to set the headers and attachments
you need yourself. If your Processor
is not producing a different Message
but only needs to slightly
modify the in, you can simply update the in Message
returned by getIn()
.
See this FAQ entry for more
details.Modifier and Type | Method and Description |
---|---|
<T extends Exchange> |
adapt(Class<T> type)
Adapts this
Exchange to the specialized type. |
Exchange |
copy()
Creates a copy of the current message exchange so that it can be forwarded to another destination
|
Map<String,Object> |
getAllProperties()
Returns all (both internal and custom) properties associated with the exchange
|
CamelContext |
getContext()
Returns the container so that a processor can resolve endpoints from URIs
|
long |
getCreated()
Gets the timestamp in millis when this exchange was created.
|
Exception |
getException()
Returns the exception associated with this exchange
|
<T> T |
getException(Class<T> type)
Returns the exception associated with this exchange.
|
String |
getExchangeId()
Returns the exchange id (unique)
|
Endpoint |
getFromEndpoint()
Returns the endpoint which originated this message exchange if a consumer on an endpoint created the message
exchange, otherwise his property will be null.
|
String |
getFromRouteId()
Returns the route id which originated this message exchange if a route consumer on an endpoint created the
message exchange, otherwise his property will be null.
|
Message |
getIn()
Returns the inbound request message
|
<T> T |
getIn(Class<T> type)
Returns the inbound request message as the given type
|
Message |
getMessage()
Returns the current message
|
<T> T |
getMessage(Class<T> type)
Returns the current message as the given type
|
Message |
getOut()
Deprecated.
use
getMessage() |
<T> T |
getOut(Class<T> type)
Deprecated.
|
ExchangePattern |
getPattern()
Returns the
ExchangePattern (MEP) of this exchange. |
Map<String,Object> |
getProperties()
Returns the properties associated with the exchange
|
Object |
getProperty(ExchangePropertyKey key)
Returns a property associated with this exchange by the key
|
<T> T |
getProperty(ExchangePropertyKey key,
Class<T> type)
Returns a property associated with this exchange by the key and specifying the type required
|
<T> T |
getProperty(ExchangePropertyKey key,
Object defaultValue,
Class<T> type)
Returns a property associated with this exchange by name and specifying the type required
|
Object |
getProperty(String name)
Returns a property associated with this exchange by name
|
<T> T |
getProperty(String name,
Class<T> type)
Returns a property associated with this exchange by name and specifying the type required
|
Object |
getProperty(String name,
Object defaultValue)
Deprecated.
|
<T> T |
getProperty(String name,
Object defaultValue,
Class<T> type)
Returns a property associated with this exchange by name and specifying the type required
|
UnitOfWork |
getUnitOfWork()
Returns the unit of work that this exchange belongs to; which may map to zero, one or more physical transactions
|
boolean |
hasOut()
Deprecated.
use
getMessage() |
boolean |
hasProperties()
Returns whether any properties has been set
|
boolean |
isExternalRedelivered()
Returns true if this exchange is an external initiated redelivered message (such as a JMS broker).
|
boolean |
isFailed()
Returns true if this exchange failed due to an exception
|
boolean |
isRollbackOnly()
Returns true if this exchange is marked for rollback
|
boolean |
isRollbackOnlyLast()
Returns true if this exchange is marked for rollback (only last transaction section)
|
boolean |
isRouteStop()
Returns true if this exchange is marked to stop and not continue routing.
|
boolean |
isTransacted()
Returns true if this exchange is transacted
|
boolean |
removeProperties(String pattern)
Remove all the properties associated with the exchange matching a specific pattern
|
boolean |
removeProperties(String pattern,
String... excludePatterns)
Removes the properties from this exchange that match the given pattern, except for the ones matching one
or more excludePatterns
|
Object |
removeProperty(ExchangePropertyKey key)
Removes the given property on the exchange
|
Object |
removeProperty(String name)
Removes the given property on the exchange
|
void |
setException(Throwable t)
Sets the exception associated with this exchange
Camel will wrap
Throwable into Exception type to accommodate for the getException()
method returning a plain Exception type. |
void |
setExchangeId(String id)
Set the exchange id
|
void |
setIn(Message in)
Sets the inbound message instance
|
void |
setMessage(Message message)
Replace the current message instance.
|
void |
setOut(Message out)
Deprecated.
|
void |
setPattern(ExchangePattern pattern)
Allows the
ExchangePattern (MEP) of this exchange to be customized. |
void |
setProperty(ExchangePropertyKey key,
Object value)
Sets a property on the exchange
|
void |
setProperty(String name,
Object value)
Sets a property on the exchange
|
void |
setRollbackOnly(boolean rollbackOnly)
Sets whether to mark this exchange for rollback
|
void |
setRollbackOnlyLast(boolean rollbackOnlyLast)
Sets whether to mark this exchange for rollback (only last transaction section)
|
void |
setRouteStop(boolean routeStop)
Sets whether this exchange is marked to stop and not continue routing.
|
static final String AUTHENTICATION
static final String AUTHENTICATION_FAILURE_POLICY_ID
@Deprecated static final String ACCEPT_CONTENT_TYPE
static final String AGGREGATED_SIZE
static final String AGGREGATED_TIMEOUT
static final String AGGREGATED_COMPLETED_BY
static final String AGGREGATED_CORRELATION_KEY
static final String AGGREGATED_COLLECTION_GUARD
static final String AGGREGATION_STRATEGY
static final String AGGREGATION_COMPLETE_CURRENT_GROUP
static final String AGGREGATION_COMPLETE_ALL_GROUPS
static final String AGGREGATION_COMPLETE_ALL_GROUPS_INCLUSIVE
static final String ASYNC_WAIT
static final String BATCH_INDEX
static final String BATCH_SIZE
static final String BATCH_COMPLETE
static final String BEAN_METHOD_NAME
static final String BINDING
static final String BREADCRUMB_ID
static final String CHARSET_NAME
static final String CIRCUIT_BREAKER_STATE
@Deprecated static final String CREATED_TIMESTAMP
static final String CLAIM_CHECK_REPOSITORY
static final String CONTENT_ENCODING
static final String CONTENT_LENGTH
static final String CONTENT_TYPE
static final String COOKIE_HANDLER
static final String CORRELATION_ID
static final String DATASET_INDEX
static final String DEFAULT_CHARSET_PROPERTY
static final String DESTINATION_OVERRIDE_URL
static final String DISABLE_HTTP_STREAM_CACHE
static final String DUPLICATE_MESSAGE
static final String DOCUMENT_BUILDER_FACTORY
static final String EXCEPTION_CAUGHT
static final String EXCEPTION_HANDLED
static final String EVALUATE_EXPRESSION_RESULT
static final String ERRORHANDLER_BRIDGE
static final String ERRORHANDLER_CIRCUIT_DETECTED
@Deprecated static final String ERRORHANDLER_HANDLED
@Deprecated static final String EXTERNAL_REDELIVERED
static final String FAILURE_HANDLED
static final String FAILURE_ENDPOINT
static final String FAILURE_ROUTE_ID
static final String FATAL_FALLBACK_ERROR_HANDLER
static final String FILE_CONTENT_TYPE
static final String FILE_LOCAL_WORK_PATH
static final String FILE_NAME
static final String FILE_NAME_ONLY
static final String FILE_NAME_PRODUCED
static final String FILE_NAME_CONSUMED
static final String FILE_PATH
static final String FILE_PARENT
static final String FILE_LAST_MODIFIED
static final String FILE_LENGTH
static final String FILE_LOCK_FILE_ACQUIRED
static final String FILE_LOCK_FILE_NAME
static final String FILE_LOCK_EXCLUSIVE_LOCK
static final String FILE_LOCK_RANDOM_ACCESS_FILE
static final String FILE_LOCK_CHANNEL_FILE
@Deprecated static final String FILTER_MATCHED
static final String FILTER_NON_XML_CHARS
static final String GROUPED_EXCHANGE
static final String HTTP_SCHEME
static final String HTTP_HOST
static final String HTTP_PORT
static final String HTTP_BASE_URI
static final String HTTP_CHARACTER_ENCODING
static final String HTTP_METHOD
static final String HTTP_PATH
static final String HTTP_PROTOCOL_VERSION
static final String HTTP_QUERY
static final String HTTP_RAW_QUERY
static final String HTTP_RESPONSE_CODE
static final String HTTP_RESPONSE_TEXT
static final String HTTP_URI
static final String HTTP_URL
static final String HTTP_CHUNKED
static final String HTTP_SERVLET_REQUEST
static final String HTTP_SERVLET_RESPONSE
static final String INTERCEPTED_ENDPOINT
static final String INTERCEPT_SEND_TO_ENDPOINT_WHEN_MATCHED
@Deprecated static final String INTERRUPTED
static final String LANGUAGE_SCRIPT
static final String LOG_DEBUG_BODY_MAX_CHARS
static final String LOG_DEBUG_BODY_STREAMS
static final String LOG_EIP_NAME
static final String LOOP_INDEX
static final String LOOP_SIZE
static final String SAGA_LONG_RUNNING_ACTION
static final String MAXIMUM_CACHE_POOL_SIZE
static final String MAXIMUM_ENDPOINT_CACHE_SIZE
static final String MAXIMUM_SIMPLE_CACHE_SIZE
static final String MAXIMUM_TRANSFORMER_CACHE_SIZE
static final String MAXIMUM_VALIDATOR_CACHE_SIZE
static final String MESSAGE_HISTORY
static final String MESSAGE_HISTORY_HEADER_FORMAT
static final String MESSAGE_HISTORY_OUTPUT_FORMAT
static final String MESSAGE_TIMESTAMP
static final String MULTICAST_INDEX
static final String MULTICAST_COMPLETE
@Deprecated static final String NOTIFY_EVENT
static final String ON_COMPLETION
static final String ON_COMPLETION_ROUTE_IDS
static final String OVERRULE_FILE_NAME
static final String PARENT_UNIT_OF_WORK
static final String STREAM_CACHE_UNIT_OF_WORK
static final String RECIPIENT_LIST_ENDPOINT
static final String RECEIVED_TIMESTAMP
static final String REDELIVERED
static final String REDELIVERY_COUNTER
static final String REDELIVERY_MAX_COUNTER
@Deprecated static final String REDELIVERY_EXHAUSTED
static final String REDELIVERY_DELAY
static final String REST_HTTP_URI
static final String REST_HTTP_QUERY
@Deprecated static final String ROLLBACK_ONLY
@Deprecated static final String ROLLBACK_ONLY_LAST
@Deprecated static final String ROUTE_STOP
static final String REUSE_SCRIPT_ENGINE
static final String COMPILE_SCRIPT
static final String SAXPARSER_FACTORY
static final String SCHEDULER_POLLED_MESSAGES
static final String SOAP_ACTION
static final String SKIP_GZIP_ENCODING
static final String SKIP_WWW_FORM_URLENCODED
static final String SLIP_ENDPOINT
static final String SLIP_PRODUCER
static final String SPLIT_INDEX
static final String SPLIT_COMPLETE
static final String SPLIT_SIZE
static final String STEP_ID
static final String TIMER_COUNTER
static final String TIMER_FIRED_TIME
static final String TIMER_NAME
static final String TIMER_PERIOD
static final String TIMER_TIME
static final String TO_ENDPOINT
static final String TRACE_EVENT
static final String TRACE_EVENT_NODE_ID
static final String TRACE_EVENT_TIMESTAMP
static final String TRACE_EVENT_EXCHANGE
static final String TRACING_HEADER_FORMAT
static final String TRACING_OUTPUT_FORMAT
static final String TRY_ROUTE_BLOCK
static final String TRANSFER_ENCODING
static final String UNIT_OF_WORK_EXHAUSTED
@Deprecated static final String UNIT_OF_WORK_PROCESS_SYNC
static final String XSLT_FILE_NAME
static final String XSLT_ERROR
static final String XSLT_FATAL_ERROR
static final String XSLT_WARNING
<T extends Exchange> T adapt(Class<T> type)
Exchange
to the specialized type.
For example to adapt to ExtendedExchange.type
- the type to adapt toExchange
adapted to the given typeExchangePattern getPattern()
ExchangePattern
(MEP) of this exchange.void setPattern(ExchangePattern pattern)
ExchangePattern
(MEP) of this exchange to be customized.
This typically won't be required as an exchange can be created with a specific MEP by calling
Endpoint.createExchange(ExchangePattern)
but it is here just in case it is needed.pattern
- the patternObject getProperty(ExchangePropertyKey key)
key
- the exchange key<T> T getProperty(ExchangePropertyKey key, Class<T> type)
key
- the exchange keytype
- the type of the property<T> T getProperty(ExchangePropertyKey key, Object defaultValue, Class<T> type)
key
- the exchange keydefaultValue
- the default value to return if property was absenttype
- the type of the propertyvoid setProperty(ExchangePropertyKey key, Object value)
key
- the exchange keyvalue
- to associate with the nameObject removeProperty(ExchangePropertyKey key)
key
- the exchange keyObject getProperty(String name)
name
- the name of the property@Deprecated Object getProperty(String name, Object defaultValue)
name
- the name of the propertydefaultValue
- the default value to return if property was absent<T> T getProperty(String name, Class<T> type)
name
- the name of the propertytype
- the type of the property<T> T getProperty(String name, Object defaultValue, Class<T> type)
name
- the name of the propertydefaultValue
- the default value to return if property was absenttype
- the type of the propertyvoid setProperty(String name, Object value)
name
- of the propertyvalue
- to associate with the nameObject removeProperty(String name)
name
- of the propertyboolean removeProperties(String pattern)
pattern
- pattern of namesboolean removeProperties(String pattern, String... excludePatterns)
pattern
- pattern of names that should be removedexcludePatterns
- one or more pattern of properties names that should be excluded (= preserved)Map<String,Object> getProperties()
getAllProperties()
Map<String,Object> getAllProperties()
getProperties()
boolean hasProperties()
Message getIn()
Message getMessage()
<T> T getMessage(Class<T> type)
type
- the given typevoid setMessage(Message message)
message
- the new message<T> T getIn(Class<T> type)
type
- the given typevoid setIn(Message in)
in
- the inbound message@Deprecated Message getOut()
getMessage()
getIn()
instead as it will ensure
headers etc. is kept and propagated when routing continues. Bottom line end users should rarely use this method.
hasOut()
method.
See also the class java doc for this Exchange
for more details and this
FAQ entry.getIn()
@Deprecated <T> T getOut(Class<T> type)
getMessage(Class)
getIn()
instead as it will ensure
headers etc. is kept and propagated when routing continues. Bottom line end users should rarely use this method.
hasOut()
method.
See also the class java doc for this Exchange
for more details and this
FAQ entry.type
- the given typegetIn(Class)
@Deprecated boolean hasOut()
getMessage()
@Deprecated void setOut(Message out)
setMessage(Message)
out
- the outbound messageException getException()
<T> T getException(Class<T> type)
type
- the exception typevoid setException(Throwable t)
Throwable
into Exception
type to accommodate for the getException()
method returning a plain Exception
type.t
- the caused exceptionboolean isFailed()
getException()
boolean isTransacted()
boolean isRouteStop()
void setRouteStop(boolean routeStop)
routeStop
- true to stop routingboolean isExternalRedelivered()
boolean isRollbackOnly()
void setRollbackOnly(boolean rollbackOnly)
boolean isRollbackOnlyLast()
void setRollbackOnlyLast(boolean rollbackOnlyLast)
CamelContext getContext()
Exchange copy()
Endpoint getFromEndpoint()
getContext().getRoute(getFromRouteId()).getEndpoint()
String getFromRouteId()
UnitOfWork getUnitOfWork()
String getExchangeId()
void setExchangeId(String id)
long getCreated()
Message.getMessageTimestamp()
Apache Camel