org.apache.camel.impl
Class DefaultExchange

java.lang.Object
  extended by org.apache.camel.impl.DefaultExchange
All Implemented Interfaces:
Exchange
Direct Known Subclasses:
GenericFileExchange, GroupedExchange, TraceEventExchange

public class DefaultExchange
extends Object
implements Exchange

A default implementation of Exchange

Version:
$Revision: 777808 $

Field Summary
protected  CamelContext context
           
 
Fields inherited from interface org.apache.camel.Exchange
AGGREGATED_INDEX, AGGREGATED_SIZE, ASYNC_WAIT, BATCH_COMPLETE, BATCH_INDEX, BATCH_SIZE, BEAN_HOLDER, BEAN_METHOD_NAME, BEAN_MULTI_PARAMETER_ARRAY, CHARSET_NAME, CONTENT_TYPE, DATASET_INDEX, EXCEPTION_CAUGHT, EXCEPTION_HANDLED, FAILURE_HANDLED, FILE_LOCAL_WORK_PATH, FILE_NAME, FILE_NAME_ONLY, FILE_NAME_PRODUCED, FILE_PARENT, FILE_PATH, FILTERED, HTTP_CHARACTER_ENCODING, HTTP_METHOD, HTTP_PATH, HTTP_QUERY, HTTP_RESPONSE_CODE, HTTP_URI, INTERCEPTED_ENDPOINT, LOG_DEBUG_BODY_MAX_CHARS, LOOP_INDEX, LOOP_SIZE, MULTICAST_INDEX, ON_COMPLETION, REDELIVERED, REDELIVERY_COUNTER, ROLLBACK_ONLY, ROUTE_STOP, SPLIT_INDEX, SPLIT_SIZE, TIMER_FIRED_TIME, TIMER_NAME, TIMER_PERIOD, TIMER_TIME, TRANSACTED
 
Constructor Summary
DefaultExchange(CamelContext context)
           
DefaultExchange(CamelContext context, ExchangePattern pattern)
           
DefaultExchange(Endpoint fromEndpoint)
           
DefaultExchange(Endpoint fromEndpoint, ExchangePattern pattern)
           
DefaultExchange(Exchange parent)
           
 
Method Summary
 void addOnCompletion(Synchronization onCompletion)
          Adds a Synchronization to be invoked as callback when this exchange is completed.
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  String createExchangeId()
           
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
 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)
          Returns the fault message; optionally lazily creating one if one has not been associated with this exchange
 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)
          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 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 newCopy(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.
 Exchange newInstance()
          Creates a new exchange instance with empty messages, headers and properties
 void removeFault()
          Removes the fault message.
 Object removeProperty(String name)
          Removes the given property on the exchange
 void setException(Exception exception)
          Sets the exception associated with this exchange
 void setExchangeId(String id)
          Set the exchange id
 void setFault(Message fault)
           
 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 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
 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(Exchange parent)

DefaultExchange

public DefaultExchange(Endpoint fromEndpoint)

DefaultExchange

public DefaultExchange(Endpoint fromEndpoint,
                       ExchangePattern pattern)
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

newCopy

public Exchange newCopy(boolean handoverOnCompletion)
Description copied from interface: Exchange
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.

Specified by:
newCopy in interface Exchange
Parameters:
handoverOnCompletion - whether the on completion callbacks should be handed over to the new copy.

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 test whether an OUT message have been set or not, use the Exchange.hasOut() method.

Specified by:
getOut in interface Exchange
Returns:
the response

hasOut

public boolean hasOut()
Description copied from interface: Exchange
Returns whether an OUT message has been set or not.

Specified by:
hasOut in interface Exchange
Returns:
true if an OUT message exists, false otherwise.

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 Exception 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)

getException

public <T> T getException(Class<T> type)
Description copied from interface: Exchange
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.

Specified by:
getException in interface Exchange
Parameters:
type - the exception type
Returns:
the exception (or null if no faults or if no caused exception matched)

setException

public void setException(Exception 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

getFromEndpoint

public Endpoint getFromEndpoint()
Description copied from interface: Exchange
Returns the endpoint which originated this message exchange if a consumer on an endpoint created the message exchange otherwise this property will be null

Specified by:
getFromEndpoint in interface Exchange

setFromEndpoint

public void setFromEndpoint(Endpoint fromEndpoint)
Description copied from interface: Exchange
Sets the endpoint which originated this message exchange. This method should typically only be called by Endpoint implementations

Specified by:
setFromEndpoint in interface Exchange
Parameters:
fromEndpoint - the endpoint which is originating this message exchange

getFault

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

Specified by:
getFault in interface Exchange
Returns:
the fault

hasFault

public boolean hasFault()
Description copied from interface: Exchange
Returns whether a FAULT message has been set or not.

Specified by:
hasFault in interface Exchange
Returns:
true if a FAULT message exists, false otherwise.

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)

removeFault

public void removeFault()
Description copied from interface: Exchange
Removes the fault message.

Specified by:
removeFault in interface Exchange

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.getFault()

isTransacted

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

Specified by:
isTransacted in interface Exchange

isRollbackOnly

public boolean isRollbackOnly()
Description copied from interface: Exchange
Returns true if this exchange is marked for rollback

Specified by:
isRollbackOnly 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

addOnCompletion

public void addOnCompletion(Synchronization onCompletion)
Description copied from interface: Exchange
Adds a Synchronization to be invoked as callback when this exchange is completed.

Specified by:
addOnCompletion in interface Exchange
Parameters:
onCompletion - the callback to invoke on completion of this 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


createExchangeId

protected String createExchangeId()


Copyright © 2009 Apache Software Foundation. All Rights Reserved.