public final class ExchangeHelper extends Object
Exchange
objectsModifier and Type | Method and Description |
---|---|
static <T> T |
convertToMandatoryType(Exchange exchange,
Class<T> type,
Object value)
Converts the value to the given expected type or throws an exception
|
static <T> T |
convertToType(Exchange exchange,
Class<T> type,
Object value)
Converts the value to the given expected type
|
static Exchange |
copyExchangeAndSetCamelContext(Exchange exchange,
CamelContext context)
Copies the exchange but the copy will be tied to the given context
|
static Exchange |
copyExchangeAndSetCamelContext(Exchange exchange,
CamelContext context,
boolean handover)
Copies the exchange but the copy will be tied to the given context
|
static void |
copyResults(Exchange result,
Exchange source)
Copies the results of a message exchange from the source exchange to the result exchange
which will copy the message contents, exchange properties and the exception.
|
static void |
copyResultsPreservePattern(Exchange result,
Exchange source)
|
static Exchange |
createCopy(Exchange exchange,
boolean preserveExchangeId)
Creates a new instance and copies from the current message exchange so that it can be
forwarded to another destination as a new instance.
|
static Exchange |
createCorrelatedCopy(Exchange exchange,
boolean handover)
Creates a new instance and copies from the current message exchange so that it can be
forwarded to another destination as a new instance.
|
static Exchange |
createCorrelatedCopy(Exchange exchange,
boolean handover,
boolean useSameMessageId)
Creates a new instance and copies from the current message exchange so that it can be
forwarded to another destination as a new instance.
|
static Exchange |
createCorrelatedCopy(Exchange exchange,
boolean handover,
boolean useSameMessageId,
Predicate<Synchronization> filter)
Creates a new instance and copies from the current message exchange so that it can be
forwarded to another destination as a new instance.
|
static String |
createExceptionMessage(String message,
Exchange exchange,
Throwable cause)
Deprecated.
use org.apache.camel.CamelExchangeException.createExceptionMessage instead
|
static Map<String,Object> |
createVariableMap(Exchange exchange)
Creates a Map of the variables which are made available to a script or template
|
static <T> T |
extractFutureBody(CamelContext context,
Future<?> future,
Class<T> type)
Extracts the body from the given future, that represents a handle to an asynchronous exchange.
|
static <T> T |
extractFutureBody(CamelContext context,
Future<?> future,
long timeout,
TimeUnit unit,
Class<T> type)
Extracts the body from the given future, that represents a handle to an asynchronous exchange.
|
static Object |
extractResultBody(Exchange exchange,
ExchangePattern pattern)
Extracts the body from the given exchange.
|
static <T> T |
getBinding(Exchange exchange,
Class<T> type)
Extracts the Exchange.BINDING of the given type or null if not present
|
static String |
getContentEncoding(Exchange exchange)
Returns the MIME content encoding on the input message or null if one is not defined
|
static String |
getContentType(Exchange exchange)
Returns the MIME content type on the input message or null if one is not defined
|
static Exchange |
getExchangeById(Iterable<Exchange> exchanges,
String exchangeId)
Returns the first exchange in the given collection of exchanges which has the same exchange ID as the one given
or null if none could be found
|
static <T> T |
getHeaderOrProperty(Exchange exchange,
String name,
Class<T> type)
Gets an header or property of the correct type
|
static <T> T |
getMandatoryHeader(Exchange exchange,
String headerName,
Class<T> type)
Gets the mandatory inbound header of the correct type
|
static Object |
getMandatoryInBody(Exchange exchange)
Deprecated.
|
static <T> T |
getMandatoryInBody(Exchange exchange,
Class<T> type)
Deprecated.
|
static Object |
getMandatoryOutBody(Exchange exchange)
Deprecated.
|
static <T> T |
getMandatoryOutBody(Exchange exchange,
Class<T> type)
Deprecated.
|
static <T> T |
getMandatoryProperty(Exchange exchange,
String propertyName,
Class<T> type)
Gets the mandatory property of the exchange of the correct type
|
static Message |
getOriginalInMessage(Exchange exchange)
Gets the original IN
Message this Unit of Work was started with. |
static Message |
getResultMessage(Exchange exchange)
Returns the message where to write results in an
exchange-pattern-sensitive way.
|
static boolean |
hasExceptionBeenHandledByErrorHandler(Exchange exchange)
Tests whether the exchange has already been handled by the error handler
|
static boolean |
hasFaultMessage(Exchange exchange)
Tests whether the exchange has a fault message set and that its not null.
|
static boolean |
isFailureHandled(Exchange exchange)
Checks whether the exchange has been failure handed
|
static boolean |
isInterrupted(Exchange exchange)
Checks whether the exchange
UnitOfWork has been interrupted during processing |
static boolean |
isOutCapable(Exchange exchange)
Returns true if the given exchange pattern (if defined) can support OUT messages
|
static boolean |
isRedelivered(Exchange exchange)
Checks whether the exchange
UnitOfWork is redelivered |
static boolean |
isRedeliveryExhausted(Exchange exchange)
Checks whether the exchange is redelivery exhausted
|
static boolean |
isStreamCachingEnabled(Exchange exchange)
Check whether or not stream caching is enabled for the given route or globally.
|
static boolean |
isUnitOfWorkExhausted(Exchange exchange)
Checks whether the exchange
UnitOfWork is exhausted |
static String |
logIds(Exchange exchange)
Gets both the messageId and exchangeId to be used for logging purposes.
|
static Object |
lookupBean(Exchange exchange,
String name)
Performs a lookup in the registry of the bean name
|
static <T> T |
lookupBean(Exchange exchange,
String name,
Class<T> type)
Performs a lookup in the registry of the bean name and type
|
static Object |
lookupMandatoryBean(Exchange exchange,
String name)
Performs a lookup in the registry of the mandatory bean name and throws an exception if it could not be found
|
static <T> T |
lookupMandatoryBean(Exchange exchange,
String name,
Class<T> type)
Performs a lookup in the registry of the mandatory bean name and throws an exception if it could not be found
|
static <T> T |
newInstance(Exchange exchange,
Class<T> type)
Creates a new instance of the given type from the injector
|
static void |
populateVariableMap(Exchange exchange,
Map<String,Object> map)
Populates the Map with the variables which are made available to a script or template
|
static void |
prepareAggregation(Exchange oldExchange,
Exchange newExchange)
Prepares the exchanges for aggregation.
|
static void |
prepareOutToIn(Exchange exchange)
Strategy to prepare results before next iterator or when we are complete,
which is done by copying OUT to IN, so there is only an IN as input
for the next iteration.
|
static void |
replaceMessage(Exchange exchange,
Message newMessage,
boolean outOnly)
Replaces the existing message with the new message
|
static Endpoint |
resolveEndpoint(Exchange exchange,
Object value)
Attempts to resolve the endpoint for the given value
|
static void |
setFailureHandled(Exchange exchange)
Sets the exchange to be failure handled.
|
public static <T> T getBinding(Exchange exchange, Class<T> type)
exchange
- the message exchangetype
- the expected binding typepublic static Endpoint resolveEndpoint(Exchange exchange, Object value) throws NoSuchEndpointException
exchange
- the message exchange being processedvalue
- the value which can be an Endpoint
or an object
which provides a String representation of an endpoint via
Object.toString()
NoSuchEndpointException
- if the endpoint cannot be resolvedpublic static <T> T getMandatoryProperty(Exchange exchange, String propertyName, Class<T> type) throws NoSuchPropertyException
exchange
- the exchangepropertyName
- the property nametype
- the typeTypeConversionException
- is thrown if error during type conversionNoSuchPropertyException
- is thrown if no property existspublic static <T> T getMandatoryHeader(Exchange exchange, String headerName, Class<T> type) throws TypeConversionException, NoSuchHeaderException
exchange
- the exchangeheaderName
- the header nametype
- the typeTypeConversionException
- is thrown if error during type conversionNoSuchHeaderException
- is thrown if no headers existspublic static <T> T getHeaderOrProperty(Exchange exchange, String name, Class<T> type) throws TypeConversionException
exchange
- the exchangename
- the name of the header or the propertytype
- the typeTypeConversionException
- is thrown if error during type conversionNoSuchHeaderException
- is thrown if no headers exists@Deprecated public static Object getMandatoryInBody(Exchange exchange) throws InvalidPayloadException
Message.getMandatoryBody()
exchange
- the exchangeInvalidPayloadException
- Is thrown if the body being null or wrong class type@Deprecated public static <T> T getMandatoryInBody(Exchange exchange, Class<T> type) throws InvalidPayloadException
Message.getMandatoryBody(Class)
InvalidPayloadException
@Deprecated public static Object getMandatoryOutBody(Exchange exchange) throws InvalidPayloadException
Message.getMandatoryBody()
InvalidPayloadException
@Deprecated public static <T> T getMandatoryOutBody(Exchange exchange, Class<T> type) throws InvalidPayloadException
Message.getMandatoryBody(Class)
InvalidPayloadException
public static <T> T convertToMandatoryType(Exchange exchange, Class<T> type, Object value) throws TypeConversionException, NoTypeConversionAvailableException
TypeConversionException
- is thrown if error during type conversionNoTypeConversionAvailableException}
- if no type converters exists to convert to the given typeNoTypeConversionAvailableException
public static <T> T convertToType(Exchange exchange, Class<T> type, Object value) throws TypeConversionException
TypeConversionException
- is thrown if error during type conversionpublic static Exchange createCorrelatedCopy(Exchange exchange, boolean handover)
UnitOfWork
so its should be used
for async messaging, where the original and copied exchange are independent.exchange
- original copy of the exchangehandover
- whether the on completion callbacks should be handed over to the new copy.public static Exchange createCorrelatedCopy(Exchange exchange, boolean handover, boolean useSameMessageId)
UnitOfWork
so its should be used
for async messaging, where the original and copied exchange are independent.exchange
- original copy of the exchangehandover
- whether the on completion callbacks should be handed over to the new copy.useSameMessageId
- whether to use same message id on the copy message.public static Exchange createCorrelatedCopy(Exchange exchange, boolean handover, boolean useSameMessageId, Predicate<Synchronization> filter)
UnitOfWork
so its should be used
for async messaging, where the original and copied exchange are independent.exchange
- original copy of the exchangehandover
- whether the on completion callbacks should be handed over to the new copy.useSameMessageId
- whether to use same message id on the copy message.filter
- whether to handover the on completionpublic static Exchange createCopy(Exchange exchange, boolean preserveExchangeId)
exchange
- original copy of the exchangepreserveExchangeId
- whether or not the exchange id should be preservedpublic static void copyResults(Exchange result, Exchange source)
ExchangePattern
is not copied/altered.result
- the result exchange which will have the output and error state addedsource
- the source exchange which is not modifiedpublic static void copyResultsPreservePattern(Exchange result, Exchange source)
source
- source exchange.result
- target exchange.public static Message getResultMessage(Exchange exchange)
exchange
- message exchange.public static boolean isOutCapable(Exchange exchange)
exchange
- the exchange to interrogateExchangePattern
which supports
OUT messagespublic static <T> T newInstance(Exchange exchange, Class<T> type)
exchange
- the exchangetype
- the given typepublic static Map<String,Object> createVariableMap(Exchange exchange)
exchange
- the exchange to make availablepublic static void populateVariableMap(Exchange exchange, Map<String,Object> map)
exchange
- the exchange to make availablemap
- the map to populatepublic static String getContentType(Exchange exchange)
exchange
- the exchangepublic static String getContentEncoding(Exchange exchange)
exchange
- the exchangepublic static Object lookupMandatoryBean(Exchange exchange, String name) throws NoSuchBeanException
exchange
- the exchangename
- the bean nameNoSuchBeanException
- if no bean could be found in the registrypublic static <T> T lookupMandatoryBean(Exchange exchange, String name, Class<T> type)
exchange
- the exchangename
- the bean nametype
- the expected bean typeNoSuchBeanException
- if no bean could be found in the registrypublic static Object lookupBean(Exchange exchange, String name)
exchange
- the exchangename
- the bean namepublic static <T> T lookupBean(Exchange exchange, String name, Class<T> type)
exchange
- the exchangename
- the bean nametype
- the expected bean typepublic static Exchange getExchangeById(Iterable<Exchange> exchanges, String exchangeId)
exchanges
- the exchangesexchangeId
- the exchangeId to findpublic static void prepareAggregation(Exchange oldExchange, Exchange newExchange)
oldExchange
- the old exchangenewExchange
- the new exchangepublic static boolean isFailureHandled(Exchange exchange)
exchange
- the exchangepublic static boolean isUnitOfWorkExhausted(Exchange exchange)
UnitOfWork
is exhaustedexchange
- the exchangepublic static void setFailureHandled(Exchange exchange)
exchange
- the exchangepublic static boolean isRedeliveryExhausted(Exchange exchange)
exchange
- the exchangepublic static boolean isRedelivered(Exchange exchange)
UnitOfWork
is redeliveredexchange
- the exchangepublic static boolean isInterrupted(Exchange exchange)
UnitOfWork
has been interrupted during processingexchange
- the exchangepublic static boolean isStreamCachingEnabled(Exchange exchange)
exchange
- the exchangepublic static Object extractResultBody(Exchange exchange, ExchangePattern pattern)
exchange
- the exchangepattern
- exchange pattern if given, can be nullCamelExecutionException
- is thrown if the processing of the exchange failedpublic static boolean hasFaultMessage(Exchange exchange)
exchange
- the exchangepublic static boolean hasExceptionBeenHandledByErrorHandler(Exchange exchange)
exchange
- the exchangepublic static <T> T extractFutureBody(CamelContext context, Future<?> future, Class<T> type)
context
- the camel contextfuture
- the future handletype
- the expected body response typeCamelExecutionException
- is thrown if the processing of the exchange failedpublic static <T> T extractFutureBody(CamelContext context, Future<?> future, long timeout, TimeUnit unit, Class<T> type) throws TimeoutException
context
- the camel contextfuture
- the future handletimeout
- timeout valueunit
- timeout unittype
- the expected body response typeCamelExecutionException
- is thrown if the processing of the exchange failedTimeoutException
- is thrown if a timeout triggered@Deprecated public static String createExceptionMessage(String message, Exchange exchange, Throwable cause)
public static void prepareOutToIn(Exchange exchange)
exchange
- the exchange to preparepublic static String logIds(Exchange exchange)
exchange
- the exchangepublic static Exchange copyExchangeAndSetCamelContext(Exchange exchange, CamelContext context)
exchange
- the source exchangecontext
- the camel contextpublic static Exchange copyExchangeAndSetCamelContext(Exchange exchange, CamelContext context, boolean handover)
exchange
- the source exchangecontext
- the camel contexthandover
- whether to handover on completions from the source to the copypublic static void replaceMessage(Exchange exchange, Message newMessage, boolean outOnly)
exchange
- the exchangenewMessage
- the new messageoutOnly
- whether to replace the message as OUT messagepublic static Message getOriginalInMessage(Exchange exchange)
Message
this Unit of Work was started with.
The original message is only returned if the option RuntimeConfiguration.isAllowUseOriginalMessage()
is enabled. If its disabled, then null is returned.Message
, or null if using original message is disabled.Apache Camel