org.apache.camel
Interface Exchange

All Known Implementing Classes:
DefaultExchange

public interface Exchange

The base message exchange interface providing access to the request, response and fault Message instances. Different providers such as JMS, JBI, CXF and HTTP can provide their own derived API to expose the underlying transport semantics to avoid the leaky abstractions of generic APIs.

Version:
$Revision: 793361 $

Field Summary
static String ACCEPT_CONTENT_TYPE
           
static String AGGREGATED_INDEX
           
static String AGGREGATED_SIZE
           
static String ASYNC_WAIT
           
static String BATCH_COMPLETE
           
static String BATCH_INDEX
           
static String BATCH_SIZE
           
static String BEAN_HOLDER
           
static String BEAN_METHOD_NAME
           
static String BEAN_MULTI_PARAMETER_ARRAY
           
static String BINDING
           
static String CHARSET_NAME
           
static String CONTENT_ENCODING
           
static String CONTENT_TYPE
           
static String CORRELATION_ID
           
static String DATASET_INDEX
           
static String ERRORHANDLER_HANDLED
           
static String EXCEPTION_CAUGHT
           
static String FAILURE_HANDLED
           
static String FILE_LOCAL_WORK_PATH
           
static String FILE_NAME
           
static String FILE_NAME_ONLY
           
static String FILE_NAME_PRODUCED
           
static String FILE_PARENT
           
static String FILE_PATH
           
static String FILTERED
           
static String GROUPED_EXCHANGE
           
static String HTTP_CHARACTER_ENCODING
           
static String HTTP_METHOD
           
static String HTTP_PATH
           
static String HTTP_QUERY
           
static String HTTP_RESPONSE_CODE
           
static String HTTP_URI
           
static String HTTP_URL
           
static String INTERCEPTED_ENDPOINT
           
static String LOG_DEBUG_BODY_MAX_CHARS
           
static String LOOP_INDEX
           
static String LOOP_SIZE
           
static String MULTICAST_INDEX
           
static String ON_COMPLETION
           
static String REDELIVERED
           
static String REDELIVERY_COUNTER
           
static String ROLLBACK_ONLY
           
static String ROUTE_STOP
           
static String SPLIT_INDEX
           
static String SPLIT_SIZE
           
static String TIMER_FIRED_TIME
           
static String TIMER_NAME
           
static String TIMER_PERIOD
           
static String TIMER_TIME
           
static String TRACE_EVENT
           
static String TRACE_EVENT_EXCHANGE
           
static String TRACE_EVENT_NODE_ID
           
static String TRACE_EVENT_TIMESTAMP
           
static String TRANSACTED
           
 
Method Summary
 void addOnCompletion(Synchronization onCompletion)
          Adds a Synchronization to be invoked as callback when this exchange is completed.
 Exchange copy()
          Creates a copy of the current message exchange so that it can be forwarded to another destination
 Exchange copy(boolean handoverOnCompletion)
          Creates a new instance and copies from the current message exchange so that it can be forwarded to another destination as a new instance.
 void copyFrom(Exchange source)
          Copies the data into this exchange from the given exchange
 CamelContext getContext()
          Returns the container so that a processor can resolve endpoints from URIs
 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)
 Message getFault()
          Returns the fault message
 Message getFault(boolean lazyCreate)
          Deprecated. use hasFault() or getFault(). Will be remove in Camel 2.0 GA.
 Endpoint getFromEndpoint()
          Returns the endpoint which originated this message exchange if a consumer on an endpoint created the message exchange otherwise this property will be null
 Message getIn()
          Returns the inbound request message
 Message getOut()
          Returns the outbound message, lazily creating one if one has not already been associated with this exchange.
 Message getOut(boolean lazyCreate)
          Deprecated. use hasOut() or getOut(). Will be remove in Camel 2.0 GA.
 ExchangePattern getPattern()
          Returns the ExchangePattern (MEP) of this exchange.
 Map<String,Object> getProperties()
          Returns all of the properties associated with the exchange
 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
 UnitOfWork getUnitOfWork()
          Returns the unit of work that this exchange belongs to; which may map to zero, one or more physical transactions
 boolean hasFault()
          Returns whether a FAULT message has been set or not.
 boolean hasOut()
          Returns whether an OUT message has been set or not.
 boolean isFailed()
          Returns true if this exchange failed due to either an exception or fault
 boolean isRollbackOnly()
          Returns true if this exchange is marked for rollback
 boolean isTransacted()
          Returns true if this exchange is transacted
 Exchange newInstance()
          Creates a new exchange instance with empty messages, headers and properties
 Object removeProperty(String name)
          Removes the given property on the exchange
 void setException(Exception e)
          Sets the exception associated with this exchange
 void setExchangeId(String id)
          Set the exchange id
 void setFault(Message fault)
          Sets the fault message
 void setFromEndpoint(Endpoint fromEndpoint)
          Sets the endpoint which originated this message exchange.
 void setIn(Message in)
          Sets the inbound message instance
 void setOut(Message out)
          Sets the outbound message
 void setPattern(ExchangePattern pattern)
          Allows the ExchangePattern (MEP) of this exchange to be customized.
 void setProperty(String name, Object value)
          Sets a property on the exchange
 void setUnitOfWork(UnitOfWork unitOfWork)
          Sets the unit of work that this exchange belongs to; which may map to zero, one or more physical transactions
 

Field Detail

ACCEPT_CONTENT_TYPE

static final String ACCEPT_CONTENT_TYPE
See Also:
Constant Field Values

AGGREGATED_INDEX

static final String AGGREGATED_INDEX
See Also:
Constant Field Values

AGGREGATED_SIZE

static final String AGGREGATED_SIZE
See Also:
Constant Field Values

ASYNC_WAIT

static final String ASYNC_WAIT
See Also:
Constant Field Values

BATCH_INDEX

static final String BATCH_INDEX
See Also:
Constant Field Values

BATCH_SIZE

static final String BATCH_SIZE
See Also:
Constant Field Values

BATCH_COMPLETE

static final String BATCH_COMPLETE
See Also:
Constant Field Values

BEAN_METHOD_NAME

static final String BEAN_METHOD_NAME
See Also:
Constant Field Values

BEAN_HOLDER

static final String BEAN_HOLDER
See Also:
Constant Field Values

BEAN_MULTI_PARAMETER_ARRAY

static final String BEAN_MULTI_PARAMETER_ARRAY
See Also:
Constant Field Values

BINDING

static final String BINDING
See Also:
Constant Field Values

CHARSET_NAME

static final String CHARSET_NAME
See Also:
Constant Field Values

CONTENT_ENCODING

static final String CONTENT_ENCODING
See Also:
Constant Field Values

CONTENT_TYPE

static final String CONTENT_TYPE
See Also:
Constant Field Values

CORRELATION_ID

static final String CORRELATION_ID
See Also:
Constant Field Values

DATASET_INDEX

static final String DATASET_INDEX
See Also:
Constant Field Values

EXCEPTION_CAUGHT

static final String EXCEPTION_CAUGHT
See Also:
Constant Field Values

ERRORHANDLER_HANDLED

static final String ERRORHANDLER_HANDLED
See Also:
Constant Field Values

FAILURE_HANDLED

static final String FAILURE_HANDLED
See Also:
Constant Field Values

FILE_LOCAL_WORK_PATH

static final String FILE_LOCAL_WORK_PATH
See Also:
Constant Field Values

FILE_NAME

static final String FILE_NAME
See Also:
Constant Field Values

FILE_NAME_ONLY

static final String FILE_NAME_ONLY
See Also:
Constant Field Values

FILE_NAME_PRODUCED

static final String FILE_NAME_PRODUCED
See Also:
Constant Field Values

FILE_PATH

static final String FILE_PATH
See Also:
Constant Field Values

FILE_PARENT

static final String FILE_PARENT
See Also:
Constant Field Values

FILTERED

static final String FILTERED
See Also:
Constant Field Values

GROUPED_EXCHANGE

static final String GROUPED_EXCHANGE
See Also:
Constant Field Values

HTTP_CHARACTER_ENCODING

static final String HTTP_CHARACTER_ENCODING
See Also:
Constant Field Values

HTTP_METHOD

static final String HTTP_METHOD
See Also:
Constant Field Values

HTTP_PATH

static final String HTTP_PATH
See Also:
Constant Field Values

HTTP_QUERY

static final String HTTP_QUERY
See Also:
Constant Field Values

HTTP_RESPONSE_CODE

static final String HTTP_RESPONSE_CODE
See Also:
Constant Field Values

HTTP_URI

static final String HTTP_URI
See Also:
Constant Field Values

HTTP_URL

static final String HTTP_URL
See Also:
Constant Field Values

INTERCEPTED_ENDPOINT

static final String INTERCEPTED_ENDPOINT
See Also:
Constant Field Values

LOG_DEBUG_BODY_MAX_CHARS

static final String LOG_DEBUG_BODY_MAX_CHARS
See Also:
Constant Field Values

LOOP_INDEX

static final String LOOP_INDEX
See Also:
Constant Field Values

LOOP_SIZE

static final String LOOP_SIZE
See Also:
Constant Field Values

MULTICAST_INDEX

static final String MULTICAST_INDEX
See Also:
Constant Field Values

ON_COMPLETION

static final String ON_COMPLETION
See Also:
Constant Field Values

ROUTE_STOP

static final String ROUTE_STOP
See Also:
Constant Field Values

REDELIVERED

static final String REDELIVERED
See Also:
Constant Field Values

REDELIVERY_COUNTER

static final String REDELIVERY_COUNTER
See Also:
Constant Field Values

ROLLBACK_ONLY

static final String ROLLBACK_ONLY
See Also:
Constant Field Values

SPLIT_INDEX

static final String SPLIT_INDEX
See Also:
Constant Field Values

SPLIT_SIZE

static final String SPLIT_SIZE
See Also:
Constant Field Values

TIMER_FIRED_TIME

static final String TIMER_FIRED_TIME
See Also:
Constant Field Values

TIMER_NAME

static final String TIMER_NAME
See Also:
Constant Field Values

TIMER_PERIOD

static final String TIMER_PERIOD
See Also:
Constant Field Values

TIMER_TIME

static final String TIMER_TIME
See Also:
Constant Field Values

TRANSACTED

static final String TRANSACTED
See Also:
Constant Field Values

TRACE_EVENT

static final String TRACE_EVENT
See Also:
Constant Field Values

TRACE_EVENT_NODE_ID

static final String TRACE_EVENT_NODE_ID
See Also:
Constant Field Values

TRACE_EVENT_TIMESTAMP

static final String TRACE_EVENT_TIMESTAMP
See Also:
Constant Field Values

TRACE_EVENT_EXCHANGE

static final String TRACE_EVENT_EXCHANGE
See Also:
Constant Field Values
Method Detail

getPattern

ExchangePattern getPattern()
Returns the ExchangePattern (MEP) of this exchange.

Returns:
the message exchange pattern of this exchange

setPattern

void setPattern(ExchangePattern pattern)
Allows the 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.

Parameters:
pattern - the pattern

getProperty

Object getProperty(String name)
Returns a property associated with this exchange by name

Parameters:
name - the name of the property
Returns:
the value of the given header or null if there is no property for the given name

getProperty

<T> T getProperty(String name,
                  Class<T> type)
Returns a property associated with this exchange by name and specifying the type required

Parameters:
name - the name of the property
type - the type of the property
Returns:
the value of the given header or null if there is no property for the given name or null if it cannot be converted to the given type

setProperty

void setProperty(String name,
                 Object value)
Sets a property on the exchange

Parameters:
name - of the property
value - to associate with the name

removeProperty

Object removeProperty(String name)
Removes the given property on the exchange

Parameters:
name - of the property
Returns:
the old value of the property

getProperties

Map<String,Object> getProperties()
Returns all of the properties associated with the exchange

Returns:
all the headers in a Map

getIn

Message getIn()
Returns the inbound request message

Returns:
the message

setIn

void setIn(Message in)
Sets the inbound message instance

Parameters:
in - the inbound message

getOut

Message getOut()
Returns the outbound message, lazily creating one if one has not already been associated with this exchange.

If you want to test whether an OUT message have been set or not, use the hasOut() method.

Returns:
the response

hasOut

boolean hasOut()
Returns whether an OUT message has been set or not.

Returns:
true if an OUT message exists, false otherwise.

getOut

Message getOut(boolean lazyCreate)
Deprecated. use hasOut() or getOut(). Will be remove in Camel 2.0 GA.

Returns the outbound message; optionally lazily creating one if one has not been associated with this exchange

Parameters:
lazyCreate - true will lazy create the out message
Returns:
the response

setOut

void setOut(Message out)
Sets the outbound message

Parameters:
out - the outbound message

getFault

Message getFault()
Returns the fault message

Returns:
the fault

hasFault

boolean hasFault()
Returns whether a FAULT message has been set or not.

Returns:
true if a FAULT message exists, false otherwise.

getFault

Message getFault(boolean lazyCreate)
Deprecated. use hasFault() or getFault(). Will be remove in Camel 2.0 GA.

Returns the fault message; optionally lazily creating one if one has not been associated with this exchange

Parameters:
lazyCreate - true will lazy create the fault message
Returns:
the fault

setFault

void setFault(Message fault)
Sets the fault message

Parameters:
fault - the fault message

getException

Exception getException()
Returns the exception associated with this exchange

Returns:
the exception (or null if no faults)

getException

<T> T getException(Class<T> type)
Returns the exception associated with this exchange.

Is used to get the caused exception that typically have been wrapped in some sort of Camel wrapper exception

The stategy is to look in the exception hieracy to find the first given cause that matches the type. Will start from the bottom (the real cause) and walk upwards.

Parameters:
type - the exception type
Returns:
the exception (or null if no faults or if no caused exception matched)

setException

void setException(Exception e)
Sets the exception associated with this exchange

Parameters:
e - the caused exception

isFailed

boolean isFailed()
Returns true if this exchange failed due to either an exception or fault

Returns:
true if this exchange failed due to either an exception or fault
See Also:
getException(), getFault()

isTransacted

boolean isTransacted()
Returns true if this exchange is transacted


isRollbackOnly

boolean isRollbackOnly()
Returns true if this exchange is marked for rollback


getContext

CamelContext getContext()
Returns the container so that a processor can resolve endpoints from URIs

Returns:
the container which owns this exchange

newInstance

Exchange newInstance()
Creates a new exchange instance with empty messages, headers and properties


copy

Exchange copy()
Creates a copy of the current message exchange so that it can be forwarded to another destination


copy

Exchange copy(boolean handoverOnCompletion)
Creates a new instance and copies from the current message exchange so that it can be forwarded to another destination as a new instance. Unlike regular copy this operation will not share the same UnitOfWork so its should be used for async messaging, where the original and copied exchange are independent.

Parameters:
handoverOnCompletion - whether the on completion callbacks should be handed over to the new copy.

copyFrom

void copyFrom(Exchange source)
Copies the data into this exchange from the given exchange

Parameters:
source - is the source from which headers and messages will be copied

getFromEndpoint

Endpoint getFromEndpoint()
Returns the endpoint which originated this message exchange if a consumer on an endpoint created the message exchange otherwise this property will be null


setFromEndpoint

void setFromEndpoint(Endpoint fromEndpoint)
Sets the endpoint which originated this message exchange. This method should typically only be called by Endpoint implementations

Parameters:
fromEndpoint - the endpoint which is originating this message exchange

getUnitOfWork

UnitOfWork getUnitOfWork()
Returns the unit of work that this exchange belongs to; which may map to zero, one or more physical transactions


setUnitOfWork

void setUnitOfWork(UnitOfWork unitOfWork)
Sets the unit of work that this exchange belongs to; which may map to zero, one or more physical transactions


getExchangeId

String getExchangeId()
Returns the exchange id (unique)


setExchangeId

void setExchangeId(String id)
Set the exchange id


addOnCompletion

void addOnCompletion(Synchronization onCompletion)
Adds a Synchronization to be invoked as callback when this exchange is completed.

Parameters:
onCompletion - the callback to invoke on completion of this exchange


Apache CAMEL