Class DefaultExchangeHolder

  • All Implemented Interfaces:
    Serializable

    public class DefaultExchangeHolder
    extends Object
    implements 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 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
    • fault 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
    • fault headers
    The body is serialized and stored as serialized bytes. The header and exchange properties only include primitive, String, and Number types (and Exception types for exchange properties). Any other type is skipped. Any message body object that is not serializable will be skipped and Camel will log this at WARN level. And any message header values that is not a primitive value will be skipped and Camel will log this at DEBUG level.
    See Also:
    Serialized Form
    • Constructor Detail

      • DefaultExchangeHolder

        public DefaultExchangeHolder()
    • Method Detail

      • marshal

        public static DefaultExchangeHolder marshal​(org.apache.camel.Exchange exchange)
        Creates a payload object with the information from the given exchange.
        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.
        Parameters:
        exchange - the exchange, must not be null
        includeProperties - whether or not to include exchange properties
        Returns:
        the holder object with information copied form the exchange
      • marshal

        public static DefaultExchangeHolder marshal​(org.apache.camel.Exchange exchange,
                                                    boolean includeProperties,
                                                    boolean allowSerializedHeaders)
        Creates a payload object with the information from the given exchange.
        Parameters:
        exchange - the exchange, must not be null
        includeProperties - whether or not to include exchange properties
        allowSerializedHeaders - whether or not to include serialized headers
        Returns:
        the holder object with information copied form the exchange
      • marshal

        public static DefaultExchangeHolder marshal​(org.apache.camel.Exchange exchange,
                                                    boolean includeProperties,
                                                    boolean allowSerializedHeaders,
                                                    boolean preserveExchangeId)
        Creates a payload object with the information from the given exchange.
        Parameters:
        exchange - the exchange, must not be null
        includeProperties - whether or not to include exchange properties
        allowSerializedHeaders - whether or not to include serialized headers
        preserveExchangeId - whether to preserve exchange id
        Returns:
        the holder object with information copied form the exchange
      • unmarshal

        public static void unmarshal​(org.apache.camel.Exchange exchange,
                                     DefaultExchangeHolder payload)
        Transfers the information from the payload to the exchange.
        Parameters:
        exchange - the exchange to set values from the payload, must not be null
        payload - the payload with the values, must not be null
      • addProperty

        public static void addProperty​(DefaultExchangeHolder payload,
                                       String key,
                                       Serializable property)
        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 payload
        key - the property key to add
        property - the property value to add
      • getValidHeaderValue

        protected static Object getValidHeaderValue​(String headerName,
                                                    Object headerValue,
                                                    boolean allowSerializedHeaders)
        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
        We make possible store serialized headers by the boolean field allowSerializedHeaders
        Parameters:
        headerName - the header name
        headerValue - the header value
        allowSerializedHeaders - the header value
        Returns:
        the value to use, null to ignore this header
      • getValidExchangePropertyValue

        protected static Object getValidExchangePropertyValue​(String propertyName,
                                                              Object propertyValue,
                                                              boolean allowSerializedHeaders)
        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 as getValidHeaderValue(String, Object, boolean) and in addition any value of type Throwable.

        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        the value to use, null to ignore this header