Package org.apache.camel.support
Class DefaultExchangeHolder
java.lang.Object
org.apache.camel.support.DefaultExchangeHolder
- All Implemented Interfaces:
Serializable
Holder object for sending an exchange over a remote wire as a serialized object. This is usually configured using the
transferExchange=true option on the endpoint.
Note: Message body of type
As opposed to normal usage where only the body part of the exchange is transferred over the wire, this holder object serializes the following fields over the wire:
The exchange properties are not propagated by default. However you can specify they should be included by the
And the following headers is transferred if their values are of primitive types, String or Number based.
Note: Message body of type
File
or WrappedFile
is not supported and a
RuntimeExchangeException
is thrown. As opposed to normal usage where only the body part of the exchange is transferred over the wire, this holder object serializes the following fields over the wire:
- exchangeId
- in body
- out body
- exception
The exchange properties are not propagated by default. However you can specify they should be included by the
marshal(Exchange, boolean)
method. And the following headers is transferred if their values are of primitive types, String or Number based.
- in headers
- out headers
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addProperty
(DefaultExchangeHolder payload, String key, Serializable property) Adds a property to the payload.static void
addVariable
(DefaultExchangeHolder payload, String key, Serializable variable) Adds a variable to the payload.protected static Object
getValidExchangePropertyValue
(String propertyName, Object propertyValue, boolean allowSerializedValues) We only want to store exchange property values of primitive and String related types, and as well any caught exception that Camel routing engine has caught.protected static Object
getValidHeaderValue
(String headerName, Object headerValue, boolean allowSerializedValues) We only want to store header values of primitive and String related types.static DefaultExchangeHolder
marshal
(org.apache.camel.Exchange exchange) Creates a payload object with the information from the given exchange.static DefaultExchangeHolder
marshal
(org.apache.camel.Exchange exchange, boolean includeProperties) Creates a payload object with the information from the given exchange.static DefaultExchangeHolder
marshal
(org.apache.camel.Exchange exchange, boolean includeProperties, boolean allowSerializedValues) Creates a payload object with the information from the given exchange.static DefaultExchangeHolder
marshal
(org.apache.camel.Exchange exchange, boolean includeProperties, boolean allowSerializedValues, boolean preserveExchangeId) Creates a payload object with the information from the given exchange.toString()
static void
unmarshal
(org.apache.camel.Exchange exchange, DefaultExchangeHolder payload) Transfers the information from the payload to the exchange.
-
Constructor Details
-
DefaultExchangeHolder
public DefaultExchangeHolder()
-
-
Method Details
-
marshal
Creates a payload object with the information from the given exchange. Exchange properties and variables is included. Serialized values are skipped.- Parameters:
exchange
- the exchange, must not be null- Returns:
- the holder object with information copied form the exchange
-
marshal
public static DefaultExchangeHolder marshal(org.apache.camel.Exchange exchange, boolean includeProperties) Creates a payload object with the information from the given exchange. Serialized values are skipped.- Parameters:
exchange
- the exchange, must not be nullincludeProperties
- whether or not to include exchange properties and variables- Returns:
- the holder object with information copied form the exchange
-
marshal
public static DefaultExchangeHolder marshal(org.apache.camel.Exchange exchange, boolean includeProperties, boolean allowSerializedValues) Creates a payload object with the information from the given exchange.- Parameters:
exchange
- the exchange, must not be nullincludeProperties
- whether or not to include exchange properties and variablesallowSerializedValues
- whether or not to include serialized values- Returns:
- the holder object with information copied form the exchange
-
marshal
public static DefaultExchangeHolder marshal(org.apache.camel.Exchange exchange, boolean includeProperties, boolean allowSerializedValues, boolean preserveExchangeId) Creates a payload object with the information from the given exchange.- Parameters:
exchange
- the exchange, must not be nullincludeProperties
- whether or not to include exchange properties and variablesallowSerializedValues
- whether or not to include serialized headerspreserveExchangeId
- whether to preserve exchange id- Returns:
- the holder object with information copied form the exchange
-
unmarshal
Transfers the information from the payload to the exchange.- Parameters:
exchange
- the exchange to set values from the payload, must not be nullpayload
- the payload with the values, must not be null
-
addProperty
Adds a property to the payload. This can be done in special situations where additional information must be added which was not provided from the source.- Parameters:
payload
- the serialized payloadkey
- the property key to addproperty
- the property value to add
-
addVariable
Adds a variable to the payload. This can be done in special situations where additional information must be added which was not provided from the source.- Parameters:
payload
- the serialized payloadkey
- the variable key to addvariable
- the variable value to add
-
toString
-
getValidHeaderValue
protected static Object getValidHeaderValue(String headerName, Object headerValue, boolean allowSerializedValues) We only want to store header values of primitive and String related types. This default implementation will allow:- any primitives and their counter Objects (Integer, Double etc.)
- String and any other literals, Character, CharSequence
- Boolean
- Number
- java.util.Date
- Parameters:
headerName
- the header nameheaderValue
- the header valueallowSerializedValues
- whether to include serialized values- Returns:
- the value to use, null to ignore this header
-
getValidExchangePropertyValue
protected static Object getValidExchangePropertyValue(String propertyName, Object propertyValue, boolean allowSerializedValues) We only want to store exchange property values of primitive and String related types, and as well any caught exception that Camel routing engine has caught. This default implementation will allow the same values asgetValidHeaderValue(String, Object, boolean)
and in addition any value of typeThrowable
.- Parameters:
propertyName
- the property namepropertyValue
- the property valueallowSerializedValues
- whether to include serialized values- Returns:
- the value to use, null to ignore this header
-