org.apache.camel.impl
Class DefaultExchange

java.lang.Object
  extended by org.apache.camel.impl.DefaultExchange
All Implemented Interfaces:
Exchange

public final class DefaultExchange
extends Object
implements Exchange

A default implementation of Exchange

Version:

Field Summary
protected  CamelContext context
           
 
Fields inherited from interface org.apache.camel.Exchange
ACCEPT_CONTENT_TYPE, AGGREGATED_COMPLETED_BY, AGGREGATED_CORRELATION_KEY, AGGREGATED_SIZE, AGGREGATED_TIMEOUT, AGGREGATION_COMPLETE_ALL_GROUPS, AGGREGATION_STRATEGY, ASYNC_WAIT, AUTHENTICATION, AUTHENTICATION_FAILURE_POLICY_ID, BATCH_COMPLETE, BATCH_INDEX, BATCH_SIZE, BEAN_METHOD_NAME, BEAN_MULTI_PARAMETER_ARRAY, BINDING, BREADCRUMB_ID, CHARSET_NAME, CONTENT_ENCODING, CONTENT_LENGTH, CONTENT_TYPE, CORRELATION_ID, CREATED_TIMESTAMP, DATASET_INDEX, DEFAULT_CHARSET_PROPERTY, DESTINATION_OVERRIDE_URL, DISABLE_HTTP_STREAM_CACHE, DUPLICATE_MESSAGE, ERRORHANDLER_HANDLED, EVALUATE_EXPRESSION_RESULT, EXCEPTION_CAUGHT, FAILURE_ENDPOINT, FAILURE_HANDLED, FILE_LAST_MODIFIED, FILE_LOCAL_WORK_PATH, FILE_NAME, FILE_NAME_ONLY, FILE_NAME_PRODUCED, FILE_PARENT, FILE_PATH, FILTER_MATCHED, FILTER_NON_XML_CHARS, GROUPED_EXCHANGE, HTTP_BASE_URI, HTTP_CHARACTER_ENCODING, HTTP_CHUNKED, HTTP_METHOD, HTTP_PATH, HTTP_PROTOCOL_VERSION, HTTP_QUERY, HTTP_RESPONSE_CODE, HTTP_SERVLET_REQUEST, HTTP_SERVLET_RESPONSE, HTTP_URI, HTTP_URL, INTERCEPTED_ENDPOINT, LANGUAGE_SCRIPT, LOG_DEBUG_BODY_MAX_CHARS, LOG_DEBUG_BODY_STREAMS, LOOP_INDEX, LOOP_SIZE, MAXIMUM_CACHE_POOL_SIZE, MAXIMUM_ENDPOINT_CACHE_SIZE, MULTICAST_COMPLETE, MULTICAST_INDEX, NOTIFY_EVENT, ON_COMPLETION, PARENT_UNIT_OF_WORK, RECEIVED_TIMESTAMP, REDELIVERED, REDELIVERY_COUNTER, REDELIVERY_DELAY, REDELIVERY_EXHAUSTED, REDELIVERY_MAX_COUNTER, ROLLBACK_ONLY, ROLLBACK_ONLY_LAST, ROUTE_STOP, SKIP_GZIP_ENCODING, SLIP_ENDPOINT, SOAP_ACTION, SPLIT_COMPLETE, SPLIT_INDEX, SPLIT_SIZE, TIMER_COUNTER, TIMER_FIRED_TIME, TIMER_NAME, TIMER_PERIOD, TIMER_TIME, TO_ENDPOINT, TRACE_EVENT, TRACE_EVENT_EXCHANGE, TRACE_EVENT_NODE_ID, TRACE_EVENT_TIMESTAMP, TRANSFER_ENCODING, UNIT_OF_WORK_EXHAUSTED, UNIT_OF_WORK_PROCESS_SYNC, XSLT_FILE_NAME
 
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
protected  String createExchangeId()
           
 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)
 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
 String getFromRouteId()
          Returns the route id which originated this message exchange if a route consumer on an endpoint created the message exchange, otherwise this property will be null
 Message getIn()
          Returns the inbound request message
<T> T
getIn(Class<T> type)
          Returns the inbound request message as the given type
 Message getOut()
          Returns the outbound message, lazily creating one if one has not already been associated with this exchange.
<T> T
getOut(Class<T> type)
          Returns the outbound request message as the given type


Important: If you want to change the current message, then use Exchange.getIn() instead as it will ensure headers etc.

 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
 Object getProperty(String name, Object defaultValue)
          Returns a property associated with this exchange by name
<T> T
getProperty(String name, Object defaultValue, 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
 List<Synchronization> handoverCompletions()
          Handover all the on completions from this exchange
 void handoverCompletions(Exchange target)
          Handover all the on completions from this exchange to the target exchange.
 boolean hasOut()
          Returns whether an OUT message has been set or not.
 boolean hasProperties()
          Returns whether any properties has been set
 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
 Object removeProperty(String name)
          Removes the given property on the exchange
 void setException(Throwable t)
          Sets the exception associated with this exchange

Camel will wrap Throwable into Exception type to accommodate for the Exchange.getException() method returning a plain Exception type.

 void setExchangeId(String id)
          Set the exchange id
 void setFromEndpoint(Endpoint fromEndpoint)
          Sets the endpoint which originated this message exchange.
 void setFromRouteId(String fromRouteId)
          Sets the route id 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

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 property or null if there is no property for the given name

getProperty

public Object getProperty(String name,
                          Object defaultValue)
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
defaultValue - the default value to return if property was absent
Returns:
the value of the given property or defaultValue 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 property or null if there is no property for the given name or null if it cannot be converted to the given type

getProperty

public <T> T getProperty(String name,
                         Object defaultValue,
                         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
defaultValue - the default value to return if property was absent
type - the type of the property
Returns:
the value of the given property or defaultValue 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

hasProperties

public boolean hasProperties()
Description copied from interface: Exchange
Returns whether any properties has been set

Specified by:
hasProperties in interface Exchange
Returns:
true if any properties has been set

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

getIn

public <T> T getIn(Class<T> type)
Description copied from interface: Exchange
Returns the inbound request message as the given type

Specified by:
getIn in interface Exchange
Parameters:
type - the given type
Returns:
the message as the given type or null if not possible to covert to given type

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.


Important: If you want to change the current message, then use Exchange.getIn() instead as it will ensure headers etc. is kept and propagated when routing continues. Bottom line end users should rarely use this method.


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

See also the class java doc for this Exchange for more details and this FAQ entry.

Specified by:
getOut in interface Exchange
Returns:
the response
See Also:
Exchange.getIn()

getOut

public <T> T getOut(Class<T> type)
Description copied from interface: Exchange
Returns the outbound request message as the given type


Important: If you want to change the current message, then use Exchange.getIn() instead as it will ensure headers etc. is kept and propagated when routing continues. Bottom line end users should rarely use this method.


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

See also the class java doc for this Exchange for more details and this FAQ entry.

Specified by:
getOut in interface Exchange
Parameters:
type - the given type
Returns:
the message as the given type or null if not possible to covert to given type
See Also:
Exchange.getIn(Class)

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.

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 strategy is to look in the exception hierarchy 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 caused exception matched)

setException

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

Camel will wrap Throwable into Exception type to accommodate for the Exchange.getException() method returning a plain Exception type.

Specified by:
setException in interface Exchange
Parameters:
t - 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

getFromRouteId

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

Specified by:
getFromRouteId in interface Exchange

setFromRouteId

public void setFromRouteId(String fromRouteId)
Description copied from interface: Exchange
Sets the route id which originated this message exchange. This method should typically only be called by the internal framework.

Specified by:
setFromRouteId in interface Exchange
Parameters:
fromRouteId - the from route id

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(), Message.setFault(boolean), Message.isFault()

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

handoverCompletions

public void handoverCompletions(Exchange target)
Description copied from interface: Exchange
Handover all the on completions from this exchange to the target exchange.

Specified by:
handoverCompletions in interface Exchange
Parameters:
target - the target exchange

handoverCompletions

public List<Synchronization> handoverCompletions()
Description copied from interface: Exchange
Handover all the on completions from this exchange

Specified by:
handoverCompletions in interface Exchange
Returns:
the on completions

configureMessage

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


createExchangeId

protected String createExchangeId()


Apache CAMEL