org.apache.camel
Interface Exchange

All Known Implementing Classes:
BeanExchange, DefaultExchange, FileExchange, JMXExchange

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: 943775 $

Field Summary
static String AGGREGATED_COUNT
           
static String CHARSET_NAME
           
static String DEFAULT_CHARSET_PROPERTY
           
static String EXCEPTION_HANDLED_PROPERTY
           
 
Method Summary
 Exchange copy()
          Creates a copy of the current message exchange so that it can be forwarded to another destination
 void copyFrom(Exchange source)
          Deprecated. Starting with Camel 2.0.0 you should use copy() to get a new instance of an exchange or simply create a new exchange object
 CamelContext getContext()
          Returns the container so that a processor can resolve endpoints from URIs
 Throwable getException()
          Returns the exception associated with this exchange
 String getExchangeId()
          Returns the exchange id (unique)
 Message getFault()
          Deprecated. Starting with Camel 2.0.0 you should use getOut() and check the #org.apache.camel.Message.isFault() flag
 Message getFault(boolean lazyCreate)
          Deprecated. Starting with Camel 2.0.0 you should use getOut() and check the #org.apache.camel.Message.isFault() flag
 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. Starting with Camel 2.0.0 you should only use getOut()
 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 isFailed()
          Returns true if this exchange failed due to either an exception or fault
 boolean isTransacted()
          Returns true if this exchange is transacted
 Exchange newInstance()
          Deprecated. Starting with Camel 2.0.0 you should use copy() to get a new instance of an exchange or simply create a new exchange object
 Object removeProperty(String name)
          Removes the given property on the exchange
 void setException(Throwable e)
          Sets the exception associated with this exchange
 void setExchangeId(String id)
          Set the exchange id
 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

CHARSET_NAME

static final String CHARSET_NAME
See Also:
Constant Field Values

DEFAULT_CHARSET_PROPERTY

static final String DEFAULT_CHARSET_PROPERTY
See Also:
Constant Field Values

AGGREGATED_COUNT

static final String AGGREGATED_COUNT
See Also:
Constant Field Values

EXCEPTION_HANDLED_PROPERTY

static final String EXCEPTION_HANDLED_PROPERTY
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 check if this exchange has an out, but not force lazy creation, invoke #hasOut() first Starting with Camel 2.0.0 an out message could also represent a fault, i.e. a persistent error at the application level (equivalent to faults defines in some specifications like wsdl and jbi). You should use #org.apache.camel.Message} fault apis to get/set the fault flag for the out message.

Returns:
the response

getOut

Message getOut(boolean lazyCreate)
Deprecated. Starting with Camel 2.0.0 you should only use getOut()

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()
Deprecated. Starting with Camel 2.0.0 you should use getOut() and check the #org.apache.camel.Message.isFault() flag

Returns the fault message

Returns:
the fault

getFault

Message getFault(boolean lazyCreate)
Deprecated. Starting with Camel 2.0.0 you should use getOut() and check the #org.apache.camel.Message.isFault() flag

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

getException

Throwable getException()
Returns the exception associated with this exchange

Returns:
the exception (or null if no faults)

setException

void setException(Throwable 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(), getOut()

isTransacted

boolean isTransacted()
Returns true if this exchange is transacted


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()
Deprecated. Starting with Camel 2.0.0 you should use copy() to get a new instance of an exchange or simply create a new exchange object

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


copyFrom

void copyFrom(Exchange source)
Deprecated. Starting with Camel 2.0.0 you should use copy() to get a new instance of an exchange or simply create a new exchange object

Copies the data into this exchange from the given exchange

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

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



Apache CAMEL