org.apache.camel.impl
Class DefaultExchange

java.lang.Object
  extended by org.apache.camel.impl.DefaultExchange
All Implemented Interfaces:
Exchange
Direct Known Subclasses:
BeanExchange, FileExchange, JMXExchange

public class DefaultExchange
extends Object
implements Exchange

A default implementation of Exchange

Version:
$Revision: 772869 $

Field Summary
protected  CamelContext context
           
 
Fields inherited from interface org.apache.camel.Exchange
AGGREGATED_COUNT, CHARSET_NAME, EXCEPTION_HANDLED_PROPERTY
 
Constructor Summary
DefaultExchange(CamelContext context)
           
DefaultExchange(CamelContext context, ExchangePattern pattern)
           
DefaultExchange(DefaultExchange parent)
           
 
Method Summary
protected  void configureMessage(Message message)
          Configures the message after it has been set on the exchange
 Exchange copy()
          Creates a copy of the current message exchange so that it can be forwarded to another destination
 void copyFrom(Exchange exchange)
          Copies the data into this exchange from the given exchange
protected  Message createFaultMessage()
          Factory method to lazily create the FAULT message
protected  Message createInMessage()
          Factory method used to lazily create the IN message
protected  Message createOutMessage()
          Factory method to lazily create the OUT message
 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()
          Returns the fault message
 Message getFault(boolean lazyCreate)
          Returns the fault message; optionally lazily creating one if one has not been associated with this exchange
 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)
          Returns the outbound message; optionally lazily creating one if one has not been associated with this exchange
 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()
          Creates a new exchange instance with empty messages, headers and properties
 Object removeProperty(String name)
          Removes the given property on the exchange
 void setException(Throwable exception)
          Sets the exception associated with this exchange
 void setExchangeId(String id)
          Set the exchange id
 void setFault(Message fault)
           
 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 setProperties(Map<String,Object> properties)
           
 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
 void throwException()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

context

protected final CamelContext context
Constructor Detail

DefaultExchange

public DefaultExchange(CamelContext context)

DefaultExchange

public DefaultExchange(CamelContext context,
                       ExchangePattern pattern)

DefaultExchange

public DefaultExchange(DefaultExchange parent)
Method Detail

toString

public String toString()
Overrides:
toString in class Object

copy

public Exchange copy()
Description copied from interface: Exchange
Creates a copy of the current message exchange so that it can be forwarded to another destination

Specified by:
copy in interface Exchange

copyFrom

public void copyFrom(Exchange exchange)
Description copied from interface: Exchange
Copies the data into this exchange from the given exchange

Specified by:
copyFrom in interface Exchange
Parameters:
exchange - is the source from which headers and messages will be copied

newInstance

public Exchange newInstance()
Description copied from interface: Exchange
Creates a new exchange instance with empty messages, headers and properties

Specified by:
newInstance in interface Exchange

getContext

public CamelContext getContext()
Description copied from interface: Exchange
Returns the container so that a processor can resolve endpoints from URIs

Specified by:
getContext in interface Exchange
Returns:
the container which owns this exchange

getProperty

public Object getProperty(String name)
Description copied from interface: Exchange
Returns a property associated with this exchange by name

Specified by:
getProperty in interface Exchange
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

public <T> T getProperty(String name,
                         Class<T> type)
Description copied from interface: Exchange
Returns a property associated with this exchange by name and specifying the type required

Specified by:
getProperty in interface Exchange
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

public void setProperty(String name,
                        Object value)
Description copied from interface: Exchange
Sets a property on the exchange

Specified by:
setProperty in interface Exchange
Parameters:
name - of the property
value - to associate with the name

removeProperty

public Object removeProperty(String name)
Description copied from interface: Exchange
Removes the given property on the exchange

Specified by:
removeProperty in interface Exchange
Parameters:
name - of the property
Returns:
the old value of the property

getProperties

public Map<String,Object> getProperties()
Description copied from interface: Exchange
Returns all of the properties associated with the exchange

Specified by:
getProperties in interface Exchange
Returns:
all the headers in a Map

setProperties

public void setProperties(Map<String,Object> properties)

getIn

public Message getIn()
Description copied from interface: Exchange
Returns the inbound request message

Specified by:
getIn in interface Exchange
Returns:
the message

setIn

public void setIn(Message in)
Description copied from interface: Exchange
Sets the inbound message instance

Specified by:
setIn in interface Exchange
Parameters:
in - the inbound message

getOut

public Message getOut()
Description copied from interface: Exchange
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.

Specified by:
getOut in interface Exchange
Returns:
the response

getOut

public Message getOut(boolean lazyCreate)
Description copied from interface: Exchange
Returns the outbound message; optionally lazily creating one if one has not been associated with this exchange

Specified by:
getOut in interface Exchange
Parameters:
lazyCreate - true will lazy create the out message
Returns:
the response

setOut

public void setOut(Message out)
Description copied from interface: Exchange
Sets the outbound message

Specified by:
setOut in interface Exchange
Parameters:
out - the outbound message

getException

public Throwable getException()
Description copied from interface: Exchange
Returns the exception associated with this exchange

Specified by:
getException in interface Exchange
Returns:
the exception (or null if no faults)

setException

public void setException(Throwable exception)
Description copied from interface: Exchange
Sets the exception associated with this exchange

Specified by:
setException in interface Exchange
Parameters:
exception - the caused exception

getPattern

public ExchangePattern getPattern()
Description copied from interface: Exchange
Returns the ExchangePattern (MEP) of this exchange.

Specified by:
getPattern in interface Exchange
Returns:
the message exchange pattern of this exchange

setPattern

public void setPattern(ExchangePattern pattern)
Description copied from interface: Exchange
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.

Specified by:
setPattern in interface Exchange
Parameters:
pattern - the pattern

throwException

public void throwException()
                    throws Exception
Throws:
Exception

getFault

public Message getFault()
Description copied from interface: Exchange
Returns the fault message

Specified by:
getFault in interface Exchange
Returns:
the fault

getFault

public Message getFault(boolean lazyCreate)
Description copied from interface: Exchange
Returns the fault message; optionally lazily creating one if one has not been associated with this exchange

Specified by:
getFault in interface Exchange
Parameters:
lazyCreate - true will lazy create the fault message
Returns:
the fault

setFault

public void setFault(Message fault)

getExchangeId

public String getExchangeId()
Description copied from interface: Exchange
Returns the exchange id (unique)

Specified by:
getExchangeId in interface Exchange

setExchangeId

public void setExchangeId(String id)
Description copied from interface: Exchange
Set the exchange id

Specified by:
setExchangeId in interface Exchange

isFailed

public boolean isFailed()
Description copied from interface: Exchange
Returns true if this exchange failed due to either an exception or fault

Specified by:
isFailed in interface Exchange
Returns:
true if this exchange failed due to either an exception or fault
See Also:
Exchange.getException(), Exchange.getOut()

isTransacted

public boolean isTransacted()
Description copied from interface: Exchange
Returns true if this exchange is transacted

Specified by:
isTransacted in interface Exchange

getUnitOfWork

public UnitOfWork getUnitOfWork()
Description copied from interface: Exchange
Returns the unit of work that this exchange belongs to; which may map to zero, one or more physical transactions

Specified by:
getUnitOfWork in interface Exchange

setUnitOfWork

public void setUnitOfWork(UnitOfWork unitOfWork)
Description copied from interface: Exchange
Sets the unit of work that this exchange belongs to; which may map to zero, one or more physical transactions

Specified by:
setUnitOfWork in interface Exchange

createInMessage

protected Message createInMessage()
Factory method used to lazily create the IN message


createOutMessage

protected Message createOutMessage()
Factory method to lazily create the OUT message


createFaultMessage

protected Message createFaultMessage()
Factory method to lazily create the FAULT message


configureMessage

protected void configureMessage(Message message)
Configures the message after it has been set on the exchange



Apache CAMEL